@echo off

reg query "HKEY_LOCAL_MACHINE\Software\Lenovo\LenovoVirtualDisplay" 2>nul
if %ERRORLEVEL% == 0 (
    echo The registry key exists and is being deleted
    reg delete "HKEY_LOCAL_MACHINE\Software\Lenovo\LenovoVirtualDisplay" /f
) else (
    echo The registry key does not exist, skip delete...
)

reg query "HKEY_CURRENT_USER\Software\Lenovo\LenovoVirtualDisplay" 2>nul
if %ERRORLEVEL% == 0 (
    echo The registry key exists and is being deleted
    reg delete "HKEY_CURRENT_USER\Software\Lenovo\LenovoVirtualDisplay" /f
) else (
    echo The registry key does not exist, skip delete...
)
 
sc query "LenovoVirtualDisplayService" >nul 2>&1
if %ERRORLEVEL% == 0 (
    echo The service exists, is being stopped and deleted...
    sc stop "LenovoVirtualDisplayService"
    timeout /t 3 /nobreak >nul
    sc delete "LenovoVirtualDisplayService"
) else (
    echo The service does not exist, skip stop and delete...
)

:: 检查当前是否以管理员权限运行
net session >nul 2>&1
if %errorLevel% == 0 (
    echo Running with administrator privileges...
    goto exec
) else (
    echo Requesting administrator privileges...
    goto UACPrompt
)

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:exec
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    :: 切换到批处理文件所在的目录
    CD /D "%~dp0"
    :: 运行a.exe并传递参数whql
    vdsetup.exe production
    @set "batchDir=%~dp0"
    pnputil.exe -i -a "%batchDir%\VirtualDisplayDriver.inf"
    
    TIMEOUT /T 10
    @echo Install Sucessfully
    exit /B




 




  
