Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Halt app while external program runs
Message
From
12/05/2004 11:31:20
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00903008
Message ID:
00903199
Views:
35
This message has been marked as the solution to the initial question of the thread.
Here is how I do it (in most cases). It works without requiring WSH be installed. We cannot have it installed at some sites due to security considerations so I had to come up with another alternative and the fellow UTers helped me out.
m.lcApp = 'NotePad.Exe'  && notepade used for this example only
m.lcCmdLine = ''         && no command line required in this example
lcdir = 'c:\windows\'    && where notepad.exe resides

*PROCEDURE  RunAndWait (lcApp, lcCmdLine, lcdir)
DO DECL
#DEFINE INFINITE  0xFFFFFFFF
LOCAL lcStartupInfo, lcProcInfo, hProcess, ;
	lnPrio, lnIBelieve1
lnIBelieve1 = 1   && Don't remember what that was
lnPrio = 32 && Priority of Process=Normal
lcStartupInfo = CHR(68) + REPLI(CHR(0), 67)
lcProcInfo = REPLI(CHR(0), 16)
IF CreateProcess(0, m.lcApp+" "+m.lcCmdLine+CHR(0), 0,0,;
		m.lnIBelieve1, m.lnPrio,;
		0, 0, @lcStartupInfo, @lcProcInfo) <> 0
* process and thread handles returned in ProcInfo structure
	hProcess = buf2dword(SUBSTR(lcProcInfo, 1,4))
	hThread = buf2dword(SUBSTR(lcProcInfo, 5,4))
* waiting until the termination
	= WaitForSingleObject(hProcess, INFINITE)
	= CloseHandle(hThread)
	= CloseHandle(hProcess)
ELSE
	RETURN .F.
ENDIF
WAIT WINDOW "Returned to VFP program.  Press Anykey to exit."
RETURN

PROCEDURE DECL
DECLARE INTEGER CreateProcess IN kernel32;
	INTEGER lpAppName, STRING lpCmdLine, INTEGER lpProcAttr,;
	INTEGER lpThrAttr, INTEGER bInhHandles, INTEGER dwCrFlags,;
	INTEGER lpEnvir, INTEGER lpCurDir, ;
	STRING @lpStInfo, STRING @lpProcInfo
DECLARE INTEGER GetLastError IN kernel32
DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject
DECLARE INTEGER WaitForSingleObject IN kernel32;
	INTEGER hHandle, INTEGER dwMilliseconds
RETURN

FUNCTION buf2dword(lcBuffer)
RETURN ASC(SUBSTR(lcBuffer, 1,1)) + ;
	ASC(SUBSTR(lcBuffer, 2,1)) * 256 +;
	ASC(SUBSTR(lcBuffer, 3,1)) * 65536 +;
	ASC(SUBSTR(lcBuffer, 4,1)) * 16777216
RETURN
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform