添加注销脚本

发布于 2024-09-24 05:46:55 字数 1102 浏览 1 评论 0原文

我有一些脚本希望在每次用户注销时运行。我想创建一些以编程方式设置注销脚本的东西。例如,可以执行将注销脚本添加到 Windows 执行的注销脚本列表中的 exe 或 cmd 文件。因此,Windows API 函数或 Windows shell 命令会更好,但我找不到这样的函数或命令来帮助解决此问题。

当您使用本地组策略编辑器将注销脚本添加到组策略时,我检查了本地组策略编辑器所做的注册表编辑,但它做了很多我不确定我可以模仿的事情。例如,它进行了大量的注册表编辑,并在某些注册表项中使用数字代码,在某些值中使用二进制数据。我不知道这些值代表什么。

我尝试了 GPEdit 所做的部分更改,希望这样做仍然有效。例如,我将其所做的更改导出到 HKCU\Software\Policies\Microsoft\Windows\System\Scripts\Logoff 并将其导入到另一台 PC 上,但这不起作用,并且 GPEdit MMC 不知道我什至做了改变。

正如我所说,如果有人知道一些可以提供帮助的 Windows API 函数或 Windows shell 命令,那么最好使用一组 Windows API 函数或 Windows shell 命令,但如果有人知道一种方法来解码 GPEdit 以我可以模拟的方式生成的信息堆那么我并不反对进行注册表更改,只要它们稳定即可。

无论我找到和使用什么解决方案,它都必须能够自动且可靠,因为它将使用 psexec 对许多计算机远程执行,并且它还将包含在未来设置的 PC 的自动设置过程中。

不幸的是,这对谷歌来说似乎是一个困难的话题,因为人们试图做的许多其他事情都有许多与我查询相同的关键词,但实际上并不是同一主题。例如,用于运行应用程序的关闭/注销挂钩,或远程注销用户。

如果有人是 Windows 注册表或 MMC 向导,并且认为查看 GPEdit MMC 在执行相同操作时所做的注册表更改的转储会很有帮助,那么就这么说吧,我会提供它,因为我已经捕获了它。我怀疑这就是正确的方法,但是我已经开始研究如何创建 MMC 管理单元工具;我的想法是,也许 GPEdit 管理单元本身可以进行逆向工程,这样我就可以以简单的方式准确地看到它在做什么。但这不会很快发生,因为我看到的 .adm 文件似乎都没有这方面的设置,并且 gpedit.msc 文件似乎没有任何会在明文部分中泄露它的内容,尽管有其中有一个部分看起来像是乱码,所以也许里面发生了某种魔法。

I have some scripts that I would like to run every time a user logs off. I would like to create something that programatically sets up the logoff scripts. For example, an exe or a cmd file that can be executed to add the logoff script to the list of logoff scripts that Windows executes. Because of this, a Windows API function or a Windows shell command would be preferable, but I can find no such functions or commands to help with this.

I checked on the registry edits that the local group policy editor makes when you use it to add a logoff script to group policy, but it does a lot of things that I'm not sure I can mimic. For example, it makes a lot of registry edits, and it uses numeric codes in some of the registry keys and binary data in some of the values. I would not know what the values represent.

I have tried subsets of the changes that GPEdit does in the hopes that doing so would still work. For example, I exported the changes it made to HKCU\Software\Policies\Microsoft\Windows\System\Scripts\Logoff and imported them on another PC, but that did not work, and the GPEdit MMC was unaware that I had even made the change.

As I said, a set of Windows API functions or a Windows shell command would be preferable if anyone knows of some that could help, but if anyone knows of a way to decode the heap of information that GPEdit makes in a way that I could mock it then I'm not against making registry changes as long as they are stable.

Whatever the solution I find and use, it has to be able to be automatic and reliable, as it will be executed remotely against many computers with psexec, and it will also be included into automated setup processes for future PCs that are set up.

Unfortunately, this seems to be a difficult topic to Google for, as many other things people are trying to do have many of the same key words that I query for but are not actually the same topic. For example, shutdown/logoff hooks for running apps, or remotely logging off users.

