在一天中的某个时间重新启动 Windows 机器并使用 Python 自动登录

发布于 2024-09-06 06:23:54 字数 266 浏览 1 评论 0原文

我知道如何远程重新启动机器,所以这是简单的部分。然而,问题的复杂性在于尝试设置以下内容。我想控制网络上的机器供下班后使用,这样当用户注销并回家,或者关闭他们的计算机时,无论如何,python或python + windows的某种组合可以重新启动他们的机器(为了清洁)并自动登录,运行一个进程过夜,然后在早上停止该进程并重新启动计算机,以便用户可以像平常一样轻松登录。

我环顾四周,并没有太幸运,尽管看起来可以通过更改注册表来做到这一点。但这听起来像是一个粗略的想法,每天修改注册表。有更简单的方法吗?

I know how to reboot machines remotely, so that's the easy part. However, the complexity of the issue is trying to setup the following. I'd like to control machines on a network for after-hours use such that when users logoff and go home, or shutdown their computers, whatever, python or some combination of python + windows could restart their machines (for cleanliness) and automatically login, running a process for the night, then in the morning, stop said process and restart the machine so the user could easily login like normal.

I've looked around, haven't had too terribly much luck, though it looks like one could do it with a changing of the registry. That sounds like a rough idea though, modifying the registry on a per-day basis. Is there an easier way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

山色无中 2024-09-13 06:23:54

您可能需要考虑运行您正在考虑的任何程序 Windows 服务,除非您绝对需要桌面。有几个与此相关的问题,例如 此处此处,以及上的食谱="http://code.activestate.com/recipes/576451-how-to-create-a-windows-service-in-python/" rel="nofollow noreferrer">活动状态。这不需要真正启动或登录计算机。

总有计划任务和不计划任务的选项。这实际上可以通过 Python 以编程方式完成,例如 此博文

至于打开已关闭电源的计算机,虽然我从未用过它,但我知道 Windows 支持 局域网唤醒功能,并且似乎有一些好的资源,再次包括食谱在 ActiveState 上。

如果您需要桌面来运行程序,我认为您别无选择,只能修改注册表以允许自动登录,因为我不相信 Window 的 GINA 可以以任何方式编写脚本。

You probably want to consider running whatever program you're considering as a Windows service, unless you absolute need a desktop. There are a couple of questions concerning that, e.g. here and here, as well as recipes on Active State. That involves no real need to start up or login to the computer.

There's also always the option of scheduled tasks and what not. That can actually be done programmatically through Python, e.g., as in this blog post.

As for powering on powered off computers, while I've never done anything with it, I know Windows supports Wake-on-LAN functionality, and there seem to be some good resources, including, again, a recipe on ActiveState.

If you need a desktop to run your program, I don't think you have any choice but to mess with the registry to permit autologins, as I don't believe the Window's GINA is scriptable in any way shape or form.

隱形的亼 2024-09-13 06:23:54

除了注册表之外,我想不出任何方法可以严格执行您想要的操作,至少在没有采取更严厉措施的情况下是这样。但进行此注册表修改并不是什么大问题;只需更改自动登录用户名/密码并重新启动计算机即可。要在用户注销时重新启动计算机,请为他们提供“注销”选项,该选项实际上会重新启动而不是注销;我见过其他地方这样做过。

(编辑)仅供参考:对于注册表编辑,Windows 有一个 REG 命令,如果您决定采用该路线,该命令将很有用。(/编辑)

另外,您要运行什么类型的进程?如果它不是一个需要您交互的 GUI 应用程序,您不必经历任何巨大的痛苦;只需远程运行该应用程序即可。在我的工作中,我们使用 psexec 来非常简单地完成此操作,并且我还创建了远程运行代码的 C++ 程序。这并不难,我这样做的方法是让 C++ 调用 WinAPI 函数在远程 PC 上远程注册一个服务并启动它,然后该服务做我想做的任何事情(本身,或者作为启动其他事情的临时点) ),然后注销自身。我只使用Python来处理简单的网页内容,所以我不确定它对访问所需的DLL有什么样的支持,但如果它可以做到这一点,你仍然可以在这里使用Python。

或者更好的是,如果您不需要远程执行此操作,而只是希望每天晚上执行此操作,则可以使用 Windows 调度程序来运行您想要在夜间运行的任何应用程序。您甚至可以通过编程方式执行此操作,因为有几个 Windows 命令可以实现此目的:一个是“at”命令,我现在不记得另一个是什么,但只需稍加谷歌搜索就可以找到它。

I can't think of any way to do strictly what you want off the top of my head other than the registry, at least not without even more drastic measures. But doing this registry modification isn't a big deal; just change the autologon username/password and reboot the computer. To have the computer reboot when the user logs off, give them a "logoff" option that actually reboots rather than logging off; I've seen other places do that.

(edit)FYI: for registry edits, Windows has a REG command that will be useful if you decide to go with that route.(/edit)

Also, what kind of process are you trying to run? If it's not a GUI app that needs your interaction, you don't have to go through any great pains; just run the app remotely. At my work, we use psexec to do it very simply, and I've also created C++ programs that run code remotely. It's not that difficult, the way I do it is to have C++ call the WinAPI function to remotely register a service on the remote PC and start it, the service then does whatever I want (itself, or as a staging point to launch other things), then unregisters itself. I have only used Python for simple webpage stuff, so I'm not sure what kind of support it has for accessing the DLLs required, but if it can do that, you can still use Python here.

Or even better yet, if you don't need to do this remotely but just want it done every night, you can just use the Windows scheduler to run whatever application you want run during the night. You can even do this programmatically as there are a couple Windows commands for that: one is the "at" command, and I don't recall right now what the other is but just a little Googling should find it for you.

请止步禁区 2024-09-13 06:23:54

感谢您的回复。为了更清楚地了解我在做什么,我有一个在启动时自动启动的程序,因此最好登录。我正在为渲染农场编写一个管理器,该管理器将占用我们的人员白天使用的所有机器,并在晚上(或者例如,每当他们注销一段时间时)将它们变成渲染服务器。

我不确定我是否一定需要 GUI 应用程序,但计算机需要启动并登录才能启动执行渲染的服务器应用程序,并且我不确定是否可以在不登录的情况下完成此操作。我是什么我需要运行的是 Autodesk 的 Backburner Server.exe,

也许不需要专门登录就可以运行,但我不熟悉做这种性质的事情。

Thanks for the responses. To be more clear on what I'm doing, I have a program that automatically starts on bootup, so getting logged in would be preferred. I'm coding a manager for a render-farm for work which will take all the machines that our guys use during the day and turn them into render servers at night (or whenever they log off for a period of time, for example).

I'm not sure if I necessarily require a GUI app, but the computer would need to boot and login to launch a server application that does the rendering, and I'm not certain if that can be done without logging in. What i'm needing to run is Autodesk's Backburner Server.exe

Maybe that can be run without needing to be logged in specifically, but I'm unfamiliar with doing things of that nature.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文