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: -
[DllImport("advapi32.dll", SetLastError=true)]
-
static extern bool LogonUser(
-
string principal,
-
string authority,
-
string password,
-
UInt32 logonType,
-
UInt32 logonProvider,
-
out IntPtr token);
-
-
[DllImport("advapi32.dll", SetLastError=true)]
-
static extern bool CreateProcessAsUser(
-
IntPtr hToken,
-
string lpApplicationName,
-
string lpCommandLine,
-
IntPtr lpProcessAttributes,
-
IntPtr lpThreadAttributes,
-
bool bInheritHandles,
-
int dwCreationFlags,
-
IntPtr lpEnvironment,
-
string lpCurrentDirectory,
-
ref STARTUPINFO lpStartupInfo,
-
ref PROCESS_INFORMATION lpProcessInformation);
-
-
IntPtr token;
-
LogonUser("UserName", ".", "Password", LogonTypes.Interactive,LogonProviders.Default, out token)
-
-
<code to impersonate user>
-
string hd = Environment.ExpandEnvironmentVariables("%USERPROFILE%");
-
-
IntPtr envBlock = IntPtr.Zero;
-
CreateProcessAsUser(token, "PathToMenu.exe",
-
NORMAL_PRIORITY_CLASS |CREATE_UNICODE_ENVIRONMENT,
-
"WinSta0\\Default", hd, envBlock, "Menu");
-
Can anyone tell me what I'm doing wrong?
0 1659 Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
by: Pradeep |
last post by:
HI
Can we invoke a process in windows Servic
Pradeep
|
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? ...
|
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? ...
|
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...
| |
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...
|
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...
|
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...
|
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)
{
...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |