I'm trying to run a DOS executable with CreateProcessWithLogon instead
of running it as a batch job.
It runs fine as a batch job but doesn't run when the workstation is
locked, that's why I wanna try the createprocess function
EXAMPLE Batch file
cd c:\WINEDISW
ALWAYSSW \CONCORDE\ 8711489112121 ALWAYS
EXAMPLE VB.NET CODE
Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
#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
Private Sub DoYourThing()
Dim szApp As String = "ALWAYSSW.exe"
Dim szCmdLine As String = "'\concorde\ 8711489112121
ALWAYSSW'"
Dim IpCurDir As String
Dim szUser As String = "JOHN"
Dim szPass As String = "DOE"
Dim szDomain As String = "ALWAYS"
Dim siStartup As STARTUPINFO
Dim piProcess As PROCESS_INFORMATION
siStartup.cb = Marshal.SizeOf(siStartup)
siStartup.dwFlags = 0
IpCurDir = "c:\winedisw"
Dim ret As Integer = CreateProcessWithLogon(szUser, szDomain,
szPass, LOGON_WITH_PROFILE, szApp, szCmdLine, _
NORMAL_PRIORITY_CLASS Or CREATE_DEFAULT_ERROR_MODE Or
CREATE_NEW_CONSOLE Or _
CREATE_NEW_PROCESS_GROUP, _
IntPtr.Zero, Marshal.StringToBSTR(IpCurDir), siStartup,
piProcess)
'IntPtr.Zero, IntPtr.Zero, siStartup, piProcess)
If ret = 0 Then
WriteToEventLog(New
System.ComponentModel.Win32Exception(Marshal.GetLa stWin32Error()).Message,
"DS Stealth Runner")
End If
WriteToEventLog("Proces naar behoren uitgevoerd!", "DS Stealth
Runner")
CloseHandle(piProcess.hProcess)
CloseHandle(piProcess.hThread)
Application.Exit()
End Sub
The problem is that the executable takes 3 parameters, I can get the
exe to run ,it notices that it's called with 3 parameters (because if
I don't send them the DOS program starts with a 'menu') but it doesn't
do a thing..
I could as wel use
Dim szCmdLine As String = "1 2 3" does pretty much the same thing
I've tried
Dim szCmdLine As String = "'\concorde\ 8711489112121 ALWAYSSW'"
Dim szCmdLine As String = "\concorde\ 8711489112121 ALWAYSSW"
Dim szCmdLine As String = "c:\concorde\ 8711489112121 ALWAYSSW'"
Dim szCmdLine As String = "c:\concorde 8711489112121 ALWAYSSW'"
I've searched for create process / lpCommandLine but I'm stuck for
now...
Do I have to do something with the spaces in between?
And uhh, the OS it has to run on is WIN2000
Please help me out here....
Thanks,
Michael