Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows7 Script Problem

Status
Not open for further replies.

wotsit

MIS
Oct 18, 2002
47
0
0
GB
Hi,

I'm hoping somebody can help me please?

I've created a script to install some software, so that it can be deployed through our deployment solution.

The script works successfully on Windows XP desktops, but not on Windows 7 desktops. It will only run on a Windows 7 desktop if you manually log on to it, run a command prompt as the administrator and then run the script from there. It seems like the Windows 7 user access control is preventing the script from running as it doesn't work from a non elevated command prompt.

Is there a way to run a script with elevated administrator rights on Windows 7? I've tried using the runas command, but it doesn't seem to work.

Any help would be much appreciated.

Thanks,
H
 
You are correct that UAC gets in the way. Can't remember where I found this workaround, but if you put the following at the beginning of your scripts, they should run successfully:

Code:
If WScript.Arguments.Named.Exists("elevated") = False Then 
	'Launch the script again as administrator 
	CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 1 
	WScript.Quit 
Else 
	'Change the working directory from the system32 folder back to the script's folder. 
	Set oShell = CreateObject("WScript.Shell") 
	oShell.CurrentDirectory = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) 
	MsgBox "Now running with elevated permissions" 
End If

The caveat to this workaround is that you will still see a "Are you sure you want to run this" prompt from UAC, but clicking yes will now allow it to run.

Cheers!
[cheers]

-Carl
"The glass is neither half-full nor half-empty: it's twice as big as it needs to be."

[tab][navy]For this site's posting policies, click [/navy]here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top