如何打开后台处理程序服务宽度C# [英] How do I open Spooler service width C#
本文介绍了如何打开后台处理程序服务宽度C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在考虑一个WPF项目。
我在Windows操作系统中打开SPOOLER服务。
我用了两种方法。这就是代码:
首先:
ServiceController ser = new ServiceController();
ser.ServiceName = 后台处理程序;
if (ser.Status!= ServiceControllerStatus.Running)
{
ser.Start();
}
ser.Close();
第二名:
处理p = new 处理()
{
StartInfo = new ProcessStartInfo(){
FileName = cmd,exe,
UseShellExecute = false ,
RedirectStandardInput = true ,
RedirectStandardOutput = true ,
RedirectStandardError = true ,
CreateNoWindow = false
}
};
p.Start();
p.StandardInput.WriteLine( sc config Spooler start = auto> nul& net start Spooler< /跨度>);
p.StandardInput.WriteLine( exit);
p.Close();
但是它们会失败。
因为这两种方式需要管理员权限。
我不希望每次都需要开放软件宽度管理员权限
或手动打开后台处理程序服务。我不想使用app.manifest。
有什么方法吗?
解决方案
你应该使用 ServiceController [ ^ ]这个类...
这样的事情:
ServiceController oSpooler = new ServiceController( 后台处理程序); // 或者服务注册的名称
oSpooler.Start();
I am woring for a WPF project.
I shuold open the SPOOLER service in windows operation system.
I have used two ways.That is the code:
First:
ServiceController ser = new ServiceController();
ser.ServiceName = "Spooler";
if (ser.Status != ServiceControllerStatus.Running)
{
ser.Start();
}
ser.Close();
Second:
Process p = new Process()
{
StartInfo = new ProcessStartInfo() {
FileName="cmd,exe",
UseShellExecute=false,
RedirectStandardInput=true,
RedirectStandardOutput=true,
RedirectStandardError=true,
CreateNoWindow=false
}
};
p.Start();
p.StandardInput.WriteLine("sc config Spooler start = auto>nul & net start Spooler");
p.StandardInput.WriteLine("exit");
p.Close();
but they faild.
Because the two ways need administrator privileges.
I don't hope that i need open software width administrator privileges every time
OR open the Spooler service manually. And i don't want use app.manifest.
Is there any ways?
解决方案
You should use The ServiceController[^] class for that...
Something like this:
ServiceController oSpooler = new ServiceController("Spooler"); // or with whatever the name the service registered oSpooler.Start();
这篇关于如何打开后台处理程序服务宽度C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文