Solved

Set Group Policy Scripts (Shutdown) programatically

Posted on 2011-03-21
4
2,691 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

730 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