Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 874247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:04:31+00:00 2026-05-15T11:04:31+00:00

In Windows Vista/7/2008/2008R2, is it at all possible to launch a process in a

  • 0

In Windows Vista/7/2008/2008R2, is it at all possible to launch a process in a user’s session from a service? Specifically, the local session would be most useful.

Everything I’ve been reading seems to say this isn’t possible, but I figured I’d ask here before giving up completely.

I’m coding in VB.NET, but will take suggestions in anything.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:04:32+00:00Added an answer on May 15, 2026 at 11:04 am

    It is really possible. The main problem which you have is that Windows should be seen as a terminal server and a users session as a remote session. Your service should be able to start a process which run in the remote session belongs to the user.

    By the way, if you write a service which run under Windows XP which is not added to a domain and the fast user switching is activated, you can have the same problems to start a process on running on the second (third and so on) logged users desktop.

    I hope you have a user token, which you receive for example with respect of impersonation or you have a dwSessionId of session. If you don’t have it you can try use some WTS-function (Remote Desktop Services API http://msdn.microsoft.com/en-us/library/aa383464.aspx, for example WTSEnumerateProcesses or WTSGetActiveConsoleSessionId) or LSA-API to find out the corresponding users session (LsaEnumerateLogonSessions see http://msdn.microsoft.com/en-us/library/aa378275.aspx and LsaGetLogonSessionData see http://msdn.microsoft.com/en-us/library/aa378290.aspx) or ProcessIdToSessionId (see http://msdn.microsoft.com/en-us/library/aa382990.aspx).

    You can use GetTokenInformation function with the parameter TokenSessionId (see http://msdn.microsoft.com/en-us/library/aa446671.aspx) to receive the session id dwSessionId of the users session if you knows the users token hClient.

    BOOL bSuccess;
    HANDLE hProcessToken = NULL, hNewProcessToken = NULL;
    DWORD dwSessionId, cbReturnLength;
    
    bSuccess = GetTokenInformation (hClient, TokenSessionId, &dwSessionId,
                                    sizeof(DWORD), &cbReturnLength);
    bSuccess = OpenProcessToken (GetCurrentProcess(), MAXIMUM_ALLOWED, &hProcessToken);
    bSuccess = DuplicateTokenEx (hProcessToken, MAXIMUM_ALLOWED, NULL,
                                 SecurityImpersonation,
                                 TokenPrimary, &hNewProcessToken);
    EnablePrivilege (SE_TCB_NAME);
    bSuccess = SetTokenInformation (hNewProcessToken, TokenSessionId, &dwSessionId,
                                    sizeof(DWORD));
    bSuccess = CreateProcessAsUser (hNewProcessToken, NULL, szCommandToExecute, ...);
    

    This code only a schema. EnablePrivilege is a simple function used AdjustTokenPrivileges to enable SE_TCB_NAME privilege (see http://msdn.microsoft.com/en-us/library/aa446619.aspx as a template). It is important that the process from which you are start a process you have TCB privilege, but if your service run under the Local System you have enough permissions. By the way, following code fragment work with not only Local System account, but the account must have SE_TCB_NAME privilege to be able to switch current terminal server session.

    One more remark. In the code above we start new process with the same account as the current process have (for example Local System). You change change a code to use another account for example the users token hClient. It is only important to have a primary token. If you have an impersonation token you can convert it to the primary token exactly like in the code above.

    In the STARTUPINFO structure used in CreateProcessAsUser you should use lpDesktop = WinSta0\Default”.

    Depend on your requirements it could be also needed to use CreateEnvironmentBlock to create an new environment block that you will be passing to the new process.

    I recommend you also to read How to ensure process window launched by Process.Start(ProcessStartInfo) has focus of all Forms? where I describe how to force that the process will be started in foreground on the users desktop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know (Windows Activation Service) WAS is advertised as part of Windows 2008/Vista/7 but
What I have installed... Windows Vista Ultimate Service Pack 1 Visual Studio 2008 Service
I'm using Windows Vista Ultimate and today I've installed the Visual Studio 2008 SP1,
It seems that using Critical Sections quite a bit in Vista/Windows Server 2008 leads
Between Windows XP and Vista (and server 2003 and 2008) Microsoft have removed the
How do Windows NT (especially XP, Vista and Server 2008) ACLs (access control lists)
Windows provides only GetTickCount up to Windows Vista and starting from that OS also
I am using Windows Vista 32bit . I have installed Eclipse Helios Service Release
Let's create WinForms Application (I have Visual Studio 2008 running on Windows Vista, but
I am using Windows Vista x86 + VSTS 2008. When creating new Windows Media

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.