VB3 Using ExitWindowsExec() in VB to Run MS-DOS Batch FileLast reviewed: March 18, 1997Article ID: Q125426 |
2.00 3.00
WINDOWS
kbprg kbcode
The information in this article applies to: - Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0
SUMMARYThe ExitWindowsExec() function terminates Windows, runs a specified MS-DOS application, and then restarts Windows. The information in this article shows you how to call this function from Microsoft Visual Basic.
MORE INFORMATIONThe ExitWindowsExec() function is typically used by installation programs to replace components of Windows which are active when Windows is running. Normally, you'd want to run an MS-DOS batch file that performs the file copying while Windows is temporarily shut down. The declaration for ExitWindowsExec() is as follows:
' Place the following declaration on one, single line: Declare Function ExitWindowsExec Lib "User" (ByVal lpszExe As String, ByVal lpszParams As Any) As Integer First Parameter: lpszExe$The first parameter for ExitWindowsExec(), lpszExe$, should be a string containing the fully qualified path to the executable file you want to run. This string must contain no more than 127 characters. For batch files, you'll need to specify COMMAND.COM as the file -- C:\DOS\COMMAND.COM. To get the fully qualified path in Visual Basic to COMMAND.COM, you can use the Environ$ function:
lpszExe$ = Environ$("COMSPEC")For more information on the Environ$ function, please refer to the Microsoft Visual Basic Language Reference or the Help menu.
Second Parameter: lpszParams$The second parameter for ExitWindowsExec(), lpszParams$, should be a string containing any necessary parameters for the executable file. If no parameters are necessary, pass a long integer 0 such as 0&. To execute a batch file, however, this is where you specify the path to the batch file and any parameters it needs. Also, you need to preface the string with the /c switch which tells MS-DOS to invoke a copy of COMMAND.COM. Here is an example:
lpszParams$ = "/C C:\DIRNAME\GENERIC.BAT PARAMETER1 PARAMETER2"The return value of this function is False when the function fails.
Step-by-Step Example
|
KBCategory: kbprg kbcode
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |