Hi Jennifer,
To run an external exe program you use the System.Diagnostics.Process class and call the Start method. You can also use the StartInfo property to set settings. Here is a sample:
Process MyEXE = new Process();
try
{
MyEXE.StartInfo.FileName = "MYEXE.EXE";
MyEXE.StartInfo.Arguments = "myargument";
MyEXE.StartInfo.WorkingDirectory = "C:\\Program Files\\MyDirectory";
MyEXE.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
MyEXE.Start();
}
catch
{
}
finally
{
MyEXE.Close();
}
>I need to call a VFP6 .exe from C# (currently it's called from another VFP6 app).
>
>The code is below, and I welcome, and will so appreciate, any suggestions on how to do it.
>
>
>Current VFP 6.0 code that calls BookOut.exe:
>
>
>LOCAL vp_AccountID, lcCurrentPath, loBookOut, lcLib, lcBookOut
>
>vp_AccountID = THISFORM.AccountID
>
>
>lcCurrentPath = CURDIR()
>
>CHDIR r:
>
>CHDIR (THIS.cBookOutPath)
>
>lcLib = "aCustomBookOutdata"
>
>SET CLASSLIB TO &lcLib IN BookOut.EXE ADDITIVE
>
>loBookOut = CREATEOBJECT(lcLib)
>
>IF TYPE("loBookOut") = "O"
>
> WITH loBookOut
>
> .iAccountid = vp_AccountID
>
> .cRegion = "Texas"
>
> DO BookOut.exe WITH loBookOut
>
> IF .lSaveSelected = .T.
>
> SELECT rv_AutoM
>
> REPLACE rv_AutoM.cVIN WITH .cVIN,;
>
> rv_AutoM.nYear WITH .iYear,;
> rv_AutoM.cMake WITH .cMake,;
> rv_AutoM.cModel WITH .cSeries,;
> rv_AutoM.nMileage WITH .iMileage,;
> rv_AutoM.nBookOutValue WITH .iAdjustedTrade,;
> rv_AutoM.nInitialBookOutValue WITH .iAdjustedTrade
>
> TABLEUPDATE(.T.)
> SELECT rv_CustCall
> REPLACE rv_CustCall.nequipmentadjustment WITH 0
> TABLEUPDATE(.T.)
>
> ENDIF
> ENDWITHELSE
>
> MESSAGEBOX("Cannot instantiate BookOut Account. Please contact the I.S. department.", 16, APP_NAME)
>
>ENDIF
>
>CHDIR c:
>CHDIR (lcCurrentPath)
>THISFORM.frmRefresh()
>
>***************
>Thank you!!
-----------------------------------------
Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.comwww.prenia.comWeblog: blogs.prenia.com/cathi