user288645
user288645

Reputation: 329

How can I run my application when windows session is disconnected?

I have made a simple application in C# and WHITE, which click on a button to clear the logs. I use to connect to my test machine using Remote Desktop Connection and execute that application. It works fine when my session is connected but whenever i disconnect my session, it stops working.

Is there any way to execute that application when windows session is disconnected?

Upvotes: 0

Views: 3744

Answers (4)

Jason
Jason

Reputation: 41

Taken from https://www.ranorex.com/help/latest/ranorex-remote/remote-faq#c13444

Create a batch file on your remote machine and insert the code below:

for /f "skip=1 tokens=3 usebackq" %%s in (
  `query user %username%`
) do (
 %windir%\System32\tscon.exe %%s /dest:console
)

Save this batch file on the desktop of your remote machine and name it: 'KeepSessionOpen.bat'. If you need to disconnect the RDP session, you can now simply run this batch file using administrator privileges and your remote machine will remain unlocked.

Upvotes: 0

Merlyn Morgan-Graham
Merlyn Morgan-Graham

Reputation: 59151

It works fine when my session is connected but whenever i disconnect my session, it stops working.

This is by design. When you disconnect your session, it is locked. When your session is locked, UI automation won't work.

You could hack around this by never locking the session, possibly via different remote desktop tools (VNC/PcAnywhere). But this is definitely a hack.

Instead I suggest a different approach. I recommend avoiding UI automation whenever possible. I have always found UI automation to be flaky and unreliable.

In the comments on your question you said your app is simply UI automation to click a button to clear a log. The logs are generated by the DebugView application.

I suggest you log to a file instead. This feature is mentioned on the web site for DebugView:

http://technet.microsoft.com/en-us/sysinternals/bb896647

You could also look into using remote monitoring.

If size is an issue, you can also look into the "Log file wrapping" and "log-file rollover" features.

Upvotes: 0

Guillaume
Guillaume

Reputation: 13138

You could also use the task scheduler. You may not need the C# wrapper, you can add yourself the required entry within the scheduler.

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039588

You could write a Windows Service.

Upvotes: 2

Related Questions