[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2928
  • Last Modified:

Set Group Policy Scripts (Shutdown) programatically

I'm looking for a way to set the local machine group policy shutdown script programatically.

I've tried modifying all of the following registry keys, but they seem to take no effect on what's displayed via gpedit.msc.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\0
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0\0
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\0
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0\0

I do notice that if I change the script via gpedit.msc, the above registry keys get updated to the new value.

I've tried changing these registry keys, and than rebooting the computer, but after rebooting I still see the old value in gpedit.msc.

Moreover, when I shutdown the machine, it seems to be calling the old script instead of new script associated with the registry key changes.

Does anyone know how to change this policy through VB or C++?
gpedit.png
0
Axter
Asked:
Axter
  • 3
1 Solution
 
WhitePhantomCommented:
Are these computers a member of a domain?  It could be that the shutdown scripts configuration set by a domain group policy is trumping the local configuration.

WP
0
 
AxterAuthor Commented:
>>Are these computers a member of a domain?  It could be that the shutdown scripts configuration set by a domain group policy is trumping the local
>>configuration.


If that were the case, it would also happen when I made the changes through GPEdit.msc.
If GPEdit.msc can make the group policy changes on the local machine, than there should be a way to programatically make the change.s
0
 
AxterAuthor Commented:
I figured it out.
GPEdit.msc is getting the value from the following hidden file:
C:\Windows\System32\GroupPolicy\Machine\Scripts\scripts.ini

Example content:

[Shutdown]
0CmdLine=MyScript.vbs
0Parameters=

Unless I have problems finding VB code to update an INI file, I'll be requesting to have this question close.
0
 
AxterAuthor Commented:
Found my own solution.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now