Skip to content

Instantly share code, notes, and snippets.

@muink
Created February 20, 2018 08:59
Show Gist options
  • Save muink/aeaacd153395481927d35f3db909bb6d to your computer and use it in GitHub Desktop.
Save muink/aeaacd153395481927d35f3db909bb6d to your computer and use it in GitHub Desktop.
:: Graphics Driver Auto Installer
:: Install graphics driver
:: Author: muink
@echo off&title Graphics Driver Auto Installer
mode con cols=100 lines=27
:Init
cd /d %~dp0
:: In Windows install ISO PE set 1
set PEmode=1
:: In Windows 7 install ISO PE set 7
set PEves=10
set "path=%path%;%~dp0bin"
set "program_save=%~dp0pkg"
set "program_path=nVidia"
set "program=setup.exe"
set "install_volume="
:: Reg key
set "reg_system_path=HKLM\VSYS"
set "file_system_path=\Windows\System32\config\SYSTEM"
set "reg_software_path=HKLM\VSOFT"
set "file_software_path=\Windows\System32\config\SOFTWARE"
setlocal enabledelayedexpansion
:Main
cls
echo.
echo. Searching for windows 7 system partition...
echo.
:: Get Windows volume letter
if not "%PEmode%" == "1" (
call:[GetLetter] win_letter nosys
) else (
if not "%PEves%" == "7" (
call:[GetLetter] win_letter nosys
) else (
call:[PE][GetLetter] win_letter nosys
)
)
for /f "tokens=3 delims=;" %%i in ("%win_letter%") do set "win_letter=%%i"
:: Verify and list Volume
set "verify_letter="
if "%win_letter%" == "0" set "verify_letter=0"&goto Menu
:List_V
for /f "tokens=1* delims= " %%i in ("%win_letter%") do set "vletter=%%i"&set "win_letter=%%j"
call:[ListVolume] %vletter% %vletter%_des
if defined %vletter%_des set "verify_letter=%verify_letter% %vletter%"
:: Clear space
set "verify_letter=%verify_letter: = %"
if defined win_letter goto List_V
call:[ClearHeadTailSpace] verify_letter
:Menu
cls
echo.Choise the system volume (Can not use for the current system)
echo.
echo. [0] Refresh
if "%verify_letter%" == "0" echo. [0] Not have windows 7 system partition
echo.
setlocal enabledelayedexpansion
:Menu_List
if not "%verify_letter%" == "0" for /f "tokens=1* delims= " %%i in ("%verify_letter%") do (
echo. [%%i] !%%i_des!
set "verify_letter=%%j"
goto Menu_List
)
endlocal
echo.
set "choise="
set /p choise=Choise and continue:
if not defined choise goto Menu
if "%choise:~0,1%"=="0" goto Main
echo.%verify_letter%|find /i /v "%choise:~0,1%">nul||(
set "install_volume=%choise:~0,1%"
goto Install
)
goto Menu
:Install
cls
rem set /a Vcount=0
rem pushd %program_save%
rem for /f "delims=" %%i in ('dir /a-d /b *.exe 2^>nul') do (
rem set /a Vcount+=1
rem set "Pro!Vcount!_Name=%%~i"
rem )
rem popd
rem :Install_Menu
rem cls
rem echo.Choise the Program
rem echo.
rem echo. [0] Refresh
rem if "%Vcount%" == "0" echo. [0] Not have install program
rem echo.
rem if not "%Vcount%" == "0" for /l %%i in (1,1,%Vcount%) do echo. [%%i] !Pro%%i_Name!
rem echo.
rem set "choise="
rem set /p choise=Choise and continue:
rem if not defined choise goto Install_Menu
rem set /a choise=%choise%
rem if %choise% equ 0 goto Install
rem if %choise% geq 1 if %choise% leq %Vcount% (echo.>nul) else goto Install
rem cls
rem 7za x "%program_save%\!Pro%choise%_Name!" -o"%install_volume%:\%program_path%\">nul 2>nul
rem rd /s /q %install_volume%:\%program_path%>nul 2>nul
xcopy /e /y "%program_save%" "%install_volume%:\%program_path%\">nul 2>nul
call:[UACOFF] %install_volume%
call:[ExtractCore] %install_volume%
exit
:[ListVolume]
setlocal enabledelayedexpansion
set "vletter=%1"
set error_m2=
call:[CheckSystem] product_name edition_id error_m2 %reg_system_path% "%vletter%:%file_system_path%" %reg_software_path% "%vletter%:%file_software_path%"
if "!error_m2!"=="2" endlocal&set "%2="&goto :eof
if "!error_m2!"=="7" endlocal&set "%2="&goto :eof
if "!error_m2!"=="8" endlocal&set "%2="&goto :eof
if "!error_m2!"=="9" endlocal&set "%2="&goto :eof
if "%PEmode%" == "1" (
call:[PE][GetTheDP] %vletter% disk disk_name
call:[PE][GetTheDP] %vletter% partition part_num
call:[PE][GetTheVolumeSize] %vletter% volume_size unit
) else (
call:[GetTheDP] %vletter% disk disk_name
call:[GetTheDP] %vletter% partition part_num
call:[GetTheVolumeSize] %vletter% volume_size unit
)
for /f "delims=" %%i in ("!disk_name! Partition !part_num! !volume_size!!unit! !product_name! !edition_id!") do endlocal&set "%2=%%~i"
goto :eof
:[PE][GetLetter]
setlocal enabledelayedexpansion
:: Get letter
rem wmic logicaldisk where "drivetype=3" get name
rem wmic logicaldisk get Description,DeviceID,DriveType,FileSystem,Size,VolumeName /format:csv
rem 0-Unknown
rem 1-No Root Directory
rem 2-Removable Disk
rem 3-Local Disk
rem 4-Network Drive
rem 5-Compact Disc
rem 6-RAM Disk
set tagr=1
set actletter=
set winletter=
set freeletter=C D E F G H I J K L M N O P Q R S T U V W X Y Z
:: For WinPE not have "fsutil" and "findstr"
rem for /f "tokens=2 delims=,:" %%i in ('wmic logicaldisk get DeviceID^,DriveType /format:csv^|findstr /i "2 3"') do (
:: For WinPE not have "fsutil"
for /f "tokens=2 delims=,:" %%i in ('wmic logicaldisk get DeviceID^,DriveType /format:csv^|find /i /v "0"^|find /i /v "1"^|find /i /v "4"^|find /i /v "5"^|find /i /v "6"') do (
if not defined tagr (
:: Used Letter
set "actletter=!actletter! %%i"
:: Win Letter
if exist "%%i:\Windows\System32\config\SYSTEM" set "winletter=!winletter! %%i"
:: Free Letter
if defined freeletter set "freeletter=!freeletter:%%i=!"&set "freeletter=!freeletter: = !"
)
set tagr=
)
call:[ClearHeadTailSpace] actletter
call:[ClearHeadTailSpace] winletter
call:[ClearHeadTailSpace] freeletter
if %2 == nosys (
set winletter=!winletter:%SystemDrive:~0,1%=!
call:[ClearHeadTailSpace] winletter
)
rem echo.Act [%actletter%]
rem echo.Free [%freeletter%]
rem echo.Win [%winletter%]
for /f "delims=" %%i in ("%actletter%;%freeletter%;%winletter%") do endlocal&set "%1=%%i"
goto :eof
:[GetLetter]
setlocal enabledelayedexpansion
:: Get letter
:: For Win
for /f "tokens=1* delims=: " %%i in ('fsutil fsinfo drives') do set "acti=%%j"
set actletter=
set winletter=
set freeletter=C D E F G H I J K L M N O P Q R S T U V W X Y Z
:[GetLetter]#loop
for /f "tokens=1* delims=:\ " %%i in ("%acti%") do (
if "%PEmode%" == "1" (
:: For WinPE not have "findstr"
fsutil fsinfo drivetype %%i:|find /i /v "CD-ROM"|find /i /v "Ram"|find /i /v "/">nul&&set ny=y||set ny=n
) else (
:: For Win
fsutil fsinfo drivetype %%i:|findstr /i "CD-ROM Ram /">nul 2>nul&&set ny=n||set ny=y
)
if "!ny!" == "y" (
:: Used Letter
set "actletter=%actletter% %%i"
:: Win Letter
if exist "%%i:\Windows\System32\config\SYSTEM" set "winletter=%winletter% %%i"
)
:: Free Letter
if defined freeletter set "freeletter=!freeletter:%%i=!"&set "freeletter=!freeletter: = !"
set "acti=%%j"
goto %~0#loop
)
call:[ClearHeadTailSpace] actletter
call:[ClearHeadTailSpace] winletter
call:[ClearHeadTailSpace] freeletter
if %2 == nosys (
set winletter=!winletter:%SystemDrive:~0,1%=!
call:[ClearHeadTailSpace] winletter
)
rem echo.Act [%actletter%]
rem echo.Free [%freeletter%]
rem echo.Win [%winletter%]
for /f "delims=" %%i in ("%actletter%;%freeletter%;%winletter%") do endlocal&set "%1=%%i"
goto :eof
:[ClearHeadTailSpace]
setlocal enabledelayedexpansion
set "strs=!%1!"
for /f "tokens=* delims= " %%i in ("%strs%") do set "strs=%%i"
if not defined strs set "strs=0"
if "%strs:~-1%" == " " set "strs=%strs:~0,-1%"
for /f "delims=" %%i in ("%strs%") do endlocal&set "%1=%%i"
goto :eof
:[PE][GetTheDP]
setlocal enabledelayedexpansion
set "letter=%~1"
set "code=%~2"
set /a "tagnum=2"
:: For WinPE not have "findstr"
for /f "delims=" %%i in ('(echo.select volume %letter%^&echo.detail %code%^)^|diskpart') do (
if !tagnum! equ 0 set "value=%%~i"&goto %~0#cut
if "%%~i" == "DISKPART> " set /a "tagnum-=1"
)
:[PE][GetTheDP]#cut
if "%code%" == "disk" (
set "value=!value: ATA Device=!"
set "value=!value: SCSI Disk Device=!"
set "value=!value: USB Device=!"
)
if "%code%" == "partition" for /f "tokens=2 delims= " %%i in ("%value%") do set "value=%%~i"
:[PE][GetTheDP]#out
for /f "delims=" %%i in ("%value%") do endlocal&set "%3=%%~i"
goto :eof
:[GetTheDP]
setlocal enabledelayedexpansion
set "letter=%~1"
set "code=%~2"
:: For Win
for /f "delims=" %%i in ('(echo.select volume %letter%^&echo.detail %code%^)^|diskpart^|findstr /i /n "^DISKPART\>"^|more +1') do (
set "linenum=%%~i"
for /f "delims=:" %%I in ("!linenum!") do set "linenum=%%~I"
goto %~0#cat
)
:[GetTheDP]#cat
for /f "delims=" %%i in ('(echo.select volume %letter%^&echo.detail %code%^)^|diskpart^|more +%linenum%') do (
set "value=%%~i"
goto %~0#cut
)
:[GetTheDP]#cut
if "%code%" == "disk" (
set "value=!value: ATA Device=!"
set "value=!value: SCSI Disk Device=!"
set "value=!value: USB Device=!"
)
if "%code%" == "partition" for /f "tokens=2 delims= " %%i in ("%value%") do set "value=%%~i"
:[GetTheDP]#out
for /f "delims=" %%i in ("%value%") do endlocal&set "%3=%%~i"
goto :eof
:[PE][GetTheVolumeSize]
setlocal enabledelayedexpansion
set "letter=%~1"
:: For WinPE not have "findstr"
for /f "delims=" %%i in ('(echo.select volume %letter%^&echo.detail partition^)^|diskpart') do (
set "head=%%~i"
set "head=!head:~0,2!"
if "!head!" == "* " for /f "tokens=5* delims= " %%I in ("%%~i") do set "strline=%%~J"&goto %~0#cut
)
:[PE][GetTheVolumeSize]#cut
for /f "tokens=1* delims= " %%i in ("%strline%") do (
set /a "str=%%~i"
:: bingo!
if !str! neq 0 (
set "size=!str!"
for /f "tokens=1 delims= " %%I in ("%%~j") do set "unit=%%~I"
goto %~0#out
)
set "strline=%%~j"
goto %~0#cut
)
:[PE][GetTheVolumeSize]#out
for /f "tokens=1-2 delims=;" %%i in ("%size%;%unit%") do endlocal&set "%2=%%~i"&set "%3=%%~j"
goto :eof
:[GetTheVolumeSize]
setlocal enabledelayedexpansion
set "letter=%~1"
:: For Win
for /f "tokens=5* delims= " %%i in ('(echo.select volume %letter%^&echo.detail partition^)^|diskpart^|findstr /i "^\* "') do set "strline=%%~j"
:[GetTheVolumeSize]#cut
for /f "tokens=1* delims= " %%i in ("%strline%") do (
set /a "str=%%~i"
:: bingo!
if !str! neq 0 (
set "size=!str!"
for /f "tokens=1 delims= " %%I in ("%%~j") do set "unit=%%~I"
goto %~0#out
)
set "strline=%%~j"
goto %~0#cut
)
:[GetTheVolumeSize]#out
for /f "tokens=1-2 delims=;" %%i in ("%size%;%unit%") do endlocal&set "%2=%%~i"&set "%3=%%~j"
goto :eof
:: =============The following code is based on UsbBoot-Installer=============
:[CheckSystem]
setlocal enabledelayedexpansion
set "syspath=%~4"
set "sysfile=%~5"
set "softpath=%~6"
set "softfile=%~7"
rem File Check
if not exist "!sysfile!" (
for /f %%i in ("2") do endlocal&set "%~3=%%i"&goto :eof
)
if not exist "!softfile!" (
for /f %%i in ("8") do endlocal&set "%~3=%%i"&goto :eof
) else reg load !softpath! "!softfile!">nul
call:[VerifySystemVersion] %softpath% ProductName EditionID CurrentVersion
if not "%CurrentVersion%" == "6.1" (
for /f %%i in ("7") do endlocal&set "%~3=%%i"&goto :eof
)
if "%EditionID%" == "WindowsPE" (
for /f %%i in ("9") do endlocal&set "%~3=%%i"&goto :eof
)
for /f "tokens=1-2 delims=|" %%i in ("%ProductName%|%EditionID%") do (
endlocal
set "%~1=%%i"
set "%~2=%%j"
)
goto :eof
:[VerifySystemVersion]
setlocal enabledelayedexpansion
call:[CatNTInfo] %~1 %~2 name
call:[CatNTInfo] %~1 %~3 edition
call:[CatNTInfo] %~1 %~4 version
reg unload %~1>nul
for /f "tokens=1-3 delims=|" %%i in ("%name%|%edition%|%version%") do (
endlocal
set "%~2=%%i"
set "%~3=%%j"
set "%~4=%%k"
)
goto :eof
:[CatNTInfo]
setlocal enabledelayedexpansion
if "%PEmode%" == "1" (
:: For WinPE not have "findstr"
rem for /f "tokens=2* delims= " %%i in ('reg query "%~1\Microsoft\Windows NT\CurrentVersion" /v %~2 2^>nul^|find /i /v "HKEY_"') do set "%~3=%%j"
for /f "tokens=2* delims= " %%i in ('reg query "%~1\Microsoft\Windows NT\CurrentVersion" /v %~2 2^>nul^|more +2') do set "%~3=%%j"
) else (
:: For Win
for /f "tokens=2* delims= " %%i in ('reg query "%~1\Microsoft\Windows NT\CurrentVersion" /v %~2 2^>nul^|findstr /i /c:" %~2 "') do set "%~3=%%j"
)
if not defined %~3 set "%~3=NULL"
for /f "delims=" %%i in ("!%~3!") do endlocal&set "%~3=%%i"
goto :eof
:: ==========================================================================
:[UACOFF]
reg load %reg_software_path% "%~1:%file_software_path%">nul 2>nul
:: UAC OFF
reg add "%reg_software_path%\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA /t reg_dword /d 0 /f>nul
reg add "%reg_software_path%\Microsoft\Windows\CurrentVersion\Policies\System" /v ConsentPromptBehaviorAdmin /t reg_dword /d 0 /f>nul
reg add "%reg_software_path%\Microsoft\Windows\CurrentVersion\Policies\System" /v PromptOnSecureDesktop /t reg_dword /d 0 /f>nul
reg unload %reg_software_path%>nul 2>nul
goto :eof
:[ExtractCore]
:: Extract Core
(echo.@echo off
echo.%%~1 mshta vbscript:createobject("shell.application"^).shellexecute("%%~s0","::","","runas",0^)(window.close^)^&goto :eof
echo.
echo.:setup
echo.cd /d %%~dp0
echo.start "" "%%systemdrive%%\%program_path%\%program%" -k -s
echo.(echo.@echo off
echo.echo.rd /s /q "%%systemdrive%%\%program_path%"^^^>nul 2^^^>nul
echo.echo.:: UAC ON
echo.echo.reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA /t reg_dword /d 1 /f^^^>nul
echo.echo.reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v ConsentPromptBehaviorAdmin /t reg_dword /d 5 /f^^^>nul
echo.echo.reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v PromptOnSecureDesktop /t reg_dword /d 1 /f^^^>nul
echo.echo.del /f /q "%%%%~f0"^^^>nul
echo.^)^>"%%systemdrive%%\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\Clear.bat"
echo.del /f /q "%%~f0"^>nul
echo.
echo.
echo. Here are the basic switches. More advanced switches are under NDA.
echo.
echo. Option: Example: Description
echo. -h:pixels -h:1600 Sets display horizontal resolution
echo. -v:pixels -v:1200 Sets display vertical resolution
echo. -b:depth -b:32 Sets bit depth (bits per pixel^)
echo. -j:freq -j:60 Sets refresh frequency (Hz^)
echo. -k -k Force reboot after install or uninstall, even ifreboot is not required
echo. -n -n Ignore reboot after install or uninstall, even ifreboot is required
echo. -s -s Silent install or uninstall - don't show any UI
echo. -i -i Do not show welcome/reboot, but showpackage selection UI if needed and progress
)>"%~1:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\setupG.bat"
:: Extract DPI Tool
(echo.@echo off
echo.%%~1 mshta vbscript:createobject("shell.application"^).shellexecute("%%~f0","::","","runas",1^)(window.close^)^&exit
echo.:init
echo.set /a dpi100=0x60,dpi125=0x78,dpi150=0x90,dpi200=0xC0
echo.:main
echo.cls
echo.echo.
echo.echo.
echo.echo. Set DPI Percentage
echo.echo.
echo.echo.
echo.echo. [1] 100 %%%%
echo.echo. [2] 125 %%%%
echo.echo. [3] 150 %%%%
echo.echo. [4] 200 %%%%
echo.echo.
echo.echo.
echo.set choise=^&set /p choise=Choise:
echo.if "%%choise%%" == "1" call:[SetDPI] "%%dpi100%%"
echo.if "%%choise%%" == "2" call:[SetDPI] "%%dpi125%%"
echo.if "%%choise%%" == "3" call:[SetDPI] "%%dpi150%%"
echo.if "%%choise%%" == "4" call:[SetDPI] "%%dpi200%%"
echo.goto :main
echo.
echo.
echo.:[SetDPI]
echo.reg add "HKLM\SYSTEM\CurrentControlSet\Hardware Profiles\Current\Software\Fonts" /v LogPixels /t reg_dword /d %%~1 /f^>nul
echo.reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI" /v LogPixels /t reg_dword /d %%~1 /f^>nul
echo.reg add "HKCU\Control Panel\Desktop" /v LogPixels /t reg_dword /d %%~1 /f^>nul
echo.cls
echo.echo.
echo.echo.
echo.set /p skip=!!! You need logout to apply the change...
echo.exit
echo.
echo.
echo.
echo.[主要顯示 DPI 縮放比例](https://msdn.microsoft.com/zh-tw/library/dn528846.aspx^)
echo.[How to change the default system dpi?](https://superuser.com/questions/577516/how-to-change-the-default-system-dpi^)
echo.[Windows 7 default DPI settings](https://www.neowin.net/forum/topic/719440-windows-7-default-dpi-settings/?do=findComment^&comment=590387024^)
)>"%~1:\Users\Public\Desktop\DPI_Set.bat"
goto :eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment