gpt-4o-2024-05-13· OpenAI
WildChat-4.8M (AI2)
create a bat file to run any exe or msi as an admin
- User
create a bat file to run any exe or msi as an admin
- Assistant
Creating a batch file (
.bat) to run an executable (.exe) or an installer (.msi) as an administrator involves using some Windows batch scripting commands. Below is a basic example of how to accomplish this task:- Open Notepad or any text editor.
- Write the following batch script:
@echo off :: BatchGotAdmin :------------------------------------- REM --> Check for permissions >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" REM --> If error flag set, we do not have admin. if '%errorlevel%' NEQ '0' ( echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %*", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" exit /B ) REM --> Clean up if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" :: Now that we have admin privileges, run the desired executable :: Replace "YourProgram.exe" with the actual file name of the EXE or MSI start "" "C:\Path\To\YourProgram.exe" :: or for MSI msiexec /i "C:\Path\To\YourInstaller.msi" pause