473,487 Members | 2,461 Online
Bytes | Software Development & Data Engineering Community
Create 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 CreateProcessAsUser 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 1659

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

Similar topics

0
1324
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...
0
866
by: Pradeep | last post by:
HI Can we invoke a process in windows Servic Pradeep
0
3263
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? ...
4
25736
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? ...
1
3252
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...
7
13338
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...
2
3595
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...
2
4898
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...
2
1671
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) { ...
1
1282
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...
0
6967
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...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6847
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...
0
7352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4875
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...
0
4565
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...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
618
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.