Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _UNICODE 1
- #define UNICODE 1
- #include "crt\string.bi"
- #include "windows.bi"
- '' Author: Ascend4nt [Update 2012/01/03 -> fixed quotes position, example calls]
- Function RunWait(ByRef sFile As Const WString, _
- ByRef sParams As Const WString,_
- ByRef sDir As Const WString, _
- ByVal nShow As Integer) _
- As Integer
- Dim stStartup As STARTUPINFOW
- Dim stProcInfo As PROCESS_INFORMATION
- Dim bSuccess As BOOL
- memset(@stStartup, 0, sizeof(STARTUPINFOW))
- stStartup.cb = sizeof(STARTUPINFOW)
- stStartup.dwFlags = STARTF_USESHOWWINDOW
- stStartup.wShowWindow = nShow
- memset(@stProcInfo, 0, sizeof(PROCESS_INFORMATION))
- Dim pDir As LPCWSTR
- If (sDir <> "") Then
- pDir = @sDir
- Else
- pDir = 0
- End If
- bSuccess = CreateProcess(0, _
- """" + sFile + """ " + sParams, _
- NULL, NULL, FALSE, 0, NULL, pDir, @stStartup, @stProcInfo)
- '' Per MSDN, best practice - don't just return on a failed call -
- '' close any handles that may have been returned
- If (stProcInfo.hThread <> 0) Then
- CloseHandle(stProcInfo.hThread)
- End If
- Dim dwExitCode As DWORD
- dwExitCode = -1
- Dim hProcess As HANDLE
- hProcess = stProcInfo.hProcess
- If (bSuccess <> FALSE) Then
- '' Wait for process to end
- WaitForSingleObject(hProcess, INFINITE)
- '' and get Exit code
- GetExitCodeProcess(hProcess, @dwExitCode)
- End If
- If (hProcess <> 0) Then
- CloseHandle(hProcess)
- End If
- Return dwExitCode
- End Function
- '' Prevent critical errors pop-ups
- SetErrorMode(SEM_NOOPENFILEERRORBOX Or SEM_FAILCRITICALERRORS)
- Dim nExitCode As Integer
- ''nExitCode = RunWait(Environ("comspec"),"", "", SW_SHOW)
- ''nExitCode = RunWait(Environ("comspec")," /c test.bat", "", SW_SHOW)
- nExitCode = RunWait("test.bat", "", "", SW_SHOW)
- Print "ExitCode = ";nExitCode
- Sleep
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement