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