3

So I'm attempting to programmatically add a logon/logoff/etc script to be ran with a GPO. I add the scripts in their respective /Sysvol/blah... directory. I update the scripts.ini file correctly to reflect the new script. I update the gpt.ini file to reflect the new version (using the correct decimal to represent the right hex byte). I update the LDAP value as well.

I go into the Group Policy Management and can see the GPO. I can see the version numbers match for AD and Sysvol, however when I go to the 'Settings' tab and can see that my script isn't listed.

I then edit the GPO via the UI (opening gpedit.msc). I can see my logon script in the UI just fine. I simply click 'OK' to confirm the gpedit UI, refresh that 'Settings' tab in the Group Policy Management UI and viola it shows my script.

So it's left me wondering what is that UI doing that I'm not? Oh, and I've tried 'gpupdate /force' and that was a no go as well :( Any ideas?

ymerej
  • 133
  • 3
  • What are you doing with scripts that can't be done with GP prefs? – Jim B Dec 14 '11 at 21:16
  • Nothing special. I'm just programmatically attempting to add scripts as it's part of my application ability to automate it. – ymerej Dec 14 '11 at 21:33
  • I have to ask why you wouldn't just use the GPMC to begin with? In addition, gpupdate doesn't update the GPMC, it refreshes Group Policy on the client computer for the computer/user (unless specified for just the computer or just the user). In addition addendum, startup and logon scripts are not processed when gpupdate is invoked unless gpupdate is invoked with the /logoff switch. – joeqwerty Dec 14 '11 at 21:37
  • I am using GPMC to create the GPO, however GPMC does not allow you to add scripts (for a reason I do not know). So I was left with trying to add the scripts manually. – ymerej Dec 14 '11 at 21:41
  • I suspect you can't add scripts because running scripts in a GPO usually causes performance issues and is almost always completely unnecessary. – Jim B Dec 16 '11 at 00:53
  • @JimB I'm not sure what having performance issues has to do with my question. I'm simply trying to add scripts to a GPO. Syneticon-dj was able to answer my question and I now have it running. – ymerej Dec 16 '11 at 20:45
  • I was simply commenting on your comment about why the gpmc doesn't allow adding scripts. – Jim B Dec 17 '11 at 01:20

1 Answers1

3

Using the documented scripting interfaces or their PowerShell counterparts for GP manipulation instead of poking around and failing should save you a lot of effort.

Specifically look at the scripting samples for exporting and importing a GPO - they work with an XML format for GPO definition which is easily generated programpatically.

the-wabbit
  • 40,319
  • 13
  • 105
  • 169
  • This seems to be the closest thing on what I'm looking for. I know those wsf scripts use the GPMC library just like I'm using in my C# app. I ran the backup and restore and it was able to properly bring back the scripts. I guess I just need to read up more on what it's doing internally so I can replicate what the scripts are doing. Thanks! – ymerej Dec 15 '11 at 18:49