简体   繁体   中英

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.

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM