PDA

View Full Version : Vista/XP Shortcut with "run-as" ?


jassing
02-13-2008, 11:22 AM
Anyone know how to create (or modify) a shortcut to enable the run-as administrator in vista or xp? (Programmatically, of course).

PaulShafft
08-15-2008, 04:43 AM
My shortcuts in Vista won't work unless the user clicks "Run as administrator". Is there any way to create such a shortcut with SetupFactory 7 ?

Thanks,
Paul.

jcuster
08-15-2008, 11:02 AM
This is a vbs script that does the runas programically. I got it from the WSNAME instructions.

fill in the user, Password and command varibles execute it.


Option Explicit

Const USER = "" UserName
Const PASS = "" Password
Const WSNAME_COMMANDLINE = "" Command Line

Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim WSHShell : Set WshShell = CreateObject("WScript.Shell")
Dim WshNetwork : Set WshNetwork = CreateObject("WScript.Network")
Dim oDic : Set oDic = CreateObject("Scripting.Dictionary")
Dim objArgs : Set objArgs = WScript.Arguments
Dim oProcessEnv : Set oProcessEnv = WshShell.Environment("PROCESS")

Dim sPathToRunAs, iReturnCode

sPathToRunAs = oProcessEnv("SystemRoot")&"\System32\runas.exe"

if Not fso.FileExists(sPathToRunAs) Then : WScript.Quit(1) 'Can't find RunAs

iReturnCode=WshShell.Run("runas /user:" & USER & " " & CHR(34) & WSNAME_COMMANDLINE & CHR(34), 2, FALSE)
Wscript.Sleep 40 ' Time for window to open.
WshShell.AppActivate(sPathToRunAs)' Activate the Window
WSHShell.SendKeys PASS & "~" ' Send the password