在 Windows Server 2008 上启动时运行批处理文件
如果服务器打开,我想启动一个 powershell 脚本。不依赖于用户,如果某个用户注销,程序应该继续工作。 我尝试使用 HKey_localMachine 在注册表中输入一个条目,但如果用户注销,我的程序将无法继续工作。也许任务计划程序有解决方案?
I would like to start a powershell script if the Server turns on. No dependency on the user and if a certain user logs out the program should continue working.
I tried an entry in the registry with the HKey_localMachine but my program won't continue working if a user logs off. Maybe there is a solution with the Task Scheduler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
任务计划程序是一个选项。也许使用系统权限而不是管理员运行它
Task scheduler is an option. Maybe run it with system-rights instead of admin
一种猜测是让计划任务在启动或用户登录时作为系统运行program/cmd.exe/powershell 脚本。
启动时启动的命令应如下所示:
schtasks /Create /TN taskName /SC onstart /TR powerShellScript.ext /RU system
其中
powerShellScript.ext
替换为您的任何内容脚本或其他文件是。这应该运行任何替换
powerShellScript.ext
作为系统的内容,从而即使没有用户登录也保留该进程。另一种选择是在服务启动后立即使用该脚本来启动该脚本,但我没有这方面的经验。
这可能不起作用,具体取决于文件的启动方式。最可靠的方法是启动可执行文件并设置启动选项以加载您真正想要的任何内容。
One shot in the dark is to have a scheduled task run a program/cmd.exe/powershell script as system on startup or user logon.
The command for starting on startup should be this:
schtasks /Create /TN taskName /SC onstart /TR powerShellScript.ext /RU system
Where
powerShellScript.ext
is replaced by whatever your script or other file is.That should run whatever replaces
powerShellScript.ext
as system, thus preserving the process even if no users are logged on.Another option is to launch the script once using a service as soon as it's started, but I don't have experience with that.
This might not work depending on how the file is launched. the most reliable method is to launch an executable and set the launch options to load whatever it is that you actually want.