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. Visual Basic
  4. Starting the process as user will not work on Win2012

Starting the process as user will not work on Win2012

Scheduled Pinned Locked Moved Visual Basic
security
8 Posts 3 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.
  • B Offline
    B Offline
    byka
    wrote on last edited by
    #1

    Starting the process as user will not work on Win2012. Getting access Denied and user is an admin

    Dim psi As New System.Diagnostics.ProcessStartInfo
    psi.UseShellExecute = False
    psi.WindowStyle = ProcessWindowStyle.Hidden
    'Win2012 run as admin
    psi.Verb = "runas"

    'This will not for Win2012 need to pass User as argument
    'psi.Domain = Domain
    'psi.UserName = UserName
    'Dim pword As New System.Security.SecureString()
    'For Each c As Char In Password
    ' pword.AppendChar(c)
    'Next
    'psi.Password = pword

    D 1 Reply Last reply
    0
    • B byka

      Starting the process as user will not work on Win2012. Getting access Denied and user is an admin

      Dim psi As New System.Diagnostics.ProcessStartInfo
      psi.UseShellExecute = False
      psi.WindowStyle = ProcessWindowStyle.Hidden
      'Win2012 run as admin
      psi.Verb = "runas"

      'This will not for Win2012 need to pass User as argument
      'psi.Domain = Domain
      'psi.UserName = UserName
      'Dim pword As New System.Security.SecureString()
      'For Each c As Char In Password
      ' pword.AppendChar(c)
      'Next
      'psi.Password = pword

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      For the last time, you do NOT need the Verb = "runas" line at all. It does nothing in this context. In what context is this code running? Is it part of a Windows Service? A console app? A Windows Forms app? What? The code works fine as an admin user. It will NOT work if the user running this code is Local System.

      A guide to posting questions on CodeProject

      Click this: Asking questions is a skill. Seriously, do it.
      Dave Kreskowiak

      B 1 Reply Last reply
      0
      • D Dave Kreskowiak

        For the last time, you do NOT need the Verb = "runas" line at all. It does nothing in this context. In what context is this code running? Is it part of a Windows Service? A console app? A Windows Forms app? What? The code works fine as an admin user. It will NOT work if the user running this code is Local System.

        A guide to posting questions on CodeProject

        Click this: Asking questions is a skill. Seriously, do it.
        Dave Kreskowiak

        B Offline
        B Offline
        byka
        wrote on last edited by
        #3

        it's a console app and user is admin user and even if I remove Verb = "runas" still getting the same issue

        D 1 Reply Last reply
        0
        • B byka

          it's a console app and user is admin user and even if I remove Verb = "runas" still getting the same issue

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          OK, now, is the app that you're trying to launch on a network share? If so, Does the user that you're impersonating have access to that share? What happens if you change the WindowStyle to Normal?

          A guide to posting questions on CodeProject

          Click this: Asking questions is a skill. Seriously, do it.
          Dave Kreskowiak

          B 1 Reply Last reply
          0
          • D Dave Kreskowiak

            OK, now, is the app that you're trying to launch on a network share? If so, Does the user that you're impersonating have access to that share? What happens if you change the WindowStyle to Normal?

            A guide to posting questions on CodeProject

            Click this: Asking questions is a skill. Seriously, do it.
            Dave Kreskowiak

            B Offline
            B Offline
            byka
            wrote on last edited by
            #5

            Maybe this details will help. SID1 have access to cmd.exe and shares. SID2 have access to DB . When I run this I am passing SID2 while accessing cmd.exe under SID1 psi.Domain = Domain psi.UserName = UserName Dim pword As New System.Security.SecureString() For Each c As Char In Password pword.AppendChar(c) Next psi.Password = pword Settings windows to normal don't help

            D 1 Reply Last reply
            0
            • B byka

              Maybe this details will help. SID1 have access to cmd.exe and shares. SID2 have access to DB . When I run this I am passing SID2 while accessing cmd.exe under SID1 psi.Domain = Domain psi.UserName = UserName Dim pword As New System.Security.SecureString() For Each c As Char In Password pword.AppendChar(c) Next psi.Password = pword Settings windows to normal don't help

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              No, you're NOT accessing "CMD" as SID1 and as you've been told before, you don't need CMD.EXE. The process you are launching is done as the user you're impersonating. If that user doesn't have access to the shares you're going to get Access Denied. The process is not created as SID1. It's created as the user you're impersonating. A security context is first created for the user you're impersonating, then CreateProcessAsUser is called in that context to load the executable and setup the process. The problem is that the user you're impersonating cannot load the executable because it doesn't have access to the share where the executable is stored. Access Denied. You're going to have to grant access to the network location to the user you're impersonating for this to work.

              A guide to posting questions on CodeProject

              Click this: Asking questions is a skill. Seriously, do it.
              Dave Kreskowiak

              L 1 Reply Last reply
              0
              • D Dave Kreskowiak

                No, you're NOT accessing "CMD" as SID1 and as you've been told before, you don't need CMD.EXE. The process you are launching is done as the user you're impersonating. If that user doesn't have access to the shares you're going to get Access Denied. The process is not created as SID1. It's created as the user you're impersonating. A security context is first created for the user you're impersonating, then CreateProcessAsUser is called in that context to load the executable and setup the process. The problem is that the user you're impersonating cannot load the executable because it doesn't have access to the share where the executable is stored. Access Denied. You're going to have to grant access to the network location to the user you're impersonating for this to work.

                A guide to posting questions on CodeProject

                Click this: Asking questions is a skill. Seriously, do it.
                Dave Kreskowiak

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Upvoted for persistence.

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                D 1 Reply Last reply
                0
                • L Lost User

                  Upvoted for persistence.

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  It's not the most accurate description of what happens behind the scenes, but it should be sufficient to get the point across.

                  A guide to posting questions on CodeProject

                  Click this: Asking questions is a skill. Seriously, do it.
                  Dave Kreskowiak

                  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