Solved

Set Group Policy Scripts (Shutdown) programatically

Posted on 2011-03-21
4
2,608 Views
Last Modified: 2012-05-11
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
Comment
Question by:Axter
  • 3
4 Comments
 
LVL 6

Expert Comment

by:WhitePhantom
ID: 35184525
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
 
LVL 30

Author Comment

by:Axter
ID: 35191439
>>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
 
LVL 30

Accepted Solution

by:
Axter earned 0 total points
ID: 35191489
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
 
LVL 30

Author Closing Comment

by:Axter
ID: 35275211
Found my own solution.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question