C # determine whether an external executable program has been opened (open if not ),
# Region finds the relevant exe through the current Code Execution path and determines whether the startup is enabled Based on processes. Length
Private bool CheckAndOpenExe (string exeName)
{
Process [] processes = Process. GetProcessesByName (exeName );
If (processes. Length> 0)
{
Return true;
}
Else
{
Return OpenExe ();
}
}
Private bool OpenExe ()
{
Process pr = new Process ();
Try
{
Pr. StartInfo. FileName = string. Format (@ "{0} \ .. \ LotteryPro \ LotteryPro.exe", AssemblyDirectory );
Pr. Start ();
Return true;
}
Catch
{
Return true;
}
Finally
{
If (pr! = Null)
{
Pr. Close ();
}
}
}
Public static string AssemblyDirectory
{
Get
{
String codeBase = System. Reflection. Assembly. GetExecutingAssembly (). CodeBase;
UriBuilder uri = new UriBuilder (codeBase );
String path = Uri. UnescapeDataString (uri. Path );
Return Path. GetDirectoryName (path );
}
} // Obtain the directory for running the current Code
# Endregion