一般来说要开启一个程序是用Process.Start(),但最近我在服务程序启动时调用Process.Start()开启了一个窗口程序,但那个窗口程序在使用时总有问题。假如那个窗口程序不在服务里启动,而是手工启动,就没问题。所以现在我有些糊涂了。
我想问一下,除了Process.Start(),还有没有其他可以启动程序的方法?
我想问一下,除了Process.Start(),还有没有其他可以启动程序的方法?
调试欢乐多
internal static extern uint WinExec(string lpCmdLine, uint uCmdShow);
private const uint SW_SHOW = 5;private void button1_Click(object sender, EventArgs e)
{
WinExec(@"c:\temp\temp.exe", SW_SHOW);
}
sc.ServiceName = "Alerter";
Console.WriteLine("The Alerter service status is currently set to {0}",
sc.Status.ToString());if (sc.Status == ServiceControllerStatus.Stopped)
{
// Start the service if the current status is stopped. Console.WriteLine("Starting the Alerter service...");
try
{
// Start the service, and wait until its status is "Running".
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running);
// Display the current service status.
Console.WriteLine("The Alerter service status is now set to {0}.",
sc.Status.ToString());
}
catch (InvalidOperationException)
{
Console.WriteLine("Could not start the Alerter service.");
}
}