Windows Server 启动时自动运行程序
我正在尝试在始终打开的 Windows 服务器上创建并安装 .NET 应用程序,但遇到了问题。我听说我不应该将其设为 Windows 服务(并且我个人更愿意有一个对话框应用程序,以便我可以看到进度等),因此我尝试使用任务计划程序。但是,任务计划程序一直试图过早关闭我的应用程序,而它应该只打开它并使其保持打开状态。
有什么想法可以让我的对话框应用程序在启动时在我的服务器上运行(并保持运行)吗?
I am trying to create and install a .NET app on a windows server that is always on, but I am running into problems. I have heard that I should not make it a Windows service (and would personally rather have a dialog app so I can see progress, etc) so I am trying to use the task scheduler. However, the task scheduler keeps trying to close my app prematurely, when it should only open it and leave it open.
Any ideas how I could have my dialog app run on startup (and stay running) on my server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用计划任务设置来在启动时间运行或按计划运行,这样用户登录/注销时就不会出现问题。
<一href="https://i.sstatic.net/i95Ve.png" rel="noreferrer">
4a。设置启动时 - 与用户登录或注销无关
4b.或设置登录时 - 取决于登录
4c.或者设置按计划工作,无论用户是否登录:
注意: 请使用服务帐户来执行此操作,如果您使用管理员帐户,则更改密码后它将失败,
注意:对于无人值守的应用程序,请选择控制台应用程序,因为一些应用程序可以具有用户界面除非用户登录,否则会出现问题,这取决于YMMV。一般来说,不要让窗口保持活动状态,即不要生成 MsgBox - 使用后杀死所有窗口,或者仅让一个控制台应用程序在后台无人值守地运行。您最不希望发生的事情就是因太多句柄和未处理的 GDI 对象而导致计算机崩溃。
/B
标志告诉 start 在后台运行应用程序而不创建新窗口。You can do it with a Scheduled Task setup to run at startup time or on a schedule so there wont be problems with users logging on/off.
4a. Set At startup - nothing to do with Users logging in or off
4b. Or set At Log On - depends on Users logging on
4c. Or set On a schedule to work regardless of users being logged in:
NOTE: Please use a Service Account to do this, if you use your Admin account then it will FAIL after changing password,
NOTE: For unattended applications choose a Console app as some user interfaces apps can have issues unless a user is logged on, it depends YMMV. In general don't keep windows alive, ie dont spawn MsgBox's - kill all windows after use or only have the one console app running in the background unattended. The last thing you want is to crash the computer with too many handles and GDI Objects left undisposed.
The
/B
flag tells start to run the application in the background without creating a new window.如果您正在寻找“登录后自动运行”,这里是答案:
在“运行”提示符中输入
shell:Startup
这将在其他位置打开一个窗口隐藏的AppData路径开始菜单/程序/启动 ->添加您要启动的程序的可执行文件的快捷方式。
当然,这仅适用于您当时使用的登录帐户。
对于所有用户,输入
shell:Common Startup
In case if you are looking for "automatically run after login" here is answer:
In the "Run" prompt type
shell:Startup
This will open a window in the otherwise hidden AppData path for the Startmenu/Programs/Startup -> Add a shortcut to the executable for the program you want to start.
This will of course only apply to the logon account that you're using at the time.
For all users type
shell:Common Startup
你应该创建一个Windows服务;这是唯一可靠的方法。
否则,您将遇到问题,例如用户注销。
如果你想要 UI,你可以制作一个单独的 GUI 来与服务通信(可能使用 WCF)。
You should make a Windows Service; it's the only reliable way to do this.
Otherwise, you will run into problems if, for example, the user logs off.
If you want UI, you can make a separate GUI that communicates with the service (probably using WCF).
我更喜欢在任务计划程序中创建任务并将触发器设置为“启动时”,但您也可以使用启动脚本。
您还可以使用本地组策略编辑器(执行 gpedit)并添加启动脚本。复制 http://technet.microsoft.com/en-us/library 中的步骤/cc770556.aspx 这样,如果他们将其删除,仍然可以在 SO 找到它。
分配计算机启动脚本
I prefer to create a task in the Task Scheduler and set the trigger as "On Startup", but you can also use Startup Scripts.
You can also use the Local Group Policy Editor (executing gpedit) and add a Startup script. Copying the steps from http://technet.microsoft.com/en-us/library/cc770556.aspx so that if they take it down, it still can be found at SO.
To assign computer startup scripts