Can anyone help me with running vbs from itself but with administrator rights? I need rename computer with Windows 8 via VBScript, but it's possible only if I run my script through administrator command line (CMD → Run as Administrator → runScript.vbs). If I start script with classic CMD the computer isn't renamed.
My idea is I start script with user rights, without parameters and if there is no parameter, the script re-runs itself with admin rights and with parameter as identificator "I'm admin".
Does anyone know how I can do this?
Edit:
I tried this:
If WScript.Arguments.Count = 0 Then Set objShell = CreateObject("Shell.Application") objShell.ShellExecute "wscript.exe", "c:\Users\admin\Documents\selfConfigure.vbs -1", "", runas", 1 End If
To run a script 'As Admin' (with elevated permissions) using VBscript can be done by running ShellExecute and setting the runas flag. This can be used to run an executable, or to run an entire script (batch file or VBScript) with elevated permissions.
Click the Start button, and then click Run. In the Open field, type the full path of the script, and then click OK. You can also type WScript followed by the full name and path of the script you want to run.
Hold down both the Ctrl and the Shift keys on your keyboard and then click or tap on that program's shortcut. You can also use the "Ctrl + Shift + Click/Tap" shortcut on an app's Start Menu tile to run it with administrator permissions in Windows 10.
If UAC is enabled on the computer, something like this should work:
If Not WScript.Arguments.Named.Exists("elevate") Then CreateObject("Shell.Application").ShellExecute WScript.FullName _ , """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1 WScript.Quit End If 'actual code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With