Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices
Public Class WebForm2
Inherits System.Web.UI.Page
Protected WithEvents lblTest As System.Web.UI.WebControls.Label
#Region "Structs"
<StructLayout(LayoutKind.Sequential)> _
Public Structure PROCESS_INFORMATION
Dim hProcess As System.IntPtr
Dim hThread As System.IntPtr
Dim dwProcessId As Integer
Dim dwThreadId As Integer
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure STARTUPINFO
Dim cb As Integer
Dim lpReserved As System.IntPtr
Dim lpDesktop As System.IntPtr
Dim lpTitle As System.IntPtr
Dim dwX As Integer
Dim dwY As Integer
Dim dwXSize As Integer
Dim dwYSize As Integer
Dim dwXCountChars As Integer
Dim dwYCountChars As Integer
Dim dwFillAttribute As Integer
Dim dwFlags As Integer
Dim wShowWindow As Short
Dim cbReserved2 As Short
' you had this as a byte, but it is LPBYTE or byte*
' so should be an IntPtr
Dim lpReserved2 As System.IntPtr
Dim hStdInput As System.IntPtr
Dim hStdOutput As System.IntPtr
Dim hStdError As System.IntPtr
End Structure
#End Region
#Region "APIINFO"
Private Const LOGON_NETCREDENTIALS_ONLY As Integer = &H2
Private Const NORMAL_PRIORITY_CLASS As Integer = &H20
Private Const CREATE_DEFAULT_ERROR_MODE As Integer = &H4000000
Private Const CREATE_NEW_CONSOLE As Integer = &H10
Private Const CREATE_NEW_PROCESS_GROUP As Integer = &H200
Private Const LOGON_WITH_PROFILE As Integer = &H1
Private Declare Unicode Function CreateProcessWithLogon Lib "Advapi32" _
Alias "CreateProcessWithLogonW" _
(ByVal lpUsername As String, _
ByVal lpDomain As String, _
ByVal lpPassword As String, _
ByVal dwLogonFlags As Integer, _
ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByVal dwCreationFlags As Integer, _
ByVal lpEnvironment As System.IntPtr, _
ByVal lpCurrentDirectory As System.IntPtr, _
ByRef lpStartupInfo As STARTUPINFO, _
ByRef lpProcessInfo As PROCESS_INFORMATION) As Integer
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As _
System.IntPtr) As Integer
#End Region
#Region " Vom Web Form Designer generierter Code "
'Dieser Aufruf ist für den Web Form-Designer erforderlich.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Init
'CODEGEN: Diese Methode ist für den Web Form-Designer erforderlich
'Verwenden Sie nicht den Code-Editor zur Bearbeitung.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Dim szApp As String = ""
Dim szCmdLine As String = "cscript.exe mkw3site.vbs -r" & _
"C:\Inetpub\wwwroot -t client.loopline.de -o 8080"
Dim szUser As String = "Administrator"
Dim szPass As String = "huhukolo72#"
Dim szDomain As String = "TEST"
Dim siStartup As STARTUPINFO
Dim piProcess As PROCESS_INFORMATION
siStartup.cb = Marshal.SizeOf(siStartup)
siStartup.dwFlags = 0
Dim ret As Integer = CreateProcessWithLogon(szUser, szDomain, szPass, _
LOGON_WITH_PROFILE, 0&, szCmdLine, _
CREATE_DEFAULT_ERROR_MODE, _
IntPtr.Zero, IntPtr.Zero, siStartup, piProcess)
If ret = 0 Then
lblTest.Text = New System.ComponentModel.Win32Exception( _
Marshal.GetLastWin32Error()).Message
End If
CloseHandle(piProcess.hProcess)
CloseHandle(piProcess.hThread)
End Sub
End Class If it was hard to code, it should be hard to read too. |