I have some issue to capture result from Shell command. Here's My code :
Shell "runas.exe /user:technician ""C:\Work\test.bat""", vbNormalFocus
Application.Wait (Now + TimeValue("0:00:03"))
SendKeys pass & "{ENTER}"
Sheets("File").Cells(1, 1) = Shell 'Here to paste the result
My "test.bat" file contain "PING 'ComputerName'" for test purpose only because I have other complicated command that 10 second to run. Code as below (To detect ProxyServer in Domain by each user) :
reg query "\\PECPC021\HKU\S-1-5-21-3026626878-399171236-2381696588-4970\software\microsoft\windows\currentversion\internet settings" /s | find /i "ProxyServer"
And this command below can capture data but cannot use "runas.exe" function because I need to combine with "SendKeys" and "Wait" function to paste the password.
strShellCommand = "runas.exe /user:technician ""C:\Work\test.bat"""
Set oSh = CreateObject("WScript.Shell")
Set oEx = oSh.Exec(strShellCommand) 'command can be combine in the "exec" Function?
strbuf = oEx.stdOut.ReadAll
Sheets("File").Cells(1, 1) = strbuf