有没有办法以编程方式将启动脚本添加到本地组策略? [英] Is there any way to programmatically add a startup script to the local group policy?

查看:46
本文介绍了有没有办法以编程方式将启动脚本添加到本地组策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个脚本,该脚本可以将自身添加到本地组策略中的启动脚本中,以便即使在没有用户登录的情况下也能运行.这可以使用 gpedit.msc 并进入计算机配置 > Windows 来完成设置 > 脚本 > 启动.但是,我还没有找到以编程方式执行此操作的方法.

I need to write a script that can add itself to the startup scripts in the local group policy so that it can run even when no users are logged in. This can be done using gpedit.msc and going into Computer Configuration > Windows Settings > Scripts > Startup. However, I haven't found a way to do this programmatically.

我已经研究过简单地编辑注册表.我发现相关位置是 HKLM\Software\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup,但是简单地添加我自己的条目没有任何效果.计算机不是域的一部分.

I've looked into simply editing the registry. I found the relevant location to be HKLM\Software\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Startup, but simply adding my own entry does not have any effect. The computer is not part of a domain.

有人知道怎么做吗?有 WMI 方法吗?

Does anyone know how to do this? Is there a WMI approach?

推荐答案

我正在为此编写一个脚本,我的测试表明您根本不必编辑注册表.按照以下步骤操作即可

I am working on a script for this and my testing shows you do not have to edit the registry at all. Follow these steps and it will work

  1. 在 scripts.ini 中查找最后一个脚本编号(每个脚本有两行0CmdLine="和0Parameters=".
  2. 为要添加的每个脚本添加两行(例如1CmdLine=myscript.vbs"和1Parameters="
  3. 增加 gpt.ini 中的version="编号
  4. 运行 Gpupdate 以应用它

脚本解决方案的重要说明:gpt.ini 使用 UTF-8 编码,scripts.ini 使用 Unicode.干杯 M$!

Important Note for scripting a solution: gpt.ini uses UTF-8 encoding, scripts.ini uses Unicode. Cheers M$!

希望这对人们有所帮助.

Hope this helps people.

肖恩

这篇关于有没有办法以编程方式将启动脚本添加到本地组策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