If anyone is a Windows registry or MMC wizard and thinks that seeing a dump of the registry changes that the GPEdit MMC makes when doing the same thing would be helpful then just say so, and I'll make that available since I've already captured it. I doubt that's the way to go, however I have started looking into how to create MMC snap-in tools; my thought is that perhaps the GPEdit snap-in itself can be reverse engineered so that I can see exactly what it's doing in a simple way. This is not going anywhere fast though, as none of the .adm files I see appear to have the settings for this, and the gpedit.msc file doesn't appear to have anything that would give it away in the plaintext part, though there is a section in it that appears as gibberish, so maybe there's some sort of magic going on in there.

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

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

发布评论

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

评论(2

浮世清欢 2024-10-01 05:46:55

从 Windows Vista 开始,任务计划程序可以执行此操作。对于Windows XP及以前的版本,似乎没有一个好的答案。 XP 没有下面列出的“与用户会话断开连接时”触发器。

Windows 中有两个用于计划任务的主要命令行实用程序:at.exe 和 schtasks.exe。就其本身而言,两者似乎都没有提供可以从 GUI 界面获得的所有选项(尽管 schtasks 非常接近)。但是,任务计划程序具有描述计划任务的 XML 格式,并且 schtasks.exe 具有从 XML 文件导入任务的选项。

要创建注销脚本,请创建一个描述您要创建的任务的 XML 文件。确保使用“与用户会话断开连接时”触发器,并选择从“任何用户”(需要提升权限)和“从本地计算机连接”注销。将所有所需的注销操作(例如注销脚本)设置为任务操作。

Microsoft 有一个用于为任务计划程序开发任务的示例列表,其中包括 XML 示例。您可以在此处找到此列表。

或者,您可以使用 GUI 工具设置一次任务,然后右键单击任务列表中显示的任务并选择“导出”。您将看到一个保存对话框,允许您以 XML 格式保存任务。

然后,我使用以下命令编写任务设置脚本:

schtasks /create /tn "Task Name Here" /XML "path to xml file here" /ru domain\username /rp "password"

注意:部分功劳应归于 user606602,以获取使用任务计划程序的建议,尽管他建议使用 GUI 应用程序,但根据我的问题,该应用程序不起作用为了这。我尝试用他建议的脚本版本编辑他的答案,然后接受,但同行评审拒绝了编辑。

The task scheduler can do this as of Windows Vista. For Windows XP and previous, there does not seem to be a good answer. XP does not have the "On disconnect from a user session" trigger listed below.

There are two main command line utilities for scheduling tasks in Windows: at.exe and schtasks.exe. By themselves, neither seem to provide all of the options that you can get from the GUI interface (though schtasks comes very close). However, the Task Scheduler has an XML format that describes scheduled tasks, and schtasks.exe has an option to import tasks from an XML file.

To create a logoff script, create an XML file that describes the task you want to create. Make sure to use a trigger of "On disconnect from a user session" and select the log off from "any user" (which requires elevated privileges) and "connection from local computer." Set up all desired logoff actions (such as your logoff scripts) as task actions.

Microsoft has a list of examples for developing tasks for the Task Scheduler, including XML examples. You can find this list here.

Alternatively, you can set up your task once using the GUI tool, then you can right-click the task where it appears in the task list and select "Export." You will get a save dialog that will allow you to save the task in XML format.

I then script the setup of the task with the following command:

schtasks /create /tn "Task Name Here" /XML "path to xml file here" /ru domain\username /rp "password"

Note: partial credit should go to user606602 for the suggestion to use the task scheduler, though he was suggesting the use of the GUI application which, as per my question, would not work for this. I tried to edit his answer with the scripted version of his suggestion then accept, but a peer review declined the edit.

囍笑 2024-10-01 05:46:55

不能只使用 Windows 任务计划程序来启动脚本吗?

较新版本的任务计划程序(例如Windows Server 2008、Windows Vista/7)应该允许您选择运行用户注销时触发的脚本。

请参阅 这里

您需要做的就是创建一个新任务,然后创建一个新触发器。在此窗口中,从下拉菜单中选择“与用户会话断开连接时”,然后从任务配置窗口的“操作”选项卡中选择要运行的脚本。

Couldn't you just use the windows task scheduler to launch the scripts?

Newer versions of the task scheduler (e.g. Windows Server 2008, Windows Vista/7) should allow you the option to run scripts that are triggered when the user logs off.

See here

All you need to do is create a new task, then create a new trigger. From this window, select 'On disconnect from a user session' from the drop-down menu, then select the scripts you want to run from the 'Actions' tab on the task configuration window.

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