Windows – How to allow VB scripts to run on an admin account

user-accountsvbscriptwindows 8windows 8.1

I'm encountering an issue with the VBscripts while I try to run them. I'm working on Windows 8.1 update 1 Enterprise, connected to an Enterprise domain, and I'm logged with a domain account. This domain account has been added to the Administrators group.

My VBscript must create a folder and a log file into the Program Files (x86) directory. If I run this VBscript by double-clicking on it with the local administrator account, it works perfectly. But if I try to run the same VBscript with my domain account, I get the error message Access denied.

One solution is to totally deactivate the UAC (with the enableLUA registry value set to 1), but this method blocks the Modern UI applications, and we need to keep these applications execution.

Is it possible to grant the full control to VBScripts execution on any admin account, like it is the case under the local administrator built-in account ? I didn't yet find any solution to this problem, and I can't believe that no solution exists, especially in enterprise.

Best Answer

the way I normally do this is to stick the following code at the top of my script:

If Not WScript.Arguments.Named.Exists("elevate") Then
  CreateObject("Shell.Application").ShellExecute WScript.FullName _
    , WScript.ScriptFullName & " /elevate", "", "runas", 1
End If

This way, if I launch the VBS as a non admin - it tries to run, notices I'm not an admin and then relaunches - prompting me to run as admin and away we go.

I know its a pain, but its a fairly simple solution.

Hope this helps