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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

invoke runas different user from inside VbScript

Status
Not open for further replies.

queen_mszdia

Programmer
Mar 8, 2022
1
0
0
SG
Hi im trying to invoke runas as different user and open a .exe application from my vbscript.

I have tried to use WshShell Exec() method but not sure how to pass in the runas parameter. Tried with WshShell.Run() method but it throw a runtime error. Below is my sample code

Dim path
Dim WshShell

Sub Launch()
Set WshShell = CreateObject(“WScript.Shell”)
Set path = WshShell.Run(“C:\Windows\System32\runas.exe /user:domain\xyzuser notepad.exe”,5,False)

WScript.Sleep (2000)
WshShell.AppActivate “C:\Windows\System32\runas.exe”
WScript.Sleep (10000)
WshShell.SendKeys “Hello”
End Sub

Sub Quit1()
If path.Status=0 Then WshShell.SendKeys “%{F4}”
WScript.Sleep (2000)
If path.Status=0 Then WshShell.SendKeys “{TAB}”
WScript.Sleep (2000)
If path.Status=0 Then WshShell.SendKeys “{ENTER}”
End Sub

Call Launch()
WScript.Sleep (2000)
Call Quit1()

I get this error message: ‘WshShell.Run(…)’
Code: 800A01A8
Source: Ms VbScript runtime error

Any help will be appreciated. Cheers

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top