Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _UNICODE 1
- #define UNICODE 1
- #include "windows.bi"
- #include "win\shellapi.bi"
- #include "win\objbase.bi"
- '' Author: Ascend4nt
- '' Alternative way (doesn't provide info on process started,
- '' nor does it wait for termination or provide exit code):
- ''ShellExecute(0,"","test.bat",0,0,SW_HIDE)
- '' Main function:
- Function ShellExWait(ByRef sFile As WString, _
- ByRef sParams As WString,_
- ByRef sDir As WString, _
- ByVal nShow As Integer) _
- As Integer
- Dim stShEx As SHELLEXECUTEINFOW
- With stShEx
- .cbSize = sizeof(SHELLEXECUTEINFOW)
- .fMask = SEE_MASK_NOCLOSEPROCESS
- .hwnd = 0
- .lpVerb = 0
- .lpFile = @sFile
- .lpParameters = @sParams
- .lpDirectory = @sDir
- .nShow = nShow
- .hInstApp = 0
- .lpIDList = 0
- .lpClass = 0
- .hkeyClass = 0
- .dwHotKey = 0
- .hIcon = 0
- .hProcess = 0
- End With
- If (ShellExecuteEx(@stShEx) = FALSE) Then
- Return -1
- End If
- Dim hProcess As HANDLE
- hProcess = stShEx.hProcess
- WaitForSingleObject(hProcess, INFINITE)
- Dim dwExitCode As DWORD
- dwExitCode = -1
- GetExitCodeProcess(hProcess, @dwExitCode)
- CloseHandle(hProcess)
- Return dwExitCode
- End Function
- '' == Program Start: ==
- '' Important for certain 'ShellExecute' commands (requires linking in libole32 [-l libole32]):
- CoInitializeEx(NULL, COINIT_APARTMENTTHREADED Or COINIT_DISABLE_OLE1DDE)
- '' Prevent critical errors pop-ups
- SetErrorMode(SEM_NOOPENFILEERRORBOX Or SEM_FAILCRITICALERRORS)
- Dim nExitCode As Integer
- '' Change to SW_HIDE to not show the command prompt:
- nExitCode = ShellExWait("test.bat", "", "", SW_SHOW)
- Print "ExitCode = ";nExitCode
- Sleep
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement