Finding out the parameter used for invoking mstsc.exe is fairly easy with a simple script using WMI (which is wholly native).
CLI mstsc errorlevel
I have an issue trying to connect to a remote system with mstsc. Occasionally it times out. I have a rough outline of a decent bat to try to connect, then try again if mstsc fails. The issue that's complicating matters is that once mstsc is executed even if it fails to connect I get errorlevel 0.
As an experiment, I tried to connect to a non-existent system. I got the popup re: Remote Desktop can't connect to the remote computer for one of these reasons: but the bat thought it was successful. As an experiment I tried a more direct test with the test code below from my beta bat, which displayed IT SAYS IT DID WORK.
start /WAIT mstsc %srv%.rdp /h:1280 /w:1024 /v:%srv% /prompt && echo IT SAYS IT DID WORK
if I tried the reverse, it did NOT return the expected error message.
start /WAIT mstsc %srv%.rdp /h:1280 /w:1024 /v:%srv% /prompt || echo IT SAYS IT FAILED
Of course I also echoed the errorlevel, and it's 0 whether or not I actually connect/log in.
Am I missing something? Does anyone have a non-powershell method to actually determine if mstsc fails?
Windows for home | Previous Windows versions | Apps
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
3 answers
Sort by: Most helpful
-
Anonymous
2018-11-30T19:30:41+00:00 -
Anonymous
2018-11-30T15:10:39+00:00 Thanks for the suggestion. Unfortunately we have a strictly controlled environment so I have to try to work with standard windows tools. I was working with call and then netstat to check for an active connection to the right server, but the question is the timing, when to kick off another mstsc. It would be simple if there was just ONE connection, so tasklist would work, but since we may have more than one connection at a time and I can't determine how to use tasklist, even w. /V to identify the specific process kicked off by the current iteration. Again, thanks for the suggestion.
-
Anonymous
2018-11-30T12:48:11+00:00 Console commands usually return an error level but applications often don't. Mstsc.exe is more of an application than a console command. The best you can do is probably run the downloadable utility nc.exe in order to test if port 3389 on the RDP host responds.