windows 在系统启动时启动应用程序而无需登录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31857849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Start an application at system start without login
提问by Daniel
We have a new server running and we got some new programs doing import routines. So far so good... But there is one program that is put into autostart folder. So it doesn't run until admin logs in and it stops if we logout.
我们有一个新服务器在运行,我们有一些新程序在执行导入例程。到目前为止一切顺利......但是有一个程序被放入自动启动文件夹。所以它在管理员登录之前不会运行,如果我们注销它就会停止。
I'd like to put this one into a seperate session so it may work without any interaction by simply starting it with the task scheduler at startup. Is this the right way to do this? Is it safe if I log in later and log out?
我想把这个放到一个单独的会话中,这样它就可以在没有任何交互的情况下工作,只需在启动时用任务调度程序启动它。这是正确的方法吗?如果我稍后登录然后退出是否安全?
Many thanks!
非常感谢!
Edit: The applications shows as a symbol in the task bar if running, it can be configured by this. Anything I must know about this if I change?
编辑:应用程序在运行时在任务栏中显示为符号,可以通过此配置。如果我改变,我必须知道什么?
Edit: It is not my application, I cannot rewrite it as a service.
编辑:这不是我的应用程序,我无法将其重写为服务。
回答by Daniel
I successfully added the application by using task schelduler on startup. Login and logout will not quit the application but no symbol is shown. Please add details to my side questions and I'll mark your answer as the accepted one.
我通过在启动时使用任务调度程序成功添加了应用程序。登录和注销不会退出应用程序,但不会显示任何符号。请在我的附带问题中添加详细信息,我会将您的答案标记为已接受的答案。
Edit: Ended up using this one. If I have to configure, I stop the application in task manager and start it again by link. After that I quit the application and restart it by task scheduler manual start.
编辑:最终使用了这个。如果我必须配置,我会在任务管理器中停止应用程序并通过链接重新启动它。之后我退出应用程序并通过任务计划程序手动启动重新启动它。
回答by Luaan
You need to separate your application in two.
您需要将您的应用程序一分为二。
To allow it to run without a user session, you need a windows service. That should handle all the background stuff. You can then register the service and set it to start when the system starts.
要允许它在没有用户会话的情况下运行,您需要一个 Windows 服务。那应该处理所有背景的东西。然后,您可以注册该服务并将其设置为在系统启动时启动。
To allow it to have a UI, and show up in the notification area, you need a windows application. This will be in autostart as usual, and will communicate with the service - for example, over named pipes.
为了让它有一个 UI,并显示在通知区域,你需要一个 Windows 应用程序。这将像往常一样处于自动启动状态,并将与服务通信 - 例如,通过命名管道。
While it is still (barely) possible to run an UI application without a user session, it's only maintained for backwards compatibility, and already shows a lot of problems. It will likely be removed altogether in the future, because it breaks quite a few contracts. Do not rely on hacks like this.
虽然仍然(几乎)可以在没有用户会话的情况下运行 UI 应用程序,但它只是为了向后兼容而维护的,并且已经显示出很多问题。将来它可能会被完全删除,因为它违反了很多合同。不要依赖这样的黑客。
回答by Pablo Santa Cruz
回答by raahlb
I could not get the "sc create" command to work. Instead I manually edited the registry using regedit. I added a new key in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services.
我无法使“sc create”命令起作用。相反,我使用 regedit 手动编辑了注册表。我在 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services 中添加了一个新键。
I used the following page to figure out required parameters and their values. Note that the names do not map.
我使用以下页面来找出所需的参数及其值。请注意,名称未映射。
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/inf-addservice-directive
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/inf-addservice-directive
回答by Ryan Douglass
Old question, but for anyone that stumbles here. Use srvany to set the program as a custom service.
老问题,但对于任何在这里绊倒的人。使用 srvany 将程序设置为自定义服务。
Note that when you do this with for example dropbox, googledrive, etc., you will need stop the service, then open the program normally to make changes like password, updates, etc.
请注意,当您使用 dropbox、googledrive 等执行此操作时,您需要停止该服务,然后正常打开程序以进行密码、更新等更改。
below is a well enough intro.
下面是一个足够好的介绍。
https://www.iceflatline.com/2015/12/run-a-windows-application-as-a-service-with-srvany/
https://www.iceflatline.com/2015/12/run-a-windows-application-as-a-service-with-srvany/
Download the tool kit here
在此处下载工具包
https://www.microsoft.com/en-us/download/details.aspx?id=17657
https://www.microsoft.com/en-us/download/details.aspx?id=17657
回答by amilamad
Convert user application to Service and Register it using Regsvr32or installutil.exe. It will start the service using SYSTEMuser account. Which is a high privilege account. Note : You can`t run any Window based application. Even a Message only window.
将用户应用程序转换为服务并使用Regsvr32或installutil.exe注册它。它将使用SYSTEM用户帐户启动服务 。这是一个高权限帐户。注意:您不能运行任何基于 Window 的应用程序。即使是仅消息窗口。
回答by ZEE
it is a old question but I recently solved in another way...
这是一个老问题,但我最近以另一种方式解决了......
(before I was using a scheduled-task for startup but this gave me diverse problems with lots software...)
(在我使用计划任务启动之前,这给我带来了很多软件的各种问题......)
Some programs also for diverse reasons must be run at a user level... or even inside a specific user session...
出于各种原因,某些程序也必须在用户级别运行……甚至在特定的用户会话中……
So the best way I found was to use a tool like Sysinternal/Autoruns to program the auto-logon to a specific user (it is a registry setting)... and in the startup-folder of that user (or any other "autorun/autolaunch" task)... run a script that first locks the screen... and next runs the other intended programs... that will run under that user profile...
所以我发现的最好方法是使用像 Sysinternal/Autoruns 这样的工具将自动登录编程到特定用户(它是一个注册表设置)......并在该用户的启动文件夹中(或任何其他“自动运行/autolaunch”任务)...运行一个脚本,首先锁定屏幕...然后运行其他预期的程序...将在该用户配置文件下运行...
so you can choose a standard user or a administrator... or even launch programs from a standard user in adminsitrator mode...
所以你可以选择标准用户或管理员......甚至在管理员模式下从标准用户启动程序......
I hope will help...
This "hack" solved me many problems with startup apps...
我希望会有所帮助......
这个“黑客”解决了我启动应用程序的许多问题......