|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Start and impersonate a console app from windows serviceI posted a question earlier asking about starting a process as a different user from windows service. I got some replies and read about this a bit more on the web but still couldn't get it working. The application I want to start is a console app and it also opens a win form which contains an axWebBrowser. There is no user interaction with the form. I've tried creating a Process and set the username, password and domain in the Process's StartInfo: Process p = new Process(); p.StartInfo.FileName = "somePathToThe.EXE"; p.StartInfo.Arguments = "some arguments"; p.StartInfo.UserName = "theUser@Domain"; p.StartInfo.Password = passwordInSecureString; p.StartInfo.UseShellExecute = false; p.Start(); I've also tried Pinvoke the CreateProcessWithLogonW Windows API call. I read about having to set the default desktop for console application so I did this: startupInfo.lpDesktop = @"winsta0\default"; These 2 methods both did not work. I got this message as soon as the process starts: The application failed to initialize properly (0xc0000142). Click on OK to terminate the application. If I start this application without the impersonate, it works perfectly. I won't see the console and win form showing up but I see the expected result when the app ends. Only when I add in the impersonate, I get the error message every time when the windows service tries to start my application. Also I have a console app which does the same thing as my win service. If I try the impersonation in the console mode, it works. Only when it runs from win services, it gives the error. Is there other way to do this? Or am I missing something in my code?? Thank you!! Agnes "Agnes" <agnesw@nospam.nospam> ha scritto nel messaggio What happens if you run the service using a System or Administrator account?news:uK0jDEv7GHA.2120@TK2MSFTNGP03.phx.gbl... > Also I have a console app which does the same thing as my win service. If > I try the impersonation in the console mode, it works. Only when it runs > from win services, it gives the error. Massimo When running service as Local System Account, I got "access is denied" error
or Win32 error code 5 which is the same error "Access is denied". When running as admin or normal user account, it shows the "application failed to initialize properly" error. :( Show quote "Massimo" <bar***@mclink.it> wrote in message news:uIAFCXv7GHA.4500@TK2MSFTNGP02.phx.gbl... > "Agnes" <agnesw@nospam.nospam> ha scritto nel messaggio > news:uK0jDEv7GHA.2120@TK2MSFTNGP03.phx.gbl... > >> Also I have a console app which does the same thing as my win service. >> If I try the impersonation in the console mode, it works. Only when it >> runs from win services, it gives the error. > > What happens if you run the service using a System or Administrator > account? > > > Massimo > "Agnes" <agnesw@nospam.nospam> ha scritto nel messaggio Have you tried running it as the same user with which you're logged on?news:unYa1Mw7GHA.2128@TK2MSFTNGP05.phx.gbl... > When running service as Local System Account, I got "access is denied" > error or Win32 error code 5 which is the same error "Access is denied". > > When running as admin or normal user account, it shows the "application > failed to initialize properly" error. :( Also, did you set the option to allow the service to interact with the desktop? Massimo > yup, I tried running as myself and I am also the admin on the machine but > Have you tried running it as the same user with which you're logged on? > Also, did you set the option to allow the service to interact with the > desktop? it's still not working. I see that I can only set that option if I use the Local System account to run the service. From the service property window, I don't seen an option to enter a user logon and select the allow service to interact with desktop. Is there other way to set this up?? Thank you very much for your help!!! I have just tried changing the LogonFlag of the CreateProcessWithLogonW
method from LOGON_WITH_PROFILE to LOGON_NETCREDENTIALS_ONLY. It started the new process properly but then I realised the process was not running as the new user, it's using the user credential for network only. So windows service has no problem starting a new process. But if the process has to be started as a different user, it gives that error. Is there some permission thing that I need to setup before creating the process?? Has anyone tried this before? Thanks in advance!!! Show quote "Agnes" <agnesw@nospam.nospam> wrote in message news:uK0jDEv7GHA.2120@TK2MSFTNGP03.phx.gbl... > Hi, > > I posted a question earlier asking about starting a process as a different > user from windows service. I got some replies and read about this a bit > more on the web but still couldn't get it working. > > The application I want to start is a console app and it also opens a win > form which contains an axWebBrowser. There is no user interaction with > the form. > > I've tried creating a Process and set the username, password and domain in > the Process's StartInfo: > > Process p = new Process(); > p.StartInfo.FileName = "somePathToThe.EXE"; > p.StartInfo.Arguments = "some arguments"; > p.StartInfo.UserName = "theUser@Domain"; > p.StartInfo.Password = passwordInSecureString; > p.StartInfo.UseShellExecute = false; > p.Start(); > > I've also tried Pinvoke the CreateProcessWithLogonW Windows API call. I > read about having to set the default desktop for console application so I > did this: startupInfo.lpDesktop = @"winsta0\default"; > > These 2 methods both did not work. I got this message as soon as the > process starts: The application failed to initialize properly > (0xc0000142). Click on OK to terminate the application. > > If I start this application without the impersonate, it works perfectly. > I won't see the console and win form showing up but I see the expected > result when the app ends. > Only when I add in the impersonate, I get the error message every time > when the windows service tries to start my application. > > Also I have a console app which does the same thing as my win service. If > I try the impersonation in the console mode, it works. Only when it runs > from win services, it gives the error. > > Is there other way to do this? Or am I missing something in my code?? > > Thank you!! > > Agnes > |
|||||||||||||||||||||||