Bruno Romano
Bruno Romano

Reputation: 303

WIndows service run desktop program in Remote Desktop

I need launch program in remote desktop, this program open a window and need user interact, but my application is a windows service.

I'm using windows 2008. I'm created an application with success but launch program only session connect with mouse, keyboard, but I need launch in RDP.

Now I'm using these functions.

WTSEnumerateSessions (enum all sessions, here I know if RDP)
WTSQueryUserToken (Get user token)
DuplicateTokenEx ( make a primary token)
CreateProcessAsUser (run application with SI.lpDesktop = _T("winsta0\\default"))

But this only work success for run application in console connect to keyboard, mouse, monitor, not RDP.

Anyway can help me ? thanks.

Upvotes: 0

Views: 2540

Answers (2)

Dan Ports
Dan Ports

Reputation: 1451

So you're trying to launch a GUI application in a particular RDP session on the machine? You have the right idea, more or less, though you may be missing a few pieces. Take a look at the ProcessHelper class in the source for automated tests of the Cassia library. You can remove a lot of the managed cruft for use in C++. You can also omit the GetTokenInformation( ...TokenInformationClass.TokenLinkedToken... ) nonsense if you don't need to run the process with elevated permissions. This code has been tested on every version of Windows since Windows XP.

Note also that calling WTSQueryUserToken requires the SE_TCB_NAME privilege (which the LocalSystem account has by default).

Upvotes: 3

Bruno Romano
Bruno Romano

Reputation: 303

Ok, thanks Dan Ports

That solved my problem.

The problem is permissions. I configure these three permissions.

SetPrivilege(hpToken, SE_ASSIGNPRIMARYTOKEN_NAME, TRUE);
SetPrivilege(hpToken, SE_INCREASE_QUOTA_NAME, TRUE);
SetPrivilege(hpToken, SE_TCB_NAME, TRUE);

Note: SetPrivilege function I created.

And work's fine. Thanks again.

Upvotes: 0

Related Questions