0

I'm attempting to call some code remotely using Window 10 WMIC.

rem command prompt, machine 1 (main computer)
WMIC /node:"MACHINE_2" process call create "cmd.exe /k "%USERPROFILE%\test.vbs" "

This call seems to go through correctly. It produces partial output from test.vbs (shown below), which means the file is called and executing.

' test.vbs, machine 2 (MACHINE_2, in above code)
Set objFSO=CreateObject("Scripting.FileSystemObject")

outFile="%USERPROFILE%\out.txt"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "test1" & vbCrLf
objFile.Close

MsgBox("hi")
' CreateObject("WScript.Shell").Run "cmd /c ""nircmd.exe sendkey 0xB3 press"" ", 0
' Set WshShell = Nothing

outFile="%USERPROFILE%\out.txt"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "test2" & vbCrLf
objFile.Close

Expected behaviour: The script should write "test1" to out.txt. Then it should open a MsgBox. And after the MsgBox is closed on Machine_2, it should override the contents of out.txt with "test2."

The two lines of commented code below MsgBox can be substituted for the MsgBox code, and also have the same behaviour.

When executing the vbs file locally, the expected behaviour happens. However, when using the WMIC call, "test1" is printed, and then execution seems to stop. The MsgBox is never shown, and "test2" never overrides the content of out.txt.

I'm quite lost as to why this happens, and the steps I might take to make it work. At this point I've exhausted my google-fu.

fat_flying_pigs
  • 92
  • 1
  • 4
  • 14
  • You should never be displaying messageboxes on any code that may need to be automated or run automatically. Who is there to press the OK button? Anyway... I assume MY_SERVER is your local machine? To troubleshoot, replace environment specific values like `%USERPROFILE%` with hard coded values and see if it works as expected. Use this to isolate the problem. If you have an entire script that doesn't function correctly, then your next step is to find the _line_ that doesn't function. Lastly, take a look in the windows event log for clues – Nick.Mc Apr 30 '18 at 03:51
  • Oh and.... in order to run VBS you need to run it against `CScript.EXE`, not `CMD.exe`. There is Kind of an example here: https://gist.github.com/cornfred/6678466 – Nick.Mc Apr 30 '18 at 03:52
  • Thanks for the comment reply. I've edited the question for clarity. MY_SERVER is the 2nd machine, the one I am attempting to run the vbs code on. %USERPROFILE% is working correctly, as 1. the vbs script is called and 2. out.txt does contain output. I have replaced it with hard coded values with no change. The _line_ that doesn't work is the MsgBox line (or two commented lines below it). – fat_flying_pigs Apr 30 '18 at 16:38
  • Using cscript.exe instead doesn't seem to do anything different. `"cscript "%USERPROFILE%\test.vbs" "` – fat_flying_pigs Apr 30 '18 at 16:44
  • The second machine is a different machine? You aren’t going to see a message box pop up on a different machine. – Nick.Mc Apr 30 '18 at 20:51
  • I wont see a message box pop up on Machine 2's dedicated monitor?? Why not? – fat_flying_pigs Apr 30 '18 at 21:27
  • TBH I haven't tested it but.... popping up messageboxes remotely is something that just won't work. If you check task manager on the remote machine you might find something in there. This link http://www.itprotoday.com/management-mobility/rem-using-wmi-create-remote-interactive-processes seems to explain when and why it doesn't work, and also suggests a workaround. Also, do you expect `%USERPROFILE%` to resolve to _your_ userprofile or the person logged on to the other machine? Because there might be three people logged on to the other machine - which one do you expect? – Nick.Mc Apr 30 '18 at 22:51
  • You likely will not see the messagebox on Machine 2 because the script will be running under the SYSTEM context, not the user context. SCCM has a way of allowing SYSTEM context popups show to the user, however I am unaware of any way to do this - may be worth looking at PSEXEC? – Sam H May 01 '18 at 07:27

1 Answers1

0

You CANNOT display a user interface on remote scripts.

You may not mess with the logged on user.

  • Could you provide more details as to why this is the case, or what policies or standards are in place to enforce this behaviour? I specifically _want_ to "mess" with the user in this case; eg: send keystrokes, show timed ui elements, etc. – fat_flying_pigs Apr 30 '18 at 16:47