473,809 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Start Process in Session 1 from a Windows 7 Service

1 New Member
I have a service running in Windows 7. In Windows 7 all services run in Session 0. From that service I want to create an interactive user session (in a session other than Session 0) and start an application in that session. My problem is that when I call LogonUser to start an interactive user session and then use CreateProcessAs User to start the application the application ends up running in Session 0.

All of my code is C#.

Here is the relevant code:

Expand|Select|Wrap|Line Numbers
  1. [DllImport("advapi32.dll", SetLastError=true)]
  2. static extern bool LogonUser(
  3.     string principal,
  4.     string authority,
  5.     string password,
  6.     UInt32 logonType,
  7.     UInt32 logonProvider,
  8.     out    IntPtr token);
  9.  
  10. [DllImport("advapi32.dll", SetLastError=true)]
  11. static extern bool CreateProcessAsUser(
  12.     IntPtr hToken,
  13.     string lpApplicationName,
  14.     string lpCommandLine,
  15.     IntPtr lpProcessAttributes,
  16.     IntPtr lpThreadAttributes,
  17.     bool bInheritHandles,
  18.     int dwCreationFlags,
  19.     IntPtr lpEnvironment,
  20.     string lpCurrentDirectory,
  21.     ref STARTUPINFO lpStartupInfo,
  22.     ref PROCESS_INFORMATION lpProcessInformation);
  23.  
  24. IntPtr token;
  25. LogonUser("UserName", ".", "Password", LogonTypes.Interactive,LogonProviders.Default, out token)
  26.  
  27. <code to impersonate user>
  28. string hd = Environment.ExpandEnvironmentVariables("%USERPROFILE%");
  29.  
  30. IntPtr envBlock = IntPtr.Zero;
  31. CreateProcessAsUser(token, "PathToMenu.exe",
  32. NORMAL_PRIORITY_CLASS |CREATE_UNICODE_ENVIRONMENT,
  33. "WinSta0\\Default", hd, envBlock, "Menu");
  34.  
Can anyone tell me what I'm doing wrong?
Oct 19 '11 #1
0 1707

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1360
by: Trokey | last post by:
I am having a serious problem connecting to out-of-process COM objects in my windows service application. Whenever I try to create an instance of the COM object, a second instance of the COM server is started up instead of attaching to the already running one. I have tried the following fixes with no results: 1. added these lines to my service: System.Threading.Thread.CurrentThread.ApartmentState = ApartmentState.STA; int ret =...
0
892
by: Pradeep | last post by:
HI Can we invoke a process in windows Servic Pradeep
0
3301
by: Daniel Reber | last post by:
I am trying to start a process from a windows service but when the process starts the command window that the process runs in never shows. Is this because I am calling it from a windows service? Is there something else that I need to do? Here is my code: System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
4
25777
by: Daniel Reber | last post by:
I am trying to start a process from a windows service but when the process starts the command window that the process runs in never shows. Is this because I am calling it from a windows service? Is there something else that I need to do? Here is my code: System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
1
3293
by: Qais | last post by:
Hi there all, i am trying to work on this for past two weeks but nothing seem to work. I am trying to launch a process from windows service (i have to do this way, no other option). Windows service is running under system account with interaction with desktop enabled. The application i want launch is a vb.net gui application. I have tried using wmi, windows api, managed system.process.start method but all have one problem or the other....
7
13410
by: =?Utf-8?B?Sm9obi5ORVQ=?= | last post by:
Hi I have written a windows service in C# / .NET I have installed it and it's working fine on a couple boxes but on my XP box I get this error when I try to start it: Error 1053: The service did not respond to the start or control request in a timely fashion. I understand that the scm issue the start and is supposed to put up this error after some timeout period but it's coming up after only about half a second and it doesnt even...
2
3610
by: TampaWebDevelopment | last post by:
I have a Windows service that I have created. That service spins through the processes, looking to see if a certain application is running. If it is not, it starts it. The problem that I am having is that the application is not being started on the console, thus the user can not interact with it. So, can I tell the Process.Start method to start it on the console? Or, do I need to have my service running on the console/interact with the...
2
4930
by: TonyJ | last post by:
Hello!! Below I have written the main method, the C-tor and the OnStart. Who is calling OnStart? It must be the operating system that calls it after the C-tor has finished 1. Main is always started first 2. The C-tor is then called 3. The operating system is then calling OnStart
2
1689
by: deepadeshmukh | last post by:
How to call an external process from Windows service in C#2.0? This code doesnt works protected override void OnStart(string args) { Process.Start("C:\\Documents\\sessiondemo\\sessiondemo\\bin\\Debug\\Sessiondemo.exe"); }
1
1308
devonknows
by: devonknows | last post by:
Hi, what im aiming to do is to write a windows service which shuts down a process when a information in a .dat files changes, now the windows service installs, and runs, but.. its not doing the designated task i was hoping someone could offer some help. Language: .NET Version: Visual Studio 2005 Project: Windows Service As you open the new project () Ive added a timer (Timer1) to run the task at an interval of, 10,000. Below is the code...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7662
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.