各位大侠,我建了一个windows服务项目,想通过服务自动开启每次开机后自动启动exe的程序。我用web项目测试可以做到。但是用windows服务测试,老是有exe进程,而exe程序没有运行。比例abc.exe这个程序,我在进程里看到有这个程序的进程,但是程序却没有运行?请问到底该怎么做呢? public void StartSystem(string mySys)
{
int i = 1;
Process[] myProcesses = Process.GetProcesses();
foreach (Process myPrpcess in myProcesses)
{
if (myPrpcess.ProcessName.ToUpper() == mySys)//mySys EXE程序进程名
{
i = i + 1;
}
else
{
i = 1;
}
}
if (i == 1)
{
Process p = new Process();
p.StartInfo.FileName = myFile; //myFile EXE程序路径
p.Start();
}
else
{
StopSystem(mySys);
}
return;
}
{
int i = 1;
Process[] myProcesses = Process.GetProcesses();
foreach (Process myPrpcess in myProcesses)
{
if (myPrpcess.ProcessName.ToUpper() == mySys)//mySys EXE程序进程名
{
i = i + 1;
}
else
{
i = 1;
}
}
if (i == 1)
{
Process p = new Process();
p.StartInfo.FileName = myFile; //myFile EXE程序路径
p.Start();
}
else
{
StopSystem(mySys);
}
return;
}
http://hi.baidu.com/d369608w/blog/item/6358c752ed90600b0df3e303.html
今天问这个的怎么这么多
http://blog.csdn.net/zgke/archive/2009/01/11/3751917.aspx可能对你有帮助
string Apppath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"abc.exe")
RegistryKey MyReg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (MyReg.GetValue("abc.exe") != null)
{
string path = MyReg.GetValue("abc.exe").ToString();
if (path != Apppath)
{
MyReg.SetValue("abc.exe", Apppath);
}
}
else
{
MyReg.SetValue("abc.exe", Apppath);
}