Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using an external exe in a form

Status
Not open for further replies.

paul1941

Programmer
May 25, 2006
32
0
0
BE
Hi all,

I hav a form with 2 command buttons
The first ( the second is not visible at this moment) allows me to start an external programm using following code:

DECLARE INTEGER ShellExecute IN shell32.dll INTEGER hndWin,STRING cAction,STRING cFileName,STRING cParams, ;
STRING cDir,INTEGER nShowWin
cFilename = ((rstam)+'bin\stam49.exe')
cAction = "open"
ShellExecute(0,cAction,cFileName,"","",1)
thisform.command3.visible = .T.

Before stam49 starts, the second command button (command3) is visible, and that is wrong, this button must be visible after stam49 is closed.

How to manage it?

regards, Paul
 
Code:
oShell = CREATEOBJECT([WSCRIPT.Shell])
cFilename = ((rstam)+'bin\stam49.exe')
oShell.Run(cFilename,1,.t.) && Runt the EXE and wait for it to finish
thisform.command3.visible = .T.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Hi wgcs


Thank yoy for the tip.
But, how can I know - from VFP - if Windows Script Host is installed on an users computer?

Regards, Paul
 
Hi Paul,

how can I know - from VFP - if Windows Script Host is installed on an users computer?

I don't know if this is the recommended method, but this is what I do:

Code:
llError = .F.
TRY
  oShell = CREATEOBJECT([WSCRIPT.Shell])
CATCH
  llError = .F.
ENDTRY

IF llError
  * Cannot instantiate WSH (probably because it's
  * not installed)
ELSE
  * Everything OK. Proceed with rest of processing
ENDIF

The above code requires VFP 8.0 or above. With earlier versions, you would have to redirect your error-handler, instead of using TRY/ENDTRY, but the principle is the same.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi all,

I'm using now following code

PUBLIC xhost,WHSaan
WHSaan = .F.
xhost = GETENV('windir')+"\system32\wscript.exe"
IF FILE(xhost) = .T.
WHSaan = .T.
ELSE
whsaan = .F.
endif

This code is working fine at the moment.

regards Paul
 
One caution is that if the System admin creates a policy prohibiting use of WSH, the WSCRIPT.EXE file will still be there, but the Createobject() calls will fail. Likely, my IsActiveXReg would also return .T., and wouldn't give a complete solution.

Same problem if the user executes:
wscript.exe -UNREG
or something like it, to unregister the ActiveX server... file still there, CREATEO() fails.

So, regardless of how much checking you have, I'd recommend still having TRY..CATCH error handling (or ON ERROR in VFP v6) on the actual CREATE call. (Like MikeLewis suggests) This is why I only called "IsActiveXReg" "more long winded" and not better.

Plus, what will your program do when it finds out that WSH doesn't exist or isn't available?

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top