Advertisement

05.01.2003 at 12:44PM PDT, ID: 20602871
[x]
Attachment Details

Win32 CreateProcessAsUser Error 2 "The system cannot find the file specified"

Asked by ammo56 in .NET

Tags: cannot, find, file, system, specified

Please Help!!

I am trying to create a new process in an asp.net code behind (vb.net) page that will run under the authenticated user!

All is well until CreateProcessAsUser() where I get a return value of 0 and an Err.dllLastError value of 2.  When I type "net helpmsg 2" it's giving me "The system cannot find the file specified."

My code is as follows:

Note:
1)  Using Basic Windows Authentication for IIS w/ Impersonate = true and deny all anonymous
2)  Have Script and Executable access enabled at virtual dir.
3)  For debigging purposes (to rule out security) I have granted the Everyone group just about every Local Security Policy Right available!


=======================================================================
Imports System.Diagnostics
Imports Microsoft.Win32
Imports System.ComponentModel
Imports System.Security.Principal
Imports System.Runtime.InteropServices
Imports System.Security.Permissions



    Structure SECURITY_ATTRIBUTES
        Dim nLength As Int32
        Dim lpSecurityDescriptor As Int32
        Dim bInheritHandle As Int32
    End Structure

    Enum SECURITY_IMPERSONATION_LEVEL
        SecurityAnonymous
        SecurityIdentification
        SecurityImpersonation
        SecurityDelegation
    End Enum

    Enum TOKEN_TYPE
        TokenPrimary = 1
        TokenImpersonation
    End Enum

    Structure PROCESS_INFORMATION
        Dim hProcess As Int32
        Dim hThread As Int32
        Dim dwProcessId As Int32
        Dim dwThreadId As Int32
    End Structure

    Structure STARTUPINFO
        Dim cb As Int32
        Dim lpReserved As Long
        Dim lpDesktop As Long
        Dim lpTitle As Long
        Dim dwX As Int32
        Dim dwY As Int32
        Dim dwXSize As Int32
        Dim dwYSize As Int32
        Dim dwXCountChars As Int32
        Dim dwYCountChars As Int32
        Dim dwFillAttribute As Int32
        Dim dwFlags As Int32
        Dim wShowWindow As Int16
        Dim cbReserved2 As Int16
        Dim lpReserved2 As Byte
        Dim hStdInput As Int32
        Dim hStdOutput As Int32
        Dim hStdError As Int32
    End Structure

    Const CREATE_DEFAULT_ERROR_MODE = &H4000000
    Const CREATE_NEW_CONSOLE = &H10&
    Const CREATE_NEW_PROCESS_GROUP = &H200&

    Declare Auto Function DuplicateTokenEx Lib "advapi32.dll" ( _
            ByVal hExistingToken As IntPtr, _
            ByVal dwDesiredAccess As Int32, _
            ByRef lpTokenAttributes As SECURITY_ATTRIBUTES, _
            ByVal ImpersonationLevel As SECURITY_IMPERSONATION_LEVEL, _
            ByVal TokenType As TOKEN_TYPE, _
            ByRef phNewToken As IntPtr) _
    As Int32


    Declare Auto Function CreateProcessAsUser Lib "advapi32.dll" _
      Alias "CreateProcessAsUserA" ( _
            ByRef hToken As IntPtr, _
            ByVal lpApplicationName As String, _
            ByVal lpCommandLine As String, _
            ByVal lpProcessAttributes As Int32, _
            ByVal lpThreadAttributes As Int32, _
            ByVal bInheritHandles As Boolean, _
            ByVal dwCreationFlags As Int32, _
            ByVal lpEnvironment As String, _
            ByVal lpCurrentDirectory As String, _
            ByRef lpStartupInfo As STARTUPINFO, _
            ByRef lpProcessInformation As PROCESS_INFORMATION) _
    As Int32

    Declare Auto Function CloseHandle Lib "kernel32.dll" ( _
            ByVal hObject As Int32) _
    As Int32



Private Sub Page_Load(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles MyBase.Load

        Dim Token As IntPtr
        Dim TokenDuplicate As IntPtr
        Dim TokenAttributes As SECURITY_ATTRIBUTES
        Dim Result As Int32
        Dim si As New STARTUPINFO()
        Dim pi As New PROCESS_INFORMATION()
        Dim strCommandLine As String
        Dim strCurrentDirectory As String
        Dim strAppName As String
        'Dim PSA As SECURITY_ATTRIBUTES
        'Dim TSA As SECURITY_ATTRIBUTES

        Token = WindowsIdentity.GetCurrent.Token()
        Result = DuplicateTokenEx(Token, 0, TokenAttributes, _
                    SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation,
_
                    TOKEN_TYPE.TokenPrimary, TokenDuplicate)

        If Result <> 0 Then

            strAppName = "c:\inetpub\wwwroot\hfnet\utilities\auditpol"
            strCurrentDirectory = "C:\inetpub\wwwroot\hfnet\utilities"
            si.cb = Marshal.SizeOf(si)
            Result = CreateProcessAsUser( _
                            TokenDuplicate, _
                            strAppName, _
                            "", _
                            0&, _
                            0&, _
                            False, _
                            0&, _
                            0&, _
                            strCurrentDirectory, _
                            si, _
                            pi)

            If Result <> 0 Then
                Response.Write(si.hStdOutput.ToString)
            Else
                Response.Write(Err.LastDllError.ToString)
                Response.Write(si.hStdOutput.ToString)
                Response.Write(si.cb.ToString)
            End If
        Else
            Response.Write("DuplicateTokenEx() Returned Error 0...")
            Response.Write(Err.LastDllError.ToString)
        End If

        'CloseHandle(TokenDuplicate)
        CloseHandle(pi.hThread)
        CloseHandle(pi.hProcess)

End Sub
Start Free Trial
[+][-]05.01.2003 at 01:24PM PDT, ID: 8438407

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2003 at 01:25PM PDT, ID: 8438422

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2003 at 01:27PM PDT, ID: 8438435

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2003 at 01:28PM PDT, ID: 8438445

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.01.2003 at 01:32PM PDT, ID: 8438472

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.01.2003 at 06:02PM PDT, ID: 8439732

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.02.2003 at 05:12PM PDT, ID: 8448303

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.03.2003 at 05:06AM PDT, ID: 8449813

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.04.2003 at 11:43AM PDT, ID: 8456140

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.05.2003 at 09:53PM PDT, ID: 8467733

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.05.2003 at 10:02PM PDT, ID: 8467797

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.06.2003 at 06:18AM PDT, ID: 8470882

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.06.2003 at 09:36AM PDT, ID: 8472970

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.06.2003 at 09:59AM PDT, ID: 8473140

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.06.2003 at 10:17AM PDT, ID: 8473277

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.06.2003 at 10:31AM PDT, ID: 8473339

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.08.2003 at 05:44AM PDT, ID: 8488018

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2003 at 11:59AM PDT, ID: 8542626

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: .NET
Tags: cannot, find, file, system, specified
Sign Up Now!
Solution Provided By: ammo56
Participating Experts: 3
Solution Grade: A
 
 
[+][-]05.16.2003 at 12:05PM PDT, ID: 8542662

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2003 at 12:17PM PDT, ID: 8542762

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.16.2003 at 01:46PM PDT, ID: 8543281

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.23.2003 at 07:58PM PDT, ID: 8575892

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32