Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to run scripts as administrator in Windows 7?

38,100 views
Skip to first unread message

Dave "Crash" Dummy

unread,
Jul 16, 2011, 9:15:28 AM7/16/11
to
I have some scripts that require administrator privileges to run in
Windows 7, and I can't run them directly because there is no "Run as
administrator" option in the context menu for .VBS files. I work around
this by creating a shortcut to wscript.exe, with my script as the
argument. The shortcut then has the "Run as administrator" option. This
works, but it is awkward and a pain in the posterior. Is there some way
to add the "Run as administrator" option to script files?
--
Crash

I always thought Mensa was a Japanese import.

PaulM

unread,
Jul 16, 2011, 12:14:02 PM7/16/11
to
Put this code in the start of your script:

Set WshShell = WScript.CreateObject("WScript.Shell")
If WScript.Arguments.length = 0 Then
Set ObjShell = CreateObject("Shell.Application")
ObjShell.ShellExecute "wscript.exe", """" & _
WScript.ScriptFullName & """" &_
" RunAsAdministrator", , "runas", 1
Else

--
Paul's XP and Vista Help
-----------------------------------------
www.paulsxp.com
---------------------------------------
Paul's Forum
--------------------------------------
www.paulsxp.com/forum
--------------------------------------


"Dave "Crash" Dummy" <inv...@invalid.invalid> wrote in message
news:ivs2tm$pja$1...@dont-email.me...

Dave "Crash" Dummy

unread,
Jul 16, 2011, 12:24:50 PM7/16/11
to
PaulM wrote:
> Put this code in the start of your script:
>
> Set WshShell = WScript.CreateObject("WScript.Shell")
> If WScript.Arguments.length = 0 Then
> Set ObjShell = CreateObject("Shell.Application")
> ObjShell.ShellExecute "wscript.exe", """" & _
> WScript.ScriptFullName & """" &_
> " RunAsAdministrator", , "runas", 1
> Else

Cool! That works. Thank you!

--
Crash

"It is not necessary to change. Survival is not mandatory."
~ W. Edwards Deming ~

PaulM

unread,
Jul 16, 2011, 9:54:51 PM7/16/11
to
You are welcome.

--
Paul's XP and Vista Help
-----------------------------------------
www.paulsxp.com
---------------------------------------
Paul's Forum
--------------------------------------
www.paulsxp.com/forum
--------------------------------------


"Dave "Crash" Dummy" <inv...@invalid.invalid> wrote in message

news:ivse0i$r4v$1...@dont-email.me...

gune...@gmail.com

unread,
May 7, 2013, 9:02:47 AM5/7/13
to
Thank you dude =)

On Saturday, July 16, 2011 7:14:02 PM UTC+3, PaulM wrote:
> Put this code in the start of your script:
>
>
>
> Set WshShell = WScript.CreateObject("WScript.Shell")
> If WScript.Arguments.length = 0 Then
> Set ObjShell = CreateObject("Shell.Application")
> ObjShell.ShellExecute "wscript.exe", """" & _
> WScript.ScriptFullName & """" &_
> " RunAsAdministrator", , "runas", 1
> Else
>
> --
> Paul's XP and Vista Help
> -----------------------------------------
> www.paulsxp.com
> ---------------------------------------
> Paul's Forum
> --------------------------------------
> www.paulsxp.com/forum
> --------------------------------------
>
>
> "Dave "Crash" Dummy" wrote in message

kevin....@gmail.com

unread,
Jun 26, 2013, 11:26:37 AM6/26/13
to
www.paulsxp.com---------------------------------------Paul's Forum Hi Paul, I think you were the guy I got that from about 6 years ago. That has worked for me for the past 6 years except for the company I'm back with. Also I noticed I did not see End If at the end but I may have not noticed it. Something funky on our computers. It works for Admins on the network locations I have my scripts but for end users it does not, until I made it Read\Write for all. Now they did a new security update and I'm getting "The script file "File Name" cannot be found.

I'm looking for a fix for the current problem. I think the reason my scripts are failing is I have them on a remote server, it first looks for the current folder, then a subfolder.

The one I've been using is the objShell instead of WshShell. I had a gap in my programming from 1983 to 2007. Paul, would you please tell me what the different is? I've researched this for years and get mixed answers and none of them are straight forward. I also wonder about what the difference is between ObjShell = CreateObject("Shell.Application") and ObjShell = WScript.CreateObject("Shell.Application")

I've tried variations but they all end with the same Result, it calls out the name of the script and says it can't find it. I'm stubborn and don't like asking for help or directions :).

kristanra...@gmail.com

unread,
Oct 2, 2013, 7:01:10 AM10/2/13
to
Watch this..
http://www.youtube.com/watch?v=8RR4p2vCoBk
Vbscript to application as administrator.

tan2x

unread,
Oct 2, 2013, 2:34:59 PM10/2/13
to
Dave Crash Dummy wrote on 07/16/2011 09:15 ET :
> I have some scripts that require administrator privileges to run in
> Windows 7, and I can't run them directly because there is no "Run as
> administrator" option in the context menu for .VBS files. I work around
> this by creating a shortcut to wscript.exe, with my script as the
> argument. The shortcut then has the "Run as administrator" option.
> This
> works, but it is awkward and a pain in the posterior. Is there some way
> to add the "Run as administrator" option to script files?
> Crash
>
> I always thought Mensa was a Japanese import.
>
Automate everything including password input..
http://www.youtube.com/watch?v=8RR4p2vCoBk

PaulM

unread,
Oct 3, 2013, 9:36:18 AM10/3/13
to
"tan2x" wrote in message
news:WbqdnctUIo3O-tHP...@giganews.com...
This is what I used in my scripts:

If WScript.Arguments.length = 0 Then
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "wscript.exe", """" & _
WScript.ScriptFullName & """" &_
" RunAsAdministrator", , "runas", 1
Else


-----------------------------------------------------------
Paul's XP, Vista and Windows 7 Help
-----------------------------------------------------------
www.paulsxp.com
www.paulsxp.com/forum
---------------------------------------------------------

medaz...@gmail.com

unread,
Apr 11, 2014, 4:01:45 AM4/11/14
to
Open a cmd as an administrator. Open you vb using the absolute path between quotes. "C:/...."
0 new messages