简体   繁体   English

我可以在Windows服务中运行另一个命令提示符/ GUI进程吗?

[英]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.

相关问题 无法在Windows服务中以编程方式运行命令提示符 - Unable to run command prompt programmatically in Windows service 如何在运行时的命令提示符下更改目录,然后运行另一个进程? - How do i change directories on command prompt in runtime and then run another process? 我可以将Windows服务执行委托给另一个进程吗? - Can I delegate windows service execution to another process? 如何在C#中创建可以与GUI *或*一起运行的Windows应用程序? - How can I create a Windows application that can run with a GUI *or* as a Windows service in C#? 运行提升的命令提示符过程 - Run an elevated command prompt process 如何创建也可以在命令提示符下运行的Windows窗体程序 - How to create a Windows Forms program that can also run at the command prompt 使用 Windows 命令提示符安装 Windows 服务? - Install a Windows service using a Windows command prompt? 如何运行需要从.NET Web服务进行AD身份验证的命令行进程? - How can I run a command line process that requires AD authentication from a .NET web service? 如何启动从Windows服务运行bat文件的过程 - How can I start a process to run a bat file from a windows service 使用命令提示符安装Windows服务 - Windows Service Installation using Command Prompt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM