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: -
[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 1707 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 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 =...
|
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? Is there something else
that I need to do?
Here is my code:
System.Diagnostics.ProcessStartInfo info = new
System.Diagnostics.ProcessStartInfo();
|
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();
|
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....
| |
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...
|
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...
|
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
|
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");
}
|
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...
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |