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 1027017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:10:31+00:00 2026-05-16T12:10:31+00:00

Please let me know how do I run the app under current logged in

  • 0

Please let me know how do I run the app under current logged in user from the service.

To give you background, I have a VB.NET Windows service whose sole functionality is to run a Winform App at a specified time. Apart from that it also sets a system wakeup timer so that the system can be woken up at the specified time, if it goes into standby/sleep, to run the app. This service has to cater to XP/Vista/Win7 desktops on our network. This service won’t run on servers and laptops.

The Winform App shows a UI for the user to provide some inputs. If the user does not provide the input within 15 minutes, then it defaults the value and then goes into system tray icon. The user can click on the icon and change the values later (within in a specified time frame and that too only twice).

There is absolutely no interaction between the service and the winform app apart from the service starting the app. It also monitors if the app has been killed by the user/crashed. If it has been killed/crashed, then a new instance is run after 30 mins from previous run.

If there is no user logged on, then also I want the app to be run at the specified time. As I said before, the app has a default timer. So if some user has just logged off from the system, then defaults would be set by the winform app.

Now coming to why I am stuck with this design – I cannot use TaskScheduler because it has been disabled on all machines and security team is not willing to change it. TaskScheduler had the option to wakeup the machine from sleep and other things. So basically I ended up creating a service which is acting like task scheduler.

Currently when I run the app.exe via process.start() within the service, its running under SYSTEM account as the service is also running under LOCAL SYSTEM. So basically I am not getting any UI. Is there anyway to run it under the current logged in user? I am not worried about multiple user login as we wont be running it on servers and switch user is not enabled on our desktops. Even if somebody has done a remote login via mstsc, then also I need the run the app and show the UI to the user.

Please let me know how do I run the app under current logged in user from the service.

Thanks
askids

  • 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-16T12:10:32+00:00Added an answer on May 16, 2026 at 12:10 pm

    There were some additional comments that I posted. But I somehow cannot see it 🙁

    Coming back to the original question. I was able to figure it out after several trial and errors. I will put it in detail.

    With Vista and above, services run in isolation from other user sessions. They run in session 0. User sessions run in 1 and above. So basically you need to emulate the process as current logged in user.

    1. Use WTSEnumerateSessions and
      get of sessions. Check if the sesion
      state is active. This will be
      current logged on user session. If
      there are no active sessions, it
      means there is no logged on user. In
      my case, there will be only 1 logged
      on user. So I need not figure out
      the active session (like others may
      need to do).
    2. Use WTSQueryUserToken to get the user token in the active session.
      Create a primary user token using DuplicateTokenEx
    3. Create an environment using CreateEnvironmentBlock
    4. Use the information above in the CreateProcessAsUser

    The reason why it was working in XP and not in Vista was because it looks like the startup default information is different. After I set wShowWindow flag of the startupinfo structure, the GUI would start appearing.

    Dim StartupInfo As New STARTUPINFO()
    StartupInfo.cb = Marshal.SizeOf(StartupInfo)
    StartupInfo.dwFlags = STARTF_USESHOWWINDOW 
    StartupInfo.wShowWindow = WINDOW_STATUS.SW_SHOWNORMAL
    

    One more additional info. I was trying to set the default desktop using
    StartupInfo.lpDesktop = "WinSta0\\Default"
    because of which the application would crash upon launch. So I commented it out.

    I still have one final issue. The launched app is not in focus. The GUI appears, but in background. But I am thinking, it will once again have to do with some parameters like above. Once I figure it out, I will add in the details.

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

Sidebar

Related Questions

Please let me know under which subclass of the ASTNode (org.eclipse.jdt.core.dom.ASTNode) the statements with
Please let me know if you have any idea about it. Thanks EDIT What
Please let me know how to get the client IP address, I have tried
I am getting the run time error in following code. Please let me know
I have WCF service hosted on IIS7.5 running as anonymous - authentication, Please let
Please let me know what are default locations for Downloads folder on devices with
please let me know a java multithread application which i can refer ( source
Please let me know the difference between ~ and ! operator in java.
Please let me know what is the best way to determine composition of young
Please let me know how to delete n-rows in android sqlite database. I used

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.