Note that you must use Quotation marks, else the runas command will gobble up the switch option to cmd.Īlso note that the administrative shell (cmd.exe) starts up in the C:\Windows\System32 folder. This isn't what I wanted, but it was easy enough to pass in the current path to my installer, and to reference it using an absolute path. ::: strCommandLine = Trim(objWshProcessEnv("ELEVATE_CMDLINE")) ::: Set objWshProcessEnv = objWshShell.Environment("PROCESS") ::: Set objWshShell = WScript.CreateObject("WScript.Shell") ::: Set objShell = CreateObject("Shell.Application") Set "ELEVATE_CMDLINE=cd /d "%~dp0" & call "%~f0" %*"Ĭscript //nologo temp.vbs & del temp.vbs & exit /b I myself enabled it by opening Administrative Tools, Local Security Policy, then navigating to Local Policies\Security Options and changing the value of the Accounts: Administrative Account Status policy to Enabled, which is none of the three ways shown in the link.Īn even easier way to accomplish this: C:> net user Administrator /active:yes However, here is a great tutorial on how to enable it, in three different ways: Using runas this way requires the administrative account to be enabled, which is not the default on Windows 7 or Vista. ::: objShell.ShellExecute "cmd", "/c " & strCommandLine, "", "runas"įor a demo: self-elevating.bat "path with spaces" arg2 3 4 "another long argument"Īnd this is another version that does not require creating a temp file. You can call PowerShell via its CLI, powershell.exe, in order to call its Start-Process cmdlet, which supports starting processes with elevation doing so has two advantages: ObjShell.ShellExecute "cmd", "/c " & strCommandLine, "", "runas" StrCommandLine = Trim(objWshProcessEnv("ELEVATE_CMDLINE")) Set objWshProcessEnv = objWshShell.Environment("PROCESS") Set objWshShell = WScript.CreateObject("WScript.Shell") Set objShell = CreateObject("Shell.Application") nul & goto :adminĬscript //nologo "%~f0?.wsf" //job:Elevate & exit /b
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |