[英]Can I run another Command Prompt/GUI process in a Windows Service?
I am writing a windows service that occasionaly has to renew IP address of the system and It would call ipconfig /renew to do it. 我正在编写Windows服务,偶尔需要更新系统的IP地址,并且它将调用ipconfig / renew来完成。 The code is going to look like this
代码看起来像这样
Process ipconfigProcess = new Process();
ipconfigProcess.StartInfo.FileName = "ipconfig";
ipconfigProcess.StartInfo.Arguments = " /renew";
ipconfigProcess.StartInfo.UseShellExecute = false;
ipconfigProcess.StartInfo.RedirectStandardOutput = true;
ipconfigProcess.Start();
strOutput = compiler.StandardOutput.ReadToEnd();
ipconfigProcess.WaitForExit();
I suppose a windows service is not allowed to show windows/dialogs. 我想Windows服务不允许显示Windows /对话框。 So my question is whether renewing ip as above would be a problem in windows service because it may or may not show a console to run ipconfig ?
所以我的问题是,如上所述,在Windows服务中更新ip是否会成为问题,因为它可能会或可能不会显示运行ipconfig的控制台?
我认为您要面对的唯一问题是权限问题-运行这样的过程应该没有问题(只要您不想与任何类型的UI交互),但是Windows服务需要以能够生成进程并执行ipconfig的帐户运行。
This does not require an instance of cmd.exe. 这不需要cmd.exe的实例。 Many command line applications are used in this manner.
以这种方式使用了许多命令行应用程序。
A service can use GUI functions and/or create a console. 服务可以使用GUI功能和/或创建控制台。 Windows creates a dummy display surface to draw on as necessary.
Windows将创建一个虚拟的显示表面以根据需要进行绘制。 (Obviously, this dummy surface can't interact with the user.)
(显然,该虚拟表面无法与用户交互。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.