queen_mszdia
Programmer
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
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