RunProgram Wait alternative << Back



Sture asked about how to execute and wait for a program with a long parameter list. Here is a quick snippet of code. Tested it on VDF 16.1. Adjust it accordingly to your version of VDF/DF. If you are wondering why I have to do line 32 to 34, please refer to this and this article.


Use Windows
External_Function CloseHandle "CloseHandle" KERNEL32.DLL Integer i1 Returns Integer
External_Function WaitForSingleObject "WaitForSingleObject" KERNEL32.DLL Integer i1 Integer i2 Returns Integer
External_Function ShellExecuteEx "ShellExecuteExA" SHELL32.DLL Pointer pExecInfo Returns Boolean

Struct SHELLEXECUTEINFO
	Integer cbSize
	Integer fMask
	Integer hwnd
	Integer lpVerb
	Integer lpFile
	Integer lpParameters
	Integer lpDirectory
	Integer nShow
	Integer hInstApp
	Integer lpIDList
	Integer lpClass
	Integer hkeyClass
	Integer dwHotKey
	Integer hIcon
	Integer hProcess
End_Struct // SHELLEXECUTEINFO

Define SEE_MASK_NOCLOSEPROCESS for |CI$40

Procedure RunProgramWait Global String sFile String sDirectory String sParameters
	SHELLEXECUTEINFO sInfo
	Boolean bSuccess
	String sAction
	Integer iVoid
	Move "open" to sAction
	Move sFile to sFile
	Move sParameters to sParameters
	Move sDirectory to sDirectory
	Move (SizeOfType(SHELLEXECUTEINFO)) To sInfo.cbSize
	Move SEE_MASK_NOCLOSEPROCESS To sInfo.fMask
	Move (AddressOf(sAction)) To sInfo.lpVerb
	Move (AddressOf(sFile)) To sInfo.lpFile
	Move (AddressOf(sParameters)) to sInfo.lpParameters
	Move (AddressOf(sDirectory)) to sInfo.lpDirectory
	Move SW_SHOW To sInfo.nShow
	Move (ShellExecuteEx(AddressOf(sInfo))) To bSuccess
	If (bSuccess) Begin
		Move (WaitForSingleObject(sInfo.hProcess,-1)) to iVoid
		Move (CloseHandle(sInfo.hProcess)) to iVoid
	End
End_Procedure

Send Info_Box "Before"
Send RunProgramWait "C:\Windows\Notepad.exe" "C:\Windows" "C:\Windows\System.ini"
Send Info_Box "After"
Free Web Hosting