将条目添加到 GPO 启动脚本的安装程序

发布于 2024-11-05 04:04:17 字数 1116 浏览 4 评论 0 原文

我正在使用 NSIS 编写一个安装程序,它将向计算机的 GPO 添加一个条目,以便在系统启动时运行命令。

# From http://nsis.sourceforge.net/LGP_Startup/Shutdown_Script
!include LGPScript.nsh

Section
  SetOutPath -

  # Install all files from myprog directory into C:\Program Files\myprog
  File myprog\*

  # Copy mysystweak.bat to System32\GroupPolicy\Machine\Scripts\Startup
  SetOutPath $SYSDIR\GroupPolicy\Machine\Scripts\Startup
  File myprog\mysystweak.bat
  SetOutPath -

  # Add GPO entry to execute mysystweak.bat on startup
  ${LGPScript::Create} 'Startup' 'mysystweak.bat' '' $R1
  DetailPrint "Create startup LGP return code:$R1"

  # Write uninstaller
  Writeuninstaller "${uninstall_name}"
SectionEnd

一切都很顺利,除了…\Startup 中没有任何显示。安装程序认为一切正常:

Output folder: C:\WINDOWS\system32\GroupPolicy\Machine\Scripts\Startup
Extract: mysystweak.bat... 100%
Output folder: C:\Program Files (x86)\myprog

我最初尝试使用 CopyFiles 将批处理文件从 $INSTDIR 复制到 ...\Startup,但得到了相同的结果。

这里出了什么问题?

相关:https://serverfault.com/q/266338/2101

I'm in the process of writing an installer using NSIS that will add an entry to the computer's GPO to run a command on system boot.

# From http://nsis.sourceforge.net/LGP_Startup/Shutdown_Script
!include LGPScript.nsh

Section
  SetOutPath -

  # Install all files from myprog directory into C:\Program Files\myprog
  File myprog\*

  # Copy mysystweak.bat to System32\GroupPolicy\Machine\Scripts\Startup
  SetOutPath $SYSDIR\GroupPolicy\Machine\Scripts\Startup
  File myprog\mysystweak.bat
  SetOutPath -

  # Add GPO entry to execute mysystweak.bat on startup
  ${LGPScript::Create} 'Startup' 'mysystweak.bat' '' $R1
  DetailPrint "Create startup LGP return code:$R1"

  # Write uninstaller
  Writeuninstaller "${uninstall_name}"
SectionEnd

Everything goes well except nothing shows up in …\Startup. The installer thinks everything worked:

Output folder: C:\WINDOWS\system32\GroupPolicy\Machine\Scripts\Startup
Extract: mysystweak.bat... 100%
Output folder: C:\Program Files (x86)\myprog

I originally tried using CopyFiles to copy the batch file from $INSTDIR into …\Startup, but got the same result.

What's going wrong here?

related: https://serverfault.com/q/266338/2101

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

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

发布评论

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

评论(1

凯凯我们等你回来 2024-11-12 04:04:17

如果这是一个 x64 系统,您需要禁用 FS 重定向,否则 $SYSDIR 将不会指向真正的 system32 目录:

!include x64.nsh

Section
...
SetOutPath $SYSDIR\GroupPolicy\Machine\Scripts\Startup
${DisableX64FSRedirection}
File myprog\mysystweak.bat
${EnableX64FSRedirection}
...
SectionEnd

您可以通过使用 进程监视器

If this is a x64 system you need to disable FS redirection, without it $SYSDIR will not point to the true system32 directory:

!include x64.nsh

Section
...
SetOutPath $SYSDIR\GroupPolicy\Machine\Scripts\Startup
${DisableX64FSRedirection}
File myprog\mysystweak.bat
${EnableX64FSRedirection}
...
SectionEnd

You can verify that this is the problem by watching the installer with Process Monitor

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