Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. help with CreateProcessWithLogonW

help with CreateProcessWithLogonW

Scheduled Pinned Locked Moved C#
help
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    drey1
    wrote on last edited by
    #1

    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.

    J 1 Reply Last reply
    0
    • D drey1

      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.

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • J Judah Gabriel 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

        D Offline
        D Offline
        drey1
        wrote on last edited by
        #3

        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" }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups