help with CreateProcessWithLogonW
-
I am using "CreateProcessWithLogonW" in my code. it works fine it runs the application as intended, up to the point that returns a process in code. My problem is: Since I am impersonating another user, Access to the process is denied. I need to add the "Exited" event to this process, but I keep getting the "Access denied" message. Thank you for any help I can get.
-
I am using "CreateProcessWithLogonW" in my code. it works fine it runs the application as intended, up to the point that returns a process in code. My problem is: Since I am impersonating another user, Access to the process is denied. I need to add the "Exited" event to this process, but I keep getting the "Access denied" message. Thank you for any help I can get.
Keep in mind you have to turn on
Process.EnableRaisingEvents
before receiving any events. That said, I'm not sure if you'll actually receive an Exited event since the process never launched successfully. *edit* whoops, forgot you were using P/Invoke. Can you put a try/catch statement around your call to logon with credentials? That would tell you if it wasn't launched successfully AFAIK. You won't be able to hook into any events since this isn't a .NET Process object; you could however check for the existence of the process on some interval, then raise your own event when discovered the process is not running.Tech, life, family, faith: Give me a visit. Judah Himango
-
Keep in mind you have to turn on
Process.EnableRaisingEvents
before receiving any events. That said, I'm not sure if you'll actually receive an Exited event since the process never launched successfully. *edit* whoops, forgot you were using P/Invoke. Can you put a try/catch statement around your call to logon with credentials? That would tell you if it wasn't launched successfully AFAIK. You won't be able to hook into any events since this isn't a .NET Process object; you could however check for the existence of the process on some interval, then raise your own event when discovered the process is not running.Tech, life, family, faith: Give me a visit. Judah Himango
Thank you for your reply. My process runs fine. I get and id back and I use the getprocess method to get the process. but when it hit the code Process.EnableRaisingEvents or any Process.(something) it gives me an Access denied message. But if i impersonate myself, it works fine. this is the code: bool ret = true; ret = CreateProcessWithLogonW(m_username, m_domain, m_password, (int)LogonFlags.WithProfile,null,m_sb, (uint)PriorityFlags.NormalPriority | (uint)CreationFlags.UnicodeEnvironment, IntPtr.Zero,"c:\\", ref m_sui, out m_pi); if(ret) { System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(m_pi.dwProcessId); p.EnableRaisingEvents = true; "FAILS IN THIS LINE" }