1

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
Community
  • 1
  • 1
Falhuddin
  • 83
  • 1
  • 9
  • Possible duplicate of [Capture output value from a shell command in VBA?](https://stackoverflow.com/questions/2784367/capture-output-value-from-a-shell-command-in-vba) – Pᴇʜ Oct 23 '17 at 13:22
  • My Shell command need to run 2 times (Reuse existing shell) before capture the Shell output : (1) Run Shell as Admin privilege + Code to run. (2) Wait 3 second and Paste the Admin Password. Is it possible to execute above command at the same time? or Run Shell As Admin include Password + Code? – Falhuddin Oct 24 '17 at 00:22
  • i posted some code here earlier today that runs a command string ... parts of it may or may not help ..... https://stackoverflow.com/questions/46857148/locate-folder-path-based-on-a-cell-value-with-a-combo-box/46900124#46900124 – jsotola Oct 24 '17 at 06:45
  • here is some code that elevates the user https://stackoverflow.com/questions/7044985/how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-administrator/12264592#12264592 ..... also google "elevate.bat" – jsotola Oct 24 '17 at 06:50

0 Answers0