2
我想创建一个Windows服务,将监视和更新应用程序(winform),如果它停止或它不运行应启动它。但它应该以当前控制台用户身份运行该应用程序。 我的问题是,它启动与网络服务凭据的形式,因此它不适用于当前用户。攻击这个是否有可能从当前控制台使用从Windows服务启动winform
protected override void OnStart(string[] args)
{
if (!GetProcessList())
{
Process p = new Process();
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(p_Exited);
StartProcces();
}
else
{
eventLog1.WriteEntry("Process is running");
}
}
void p_Exited(object sender, EventArgs e)
{
StartProcces();
}
static void StartProcces()
{
System.Diagnostics.ProcessStartInfo myProcess = new System.Diagnostics.ProcessStartInfo(@Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\WmiMonClient.exe");
myProcess.WorkingDirectory = System.Reflection.Assembly.GetEntryAssembly().Location;
//set environment path
try
{
System.Diagnostics.Process.Start(myProcess);
}
catch (Exception ex)
{
}
}
private static bool GetProcessList()
{
bool proccesIsRunning = false;
Process[] processlist = Process.GetProcesses();
foreach (Process theprocess in processlist)
{
if (theprocess.ProcessName == "WmiMonClient.exe")
{
proccesIsRunning = true;
}
}
return proccesIsRunning;
}
protected override void OnStop()
{
}
这可能是一个解决方案 – 2012-02-22 16:30:11