Check or detect whether user is currently connected via RDP / MSTSC

m1chael

New Member
Joined
Nov 12, 2013
Messages
16
Hi,

I am looking for a way of checking or detecting whether the user is currently connected via RDP / MSTSC.

I think I'm half-way there as I can use the ENVIRON$("SESSIONNAME") variable to get either "CONSOLE" or "RDP*". If that variable is "RDP*" then this gives me half of what I need.

However, that variable doesn't tell me whether the user is currently connected and actively viewing the RDP session at that point in time. If the user has disconnected their view, that variable doesn't give me the answer. I need to know whether the user is actually connected at that point in time.

I've separately found code online that detects whether the user has locked their workstation. I had suspected this might work, but unfortunately it returns that the workstation is unlocked even when RDP is disconnected.

Can anyone help?

Thanks,
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Please clarify: You want to check if
a remote user is using RDP to view another computer
or
you want to check if a remote user is viewed from another computer
or
a local user (local computer) is using RDP to view another computer
or
a local user (local computer) is viewed by RDP from another computer
 
Upvote 0
Hi,
From my laptop, I am connecting to a desktop via RDP.
While connected via RDP, I will then start a macro on that desktop.
I will leave that macro running and disconnect from RDP. The macro will continue to run on the desktop even though I'm not viewing it.
At various points while the macro is running, I may reconnect to the desktop again via RDP (to view only - check on progress - but not interrupt the running macro).
I want the macro (at any time while it is running on the desktop) to be able to know:
(1) Whether it was started when I was connected via RDP - I can do this using ENVIRON$("SESSIONNAME").
(2) Whether I am currently connected via RDP and watching the macro process - I don't know how to do this.
 
Upvote 0
Hi,
Thank you - I've tried running this via CMD command prompt and it gives me what I need I think.
However, when I try running the same query via Excel using Shell to output the response to a text file, I just get a blank output.
 
Upvote 0
It seems like there is something about "query session" or "query user" that isn't working.
I can get the output of "dir C:" for example within Excel ok, but if I replace that with the above, I just get a blank output.
Any ideas?
 
Upvote 0
This appears to be a separate issue, so I am going to close this thread, and open a new one with the new issue. Thanks.
 
Upvote 0
Hi, I solved the issue myself so didn't post a new thread.

When I type "quser" into command prompt, it worked.

However, when I ran from Excel VBA, I had to specify the full path "C:\Windows\WinSxS\amd64_microsoft-windows-t..commandlinetoolsmqq_31bf3856ad364e35_10.0.16299.15_none_4c159d541d2991ac\quser.exe" for it work for some reason...
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top