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.InteropServ
ices
Imports System.Security.Permission
s
Structure SECURITY_ATTRIBUTES
Dim nLength As Int32
Dim lpSecurityDescriptor As Int32
Dim bInheritHandle As Int32
End Structure
Enum SECURITY_IMPERSONATION_LEV
EL
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_LEV
EL, _
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_LEV
EL.Securit
yImpersona
tion,
_
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.hStdOutp
ut.ToStrin
g)
Else
Response.Write(Err.LastDll
Error.ToSt
ring)
Response.Write(si.hStdOutp
ut.ToStrin
g)
Response.Write(si.cb.ToStr
ing)
End If
Else
Response.Write("DuplicateT
okenEx() Returned Error 0...")
Response.Write(Err.LastDll
Error.ToSt
ring)
End If
'CloseHandle(TokenDuplicat
e)
CloseHandle(pi.hThread)
CloseHandle(pi.hProcess)
End Sub
Start Free Trial