Attribute VB_Name = "modOpenAndClose" Option Explicit '============================================================================================================= ' ' modOpenAndClose Module ' ---------------------- ' ' Created By : Kevin Wilson ' http://www.TheVBZone.com ( The VB Zone ) ' http://www.TheVBZone.net ( The VB Zone .net ) ' ' Last Update : August 31, 2000 ' ' VB Versions : 5.0 / 6.0 ' ' Requires : NOTHING ' ' Description : This module is meant to make it easy to open and close programs... even MS-DOS based programs ' that run in a DOS window! To kill an MS-DOS application that is running in a window, use the ' CloseProgram() function using the Thread Handle. ' ' Exaple Use : ' ' ' Dim hThread As Long ' Dim hProcess As Long ' Dim Program As String ' Dim MyAnswer As VbMsgBoxResult ' Dim CloseByThread As Boolean ' ' ' Get the program to open ' Program = InputBox("Enter the full path of the program to start:" & Chr(13) & Chr(13) & "( i.e. - C:\Windows\NOTEPAD.EXE)", " Enter Program Path", "C:\Test.bat") ' If Program = "" Then ' Exit Sub ' ElseIf Dir(Program) = "" Then ' Exit Sub ' End If ' ' ' Close by process or thread? ' MyAnswer = MsgBox("Close by Thread?" & Chr(13) & Chr(13) & "YES = Close by Thread handle" & Chr(13) & "NO = Close by Process handle", vbYesNo + vbQuestion, " How do you want to close the program?") ' If MyAnswer = vbYes Then ' CloseByThread = True ' Else ' CloseByThread = False ' End If ' ' If OpenProgram(Program, , , False, hProcess, hThread) = False Then ' MsgBox "ERROR Starting Program" ' Else ' MsgBox "Program Started" ' End If ' ' If CloseProgram(hProcess, hThread, CloseByThread) = False Then ' MsgBox "ERROR Closing Program" ' Else ' MsgBox "Closed Program Successfully" ' End If ' '============================================================================================================= ' ' LEGAL: ' ' You are free to use this code as long as you keep the above heading information intact and unchanged. Credit ' given where credit is due. Also, it is not required, but it would be appreciated if you would mention ' somewhere in your compiled program that that your program makes use of code written and distributed by ' Kevin Wilson (www.TheVBZone.com). Feel free to link to this code via your web site or articles. ' ' You may NOT take this code and pass it off as your own. You may NOT distribute this code on your own server ' or web site. You may NOT take code created by Kevin Wilson (www.TheVBZone.com) and use it to create products, ' utilities, or applications that directly compete with products, utilities, and applications created by Kevin ' Wilson, TheVBZone.com, or Wilson Media. You may NOT take this code and sell it for profit without first ' obtaining the written consent of the author Kevin Wilson. ' ' These conditions are subject to change at the discretion of the owner Kevin Wilson at any time without ' warning or notice. Copyright© by Kevin Wilson. All rights reserved. ' '============================================================================================================= ' Type Declaration - CreateProcess Public Type SECURITY_ATTRIBUTES nLength As Long lpSecurityDescriptor As Long bInheritHandle As Long End Type ' Type Declaration - CreateProcess Public Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessId As Long dwThreadID As Long End Type ' Type Declaration - CreateProcess Public Type STARTUPINFO cb As Long ' Specifies the size, in bytes, of the structure. lpReserved As String ' Reserved. Set this member to NULL before passing the structure to CreateProcess. lpDesktop As String ' Windows NT/2000: Pointer to a null-terminated string that specifies either the name of the desktop only or the name of both the desktop and window station for this process. A backslash in the string pointed to by lpDesktop indicates that the string includes both desktop and window station names. If lpDesktop is NULL, the new process inherits the desktop and window station of its parent process. If lpDesktop is an empty string, the process does not inherit the desktop and window station of its parent process; instead, the system determines if a new desktop and window station need to be created. If the impersonated user already has a desktop, the system will use the existing desktop. lpTitle As String ' For console processes, this is the title displayed in the title bar if a new console window is created. If NULL, the name of the executable file is used as the window title instead. This parameter must be NULL for GUI or console processes that do not create a new console window. dwX As Long ' Ignored unless dwFlags specifies STARTF_USEPOSITION. Specifies the x offset, in pixels, of the upper left corner of a window if a new window is created. The offset is from the upper left corner of the screen. For GUI processes, the specified position is used the first time the new process calls CreateWindow to create an overlapped window if the x parameter of CreateWindow is CW_USEDEFAULT. dwY As Long ' Ignored unless dwFlags specifies STARTF_USEPOSITION. Specifies the y offset, in pixels, of the upper left corner of a window if a new window is created. The offset is from the upper left corner of the screen. For GUI processes, the specified position is used the first time the new process calls CreateWindow to create an overlapped window if the y parameter of CreateWindow is CW_USEDEFAULT. dwXSize As Long ' Ignored unless dwFlags specifies STARTF_USESIZE. Specifies the width, in pixels, of the window if a new window is created. For GUI processes, this is used only the first time the new process calls CreateWindow to create an overlapped window if the nWidth parameter of CreateWindow is CW_USEDEFAULT. dwYSize As Long ' Ignored unless dwFlags specifies STARTF_USESIZE. Specifies the height, in pixels, of the window if a new window is created. For GUI processes, this is used only the first time the new process calls CreateWindow to create an overlapped window if the nHeight parameter of CreateWindow is CW_USEDEFAULT. dwXCountChars As Long ' Ignored unless dwFlags specifies STARTF_USECOUNTCHARS. For console processes, if a new console window is created, dwXCountChars specifies the screen buffer width in character columns. This value is ignored in a GUI process. dwYCountChars As Long ' Ignored unless dwFlags specifies STARTF_USECOUNTCHARS. For console processes, if a new console window is created, dwYCountChars specifies the screen buffer height in character rows. This value is ignored in a GUI process. dwFillAttribute As Long ' Ignored unless dwFlags specifies STARTF_USEFILLATTRIBUTE. Specifies the initial text and background colors if a new console window is created in a console application. These values are ignored in GUI applications. This value can be any combination of the following values: FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY. ** For example, the following combination of values produces red text on a white background: FOREGROUND_RED or BACKGROUND_RED or BACKGROUND_GREEN or BACKGROUND_BLUE dwFlags As Long ' This is a bit field that determines whether certain STARTUPINFO members are used when the process creates a window. Any combination of the STARTF_* constant values can be specified. wShowWindow As Integer ' Ignored unless dwFlags specifies STARTF_USESHOWWINDOW. The wShowWindow member can be any of the SW_ constants defined in WINUSER.H. For GUI processes, wShowWindow specifies the default value the first time ShowWindow is called. The nCmdShow parameter of ShowWindow is ignored. In subsequent calls to ShowWindow, the wShowWindow member is used if the nCmdShow parameter of ShowWindow is set to SW_SHOWDEFAULT. cbReserved2 As Integer ' Reserved; must be zero. lpReserved2 As Long ' Reserved; must be NULL. hStdInput As Long ' Ignored unless dwFlags specifies STARTF_USESTDHANDLES. Specifies a handle that will be used as the standard input handle to the process if STARTF_USESTDHANDLES is specified. hStdOutput As Long ' Ignored unless dwFlags specifies STARTF_USESTDHANDLES. Specifies a handle that will be used as the standard output handle to the process if STARTF_USESTDHANDLES is specified. hStdError As Long ' Ignored unless dwFlags specifies STARTF_USESTDHANDLES. Specifies a handle that will be used as the standard error handle to the process if STARTF_USESTDHANDLES is specified. End Type ' Enumeration - OpenProgram Public Enum Priorities p_RealTime = &H100 p_Hight = &H80 p_Normal = &H20 p_Idle = &H40 End Enum ' Constants - STARTUPINFO.wShowWindow Public Enum WindowStates SW_HIDE = 0 SW_SHOWNORMAL = 1 SW_NORMAL = 1 SW_SHOWMINIMIZED = 2 SW_SHOWMAXIMIZED = 3 SW_MAXIMIZE = 3 SW_SHOWNOACTIVATE = 4 SW_SHOW = 5 SW_MINIMIZE = 6 SW_SHOWMINNOACTIVE = 7 SW_SHOWNA = 8 SW_RESTORE = 9 SW_SHOWDEFAULT = 10 SW_FORCEMINIMIZE = 11 SW_MAX = 11 End Enum ' Constants - STARTUPINFO.dwFlags Private Const STARTF_NULL = 0 ' If this value is not specified, the hStdInput, hStdOutput, and hStdError members of the STARTUPINFO structure are ignored. Private Const STARTF_FORCEONFEEDBACK = &H40 ' Indicates that the cursor is in feedback mode for two seconds after CreateProcess is called. If during those two seconds the process makes the first GUI call, the system gives five more seconds to the process. If during those five seconds the process shows a window, the system gives five more seconds to the process to finish drawing the window. The system turns the feedback cursor off after the first call to GetMessage, regardless of whether the process is drawing. Private Const STARTF_FORCEOFFFEEDBACK = &H80 ' Indicates that the feedback cursor is forced off while the process is starting. The normal cursor is displayed. Private Const STARTF_RUNFULLSCREEN = &H20 ' Indicates that the process should be run in full-screen mode, rather than in windowed mode. This flag is only valid for console applications running on an x86 computer. Private Const STARTF_USECOUNTCHARS = &H8 ' If this value is not specified, the dwXCountChars and dwYCountChars members are ignored. Private Const STARTF_USEFILLATTRIBUTE = &H10 ' If this value is not specified, the dwFillAttribute member is ignored. Private Const STARTF_USEPOSITION = &H4 ' If this value is not specified, the dwX and dwY members are ignored. Private Const STARTF_USESHOWWINDOW = &H1 ' If this value is not specified, the wShowWindow member is ignored. Private Const STARTF_USESIZE = &H2 ' If this value is not specified, the dwXSize and dwYSize members are ignored. Private Const STARTF_USESTDHANDLES = &H100 ' Sets the standard input, standard output, and standard error handles for the process to the handles specified in the hStdInput, hStdOutput, and hStdError members of the STARTUPINFO structure. The CreateProcess function's fInheritHandles parameter must be set to TRUE for this to work properly. ' Constants - dwCreateFlags (Create) Private Const CREATE_DEFAULT_ERROR_MODE = &H4000000 ' The new process does not inherit the error mode of the calling process. Instead, CreateProcess gives the new process the current default error mode. An application sets the current default error mode by calling SetErrorMode. This flag is particularly useful for multi-threaded shell applications that run with hard errors disabled. The default behavior for CreateProcess is for the new process to inherit the error mode of the caller. Setting this flag changes that default behavior. Private Const CREATE_NEW_CONSOLE = &H10 ' The new process has a new console, instead of inheriting the parent's console. This flag cannot be used with the DETACHED_PROCESS flag. Private Const CREATE_NEW_PROCESS_GROUP = &H200 ' The new process is the root process of a new process group. The process group includes all processes that are descendants of this root process. The process identifier of the new process group is the same as the process identifier, which is returned in the lpProcessInformation parameter. Process groups are used by the GenerateConsoleCtrlEvent function to enable sending a CTRL+C or CTRL+BREAK signal to a group of console processes. Private Const CREATE_SUSPENDED = &H4 ' The primary thread of the new process is created in a suspended state, and does not run until the ResumeThread function is called. Private Const CREATE_UNICODE_ENVIRONMENT = &H400 ' Indicates the format of the lpEnvironment parameter. If this flag is set, the environment block pointed to by lpEnvironment uses Unicode characters. Otherwise, the environment block uses ANSI characters. Private Const DETACHED_PROCESS = &H8 ' For console processes, the new process does not have access to the console of the parent process. The new process can call the AllocConsole function at a later time to create a new console. This flag cannot be used with the CREATE_NEW_CONSOLE flag. Private Const DEBUG_ONLY_THIS_PROCESS = &H2 ' If this flag is not set and the calling process is being debugged, the new process becomes another process being debugged by the calling process's debugger. If the calling process is not a process being debugged, no debugging-related actions occur. Private Const DEBUG_PROCESS = &H1 ' If this flag is set, the calling process is treated as a debugger, and the new process is debugged. The system notifies the debugger of all debug events that occur in the process being debugged. If you create a process with this flag set, only the calling thread (the thread that called CreateProcess) can call the WaitForDebugEvent function. ' Windows 95/98 : This flag is not valid if the new process is a 16-bit application. 'Private Const CREATE_FORCE_DOS = ? ' Windows NT/2000 : This flag is valid only when starting a 16-bit bound application. If set, the system will force the application to run as an MS-DOS-based application rather than as an OS/2-based application. 'Private Const CREATE_NO_WINDOW = ? ' Windows NT/2000 : This flag is valid only when starting a console application. If set, the console application is run without a console window. 'Private Const CREATE_SEPARATE_WOW_VDM = ? ' Windows NT/2000 : This flag is valid only when starting a 16-bit Windows-based application. If set, the new process runs in a private Virtual DOS Machine (VDM). By default, all 16-bit Windows-based applications run as threads in a single, shared VDM. The advantage of running separately is that a crash only terminates the single VDM; any other programs running in distinct VDMs continue to function normally. Also, 16-bit Windows-based applications that are run in separate VDMs have separate input queues. That means that if one application stops responding momentarily, applications in separate VDMs continue to receive input. The disadvantage of running separately is that it takes significantly more memory to do so. You should use this flag only if the user requests that 16-bit applications should run in them own VDM. 'Private Const CREATE_SHARED_WOW_VDM = ? ' Windows NT/2000 : The flag is valid only when starting a 16-bit Windows-based application. If the DefaultSeparateVDM switch in the Windows section of WIN.INI is TRUE, this flag causes the CreateProcess function to override the switch and run the new process in the shared Virtual DOS Machine. 'Private Const CREATE_BREAKAWAY_FROM_JOB = ? ' Windows 2000 : The child processes of a process associated with a job are not associated with the job. If the calling process is not associated with a job, this flag has no effect. If the calling process is associated with a job, the job must set the JOB_OBJECT_LIMIT_BREAKAWAY_OK limit or CreateProcess will fail. ' Constants - dwCreateFlags (Priority) Private Const REALTIME_PRIORITY_CLASS = &H100 ' Indicates a process that has the highest possible priority. The threads of a real-time priority class process preempt the threads of all other processes, including operating system processes performing important tasks. For example, a real-time process that executes for more than a very brief interval can cause disk caches not to flush or cause the mouse to be unresponsive. Private Const HIGH_PRIORITY_CLASS = &H80 ' Indicates a process that performs time-critical tasks. The threads of a high-priority class process preempt the threads of normal-priority or idle-priority class processes. An example is the Task List, which must respond quickly when called by the user, regardless of the load on the system. Use extreme care when using the high-priority class, because a CPU-bound application with a high-priority class can use nearly all available cycles. Private Const NORMAL_PRIORITY_CLASS = &H20 ' Indicates a normal process with no special scheduling needs. Private Const IDLE_PRIORITY_CLASS = &H40 ' Indicates a process whose threads run only when the system is idle and are preempted by the threads of any process running in a higher priority class. An example is a screen saver. The idle priority class is inherited by child processes. 'Private Const ABOVE_NORMAL_PRIORITY_CLASS = ? ' Windows 2000: Indicates a process that has priority higher than NORMAL_PRIORITY_CLASS but lower than HIGH_PRIORITY_CLASS. 'Private Const BELOW_NORMAL_PRIORITY_CLASS = ? ' Windows 2000: Indicates a process that has priority higher than IDLE_PRIORITY_CLASS but lower than NORMAL_PRIORITY_CLASS. Public Declare Sub ExitProcess Lib "kernel32.dll" (ByVal uExitCode As Long) Public Declare Sub ExitThread Lib "kernel32.dll" (ByVal dwExitCode As Long) 'Public Declare Function CreateProcess Lib "KERNEL32.DLL" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByRef lpProcessAttributes As SECURITY_ATTRIBUTES, ByRef lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByRef lpEnvironment As Any, ByVal lpCurrentDirectory As String, ByRef lpStartupInfo As STARTUPINFO, ByRef lpProcessInformation As PROCESS_INFORMATION) As Long Public Declare Function CreateProcess Lib "kernel32.dll" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByRef lpEnvironment As Any, ByVal lpCurrentDirectory As String, ByRef lpStartupInfo As STARTUPINFO, ByRef lpProcessInformation As PROCESS_INFORMATION) As Long Public Declare Function GetExitCodeProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByRef lpExitCode As Long) As Long Public Declare Function GetExitCodeThread Lib "kernel32.dll" (ByVal hThread As Long, ByRef lpExitCode As Long) As Long Public Declare Function TerminateProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Public Declare Function TerminateThread Lib "kernel32.dll" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long '============================================================================================================= ' OpenProgram ' ' Purpose: ' -------- ' Function that starts up the specified program and returns the Process Handle/ID, ' and Thread Handle/ID of the started program ' ' Param: Use: ' -------------------------------------------- ' FullProgramPath The full path to the program to start (.EXE, .COM, .BAT, etc.) ' ProgramPriority Optional. The priority to assign to the program once it's run ' WindowState Optional. How to display the program once it's run ' DOS_FullScreen Optional. If the program run is an MS-DOS based program ' or a console based program, you can specify TRUE via this ' parameter to start it in "Full-Screen" mode ' Return_ProcessHandle Optional. Variable that recieves the handle to the started ' process ' Return_ThreadHandle Optional. Variable that recieves the handle to the started ' thread. ' Return_ProcessID Optional. Variable that recieves the ID (a unique identifier ' number for the process) to the started process ' Return_ThreadID Optional. Variable that recieves the ID (a unique identifier ' number for th eprocess) to the started thread ' ' Return: ' ------- ' Returns TRUE if succeeds, FALSE if fails ' '============================================================================================================= Public Function OpenProgram(ByVal FullProgramPath As String, Optional ByVal ProgramPriority As Priorities = p_Normal, Optional ByVal WindowState As WindowStates = SW_NORMAL, Optional ByVal DOS_FullScreen As Boolean = True, Optional ByRef Return_ProcessHandle As Long, Optional ByRef Return_ThreadHandle As Long, Optional ByRef Return_ProcessID As Long, Optional ByVal Return_ThreadID As Long) As Boolean On Error GoTo ErrorTrap Dim ReturnValue As Long Dim Flags As Long Dim StartInfo As STARTUPINFO Dim ProcInfo As PROCESS_INFORMATION If DOS_FullScreen = True Then Flags = STARTF_RUNFULLSCREEN End If Flags = Flags Or STARTF_USESHOWWINDOW With StartInfo .cb = Len(StartInfo) .dwFlags = Flags .wShowWindow = WindowState End With ReturnValue = CreateProcess(vbNullString, FullProgramPath, 0, 0, 0, ProgramPriority, ByVal 0&, StripPath(FullProgramPath), StartInfo, ProcInfo) If ReturnValue = 0 Then OpenProgram = False Else OpenProgram = True With ProcInfo Return_ProcessHandle = .hProcess Return_ProcessID = .dwProcessId Return_ThreadHandle = .hThread Return_ThreadID = .dwThreadID End With End If Exit Function ErrorTrap: If Err.Number = 0 Then ' No Error Resume Next ElseIf Err.Number = 20 Then ' Resume Without Error Resume Next Else ' Unknown Error MsgBox Err.Source & " encountered the following error:" & Chr(13) & Chr(13) & "Error Number = " & CStr(Err.Number) & Chr(13) & "Error Description = " & Err.Description, vbOKOnly + vbExclamation, " Error - " & Err.Description Err.Clear Exit Function End If End Function '============================================================================================================= ' OpenProgram ' ' Purpose: ' -------- ' Function that closes the specified program given it's Process Handle or Thread ' Handle ' ' Param: Use: ' -------------------------------------------- ' ProcessHandle Optional. Handle of the process to terminate ' ThreadHandle Optional. Handle of the thread to terminate ' CloseThread Optional. If TRUE, the program will be closed by ' terminating the passed Thread handle. If FALSE, the ' program will be closed by terminating the passed Process ' handle. ' Return: ' ------- ' Returns TRUE if succeeds, FALSE if fails ' '============================================================================================================= Public Function CloseProgram(Optional ByVal ProcessHandle As Long, Optional ByVal ThreadHandle As Long, Optional CloseThread As Boolean = True) As Boolean On Error GoTo ErrorTrap Dim ReturnValue As Long Dim ExitCode As Long ' Close the specified Thread If CloseThread = True Then ReturnValue = GetExitCodeThread(ThreadHandle, ExitCode) If ReturnValue <> 0 Then 'ExitThread ExitCode TerminateProcess ProcessHandle, ExitCode CloseProgram = True Else CloseProgram = False End If ' Close the specified Process Else ReturnValue = GetExitCodeProcess(ProcessHandle, ExitCode) If ReturnValue <> 0 Then 'ExitProcess ExitCode TerminateThread ThreadHandle, ExitCode CloseProgram = True Else CloseProgram = False End If End If Exit Function ErrorTrap: If Err.Number = 0 Then ' No Error Resume Next ElseIf Err.Number = 20 Then ' Resume Without Error Resume Next Else ' Unknown Error MsgBox Err.Source & " encountered the following error:" & Chr(13) & Chr(13) & "Error Number = " & CStr(Err.Number) & Chr(13) & "Error Description = " & Err.Description, vbOKOnly + vbExclamation, " Error - " & Err.Description Err.Clear Exit Sub End If End Function ' Function used only in the OpenProgram() function to get just the directory from a full path Private Function StripPath(ByVal FullPath As String) As String If InStr(FullPath, "\") = 0 Then StripPath = FullPath Exit Function End If StripPath = Left(FullPath, InStrRev(FullPath, "\")) End Function 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX '------------------------------------------------------------------------------------------ ' C Documentation for Win32 API Functions '------------------------------------------------------------------------------------------ 'BOOL CreateProcess( ' LPCTSTR lpApplicationName, // [in] Pointer to a null-terminated string that specifies the module to execute. ' LPTSTR lpCommandLine, // [in] Pointer to a null-terminated string that specifies the command line to execute. The system adds a null character to the command line, trimming the string if necessary, to indicate which file was actually used. ' LPSECURITY_ATTRIBUTES lpProcessAttributes, // [in] Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpProcessAttributes is NULL, the handle cannot be inherited. ' // Windows NT/2000 : The lpSecurityDescriptor member of the structure specifies a security descriptor for the new process. If lpProcessAttributes is NULL, the process gets a default security descriptor. ' LPSECURITY_ATTRIBUTES lpThreadAttributes, // [in] Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpThreadAttributes is NULL, the handle cannot be inherited. ' // Windows NT/2000 : The lpSecurityDescriptor member of the structure specifies a security descriptor for the main thread. If lpThreadAttributes is NULL, the thread gets a default security descriptor. ' BOOL bInheritHandles, // [in] Indicates whether the new process inherits handles from the calling process. If TRUE, each inheritable open handle in the calling process is inherited by the new process. Inherited handles have the same value and access privileges as the original handles. ' DWORD dwCreationFlags, // [in] Specifies additional flags that control the priority class and the creation of the process. The following creation flags can be specified in any combination, except as noted. ' LPVOID lpEnvironment, // [in] Pointer to an environment block for the new process. If this parameter is NULL, the new process uses the environment of the calling process. ' LPCTSTR lpCurrentDirectory, // [in] Pointer to a null-terminated string that specifies the current drive and directory for the child process. The string must be a full path and file name that includes a drive letter. If this parameter is NULL, the new process will have the same current drive and directory as the calling process. This option is provided primarily for shells that need to start an application and specify its initial drive and working directory. ' LPSTARTUPINFO lpStartupInfo, // [in] Pointer to a STARTUPINFO structure that specifies how the main window for the new process should appear. ' LPPROCESS_INFORMATION lpProcessInformation // [out] Pointer to a PROCESS_INFORMATION structure that receives identification information about the new process. '); 'Public Declare Function CreateProcess Lib "KERNEL32.DLL" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByRef lpProcessAttributes As SECURITY_ATTRIBUTES, ByRef lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByRef lpEnvironment As Any, ByVal lpCurrentDirectory As String, ByRef lpStartupInfo As STARTUPINFO, ByRef lpProcessInformation As PROCESS_INFORMATION) As Long 'BOOL GetExitCodeProcess( ' HANDLE hProcess, // handle to the process ' LPDWORD lpExitCode // termination status '); 'VOID ExitProcess( ' UINT uExitCode // exit code for all threads '); 'BOOL GetExitCodeThread( ' HANDLE hThread, // handle to the thread ' LPDWORD lpExitCode // termination status '); 'VOID ExitThread( ' DWORD dwExitCode // exit code for this thread '); 'BOOL TerminateProcess( ' HANDLE hProcess, // handle to the process ' UINT uExitCode // exit code for the process '); 'BOOL TerminateThread( ' HANDLE hThread, // handle to thread ' DWORD dwExitCode // exit code ');