From: NickB on
I can remove a program with a script as an administrator. However, I want to
uninstall a program when I am logged in as a user. The system has been
disabled for users. Therefore I am trying to use runas. But it does not take
the password!
Any ideas?

On Error Resume Next
dim WShell,objFSO

strUser=administrator
strPassWord=password
strApp=appwiz.cpl

set WShell = CreateObject("WScript.Shell")
set WEnv = WShell.Environment("Process")
WinPath = WEnv("SystemRoot")&"\System32\runas.exe"
set objFSO = CreateObject("Scripting.FileSystemObject")

if objFSO.FileExists(winpath) then
wscript.echo winpath & " " & "verified"
else
wscript.echo "!! ERROR !!" & VBCRLF & "Can't find or verify " & winpath &"."
set WShell=Nothing
set WEnv=Nothing
set objFSO=Nothing
wscript.quit
end if

rc=WShell.Run("runas /user:" & strUser & " " & CHR(34) & strApp & CHR(34),
3, FALSE)
Wscript.Sleep 100
WShell.AppActivate(WinPath)
Wscript.Sleep 100
WShell.SendKeys("password{ENTER}")

set WShell=Nothing
set WEnv=Nothing
set objFSO=Nothing

wscript.quit
'End of Script

From: ESP on
If I remember correctly, runas.exe does not allow you to pass it a password,
only userID.

ESP

RUNAS USAGE:
RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ]
/user:<UserName> program
RUNAS [ [/noprofile | /profile] [/env] [/savecred] ]
/smartcard [/user:<UserName>] program

/noprofile specifies that the user's profile should not be loaded.
This causes the application to load more quickly, but
can cause some applications to malfunction.
/profile specifies that the user's profile should be loaded.
This is the default.
/env to use current environment instead of user's.
/netonly use if the credentials specified are for remote
access only.
/savecred to use credentials previously saved by the user.
This option is not available on Windows XP Home Edition
and will be ignored.
/smartcard use if the credentials are to be supplied from a
smartcard.
/user <UserName> should be in form USER(a)DOMAIN or DOMAIN\USER
program command line for EXE. See below for examples





"NickB" wrote:

> I can remove a program with a script as an administrator. However, I want to
> uninstall a program when I am logged in as a user. The system has been
> disabled for users. Therefore I am trying to use runas. But it does not take
> the password!
> Any ideas?
>
> On Error Resume Next
> dim WShell,objFSO
>
> strUser=administrator
> strPassWord=password
> strApp=appwiz.cpl
>
> set WShell = CreateObject("WScript.Shell")
> set WEnv = WShell.Environment("Process")
> WinPath = WEnv("SystemRoot")&"\System32\runas.exe"
> set objFSO = CreateObject("Scripting.FileSystemObject")
>
> if objFSO.FileExists(winpath) then
> wscript.echo winpath & " " & "verified"
> else
> wscript.echo "!! ERROR !!" & VBCRLF & "Can't find or verify " & winpath &"."
> set WShell=Nothing
> set WEnv=Nothing
> set objFSO=Nothing
> wscript.quit
> end if
>
> rc=WShell.Run("runas /user:" & strUser & " " & CHR(34) & strApp & CHR(34),
> 3, FALSE)
> Wscript.Sleep 100
> WShell.AppActivate(WinPath)
> Wscript.Sleep 100
> WShell.SendKeys("password{ENTER}")
>
> set WShell=Nothing
> set WEnv=Nothing
> set objFSO=Nothing
>
> wscript.quit
> 'End of Script
>
From: ESP on
Your workaround to this will be PSEXEC ;-)
http://www.sysinternals.com/Utilities/PsTools.html

ESP




"NickB" wrote:

> I can remove a program with a script as an administrator. However, I want to
> uninstall a program when I am logged in as a user. The system has been
> disabled for users. Therefore I am trying to use runas. But it does not take
> the password!
> Any ideas?
>
> On Error Resume Next
> dim WShell,objFSO
>
> strUser=administrator
> strPassWord=password
> strApp=appwiz.cpl
>
> set WShell = CreateObject("WScript.Shell")
> set WEnv = WShell.Environment("Process")
> WinPath = WEnv("SystemRoot")&"\System32\runas.exe"
> set objFSO = CreateObject("Scripting.FileSystemObject")
>
> if objFSO.FileExists(winpath) then
> wscript.echo winpath & " " & "verified"
> else
> wscript.echo "!! ERROR !!" & VBCRLF & "Can't find or verify " & winpath &"."
> set WShell=Nothing
> set WEnv=Nothing
> set objFSO=Nothing
> wscript.quit
> end if
>
> rc=WShell.Run("runas /user:" & strUser & " " & CHR(34) & strApp & CHR(34),
> 3, FALSE)
> Wscript.Sleep 100
> WShell.AppActivate(WinPath)
> Wscript.Sleep 100
> WShell.SendKeys("password{ENTER}")
>
> set WShell=Nothing
> set WEnv=Nothing
> set objFSO=Nothing
>
> wscript.quit
> 'End of Script
>
From: deckhopper on
Try the following:

' ##############################################
' Start Script
' ##############################################

'Script assumes Win2k or WinXP
'Change 'domain' variable to suit needs
'Change 'program' variable to suit needs

Option Explicit

Dim objShell, objNetwork
Dim domain, program, domainUser

Set objShell=CreateObject("WScript.Shell")
Set objNetwork=WScript.CreateObject("WScript.Network")

domain = objNetwork.ComputerName
program = "control appwiz.cpl"
'program = "mmc %windir%\system32\lusrmgr.msc"
'program = "control userpasswords2"

domainUser = getUserName
Wscript.Sleep 1000
runAsDomainUser domain, domainUser, program


'*******************************************************
Function runAsDomainUser(fxDom, fxUser, fxProgram)

Msgbox "runas /env /user:" & fxDom & "\" _
& fxUser & " " & Chr(34) _
& fxProgram & Chr(34) & "", _
0, "This is what is being passed to RUNAS"

objShell.Run "runas /env /user:" & fxDom _
& "\" & fxUser & " " & Chr(34) _
& fxProgram & Chr(34) & "", 1, False

End Function
'*********************************************|

'*******************************************************
Function getUserName

getUserName = _
InputBox("Enter your Domain or Local" _
& " Computer User-Name")

If getUserName = "" Then
quitscript
End If

End Function
'*********************************************|

'*******************************************************
Sub quitscript

MsgBox "Quitting Now"
Wscript.Quit

End Sub
'*********************************************|
' ##############################################
' End Script
' ##############################################