static void Main(string[] args)
{
string name = "程序进程名称";//程序进程名称
int ProgressCount = 1;//判断进程是否运行的标识
Process[] prc = Process.GetProcesses();
foreach (Process pr in prc) //遍历整个进程
{
if (name == pr.ProcessName) //如果进程存在
{
ProgressCount = 0; //计数器清空
break;
}
}
if (ProgressCount != 0)//如果计数器不为0,说名所指定程序没有运行
{
bool install = false;
string installpath = "";
RegistryKey rkCurrentUser = Registry.LocalMachine;
// 获得测试键(只读)和显示它。
RegistryKey rkTest = rkCurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
foreach (string subKeyName in rkTest.GetSubKeyNames())
{
Microsoft.Win32.RegistryKey subKey = rkTest.OpenSubKey(subKeyName);
object displayName = subKey.GetValue("Inno Setup: App Path");
if (displayName != null)
{
//Console.WriteLine(displayName.ToString());
if (displayName.ToString().Contains("软件在注册表里的名字"))
{
installpath = displayName.ToString();
install = true;
break;
}
}
}
rkTest.Close();
rkCurrentUser.Close();
if (install)
{
System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
//设置外部程序名
Info.FileName = "SysFrame.exe";
//设置外部程序工作目录为 C:\
Info.WorkingDirectory = installpath;
//最小化方式启动
//Info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
//声明一个程序类
System.Diagnostics.Process Proc;
try
{
Proc = System.Diagnostics.Process.Start(Info);
}
catch (System.ComponentModel.Win32Exception)
{
return;
}
}
else {
Process.Start("http://blog.csdn.net/rrzhaobaojun");
Console.WriteLine("未安装!");
}
}
else
{
Console.WriteLine("对不起,本地已经有系统正在运行!");
}
Console.ReadKey();
}
判断程序是否安装
最新推荐文章于 2022-07-10 09:07:37 发布