-2

The GPPermissionCollection Class has no Constructor and i don't know how to declare object of it or use it.

GPDomain domain = new GPDomain(sDCName + "." + sDCExtention);
Gpo gpo_background = domain.CreateGpo("August-HCalendarGPO");

GPPermission gp = new GPPermission("Everyone", GPPermissionType.GpoEditDeleteModifySecurity, false) ;
GPPermissionCollection gppc;
gppc.Add(gp);  //This Line Has Error
gpo_background.SetSecurityInfo(gppc);

the "gppc.Add(gp);" has error " Use of Unsigned Local Variable" . how to fix this error ? any help will appeciated

Khaled Rakhisi
  • 317
  • 1
  • 4
  • 18
  • 1
    The error is fairly self explanatory, have you tried anything to fix it? – DavidG Aug 10 '17 at 10:41
  • `GPPermissionCollection gppc;` you've just declared it not created a new instance or anything. missing the `= new GPPermissionCollection()` ? – Matt Aug 10 '17 at 10:44
  • 1
    @DavidG the GPPermissionCollection Has no constructor.i dont know how can i Initialize GPPermissionCollection object. – Khaled Rakhisi Aug 10 '17 at 10:44
  • @matt the class has no constructor – Khaled Rakhisi Aug 10 '17 at 10:45
  • So what do you expect the `SetSecurityInfo` when you pass it an uninitialised object? – DavidG Aug 10 '17 at 10:46
  • "has no constructor".... it surely has one, but you may not be allowed to access it. It's probably `internal`, MS often does this to special collections. If you read the [documentation](https://msdn.microsoft.com/en-us/library/microsoft.grouppolicy.gppermissioncollection(v=vs.85).aspx), you will see that even your `gppc.Add()` call won't do what you expect. – René Vogt Aug 10 '17 at 10:46
  • @DavidG then how can i initialize this guy? – Khaled Rakhisi Aug 10 '17 at 10:48
  • I have no idea, I know nothing about these classes. Perhaps try reading the docs or finding example code? – DavidG Aug 10 '17 at 10:49
  • I think somebody needs to open this question to get answer.. – Power Star Aug 10 '17 at 10:51
  • I don't post it as answer as I don't know the furhter implications: but you can get a working instance of `GPPermissionCollection` by calling `gppc = gpo_background.GetSecurityInfo();` – René Vogt Aug 10 '17 at 10:51
  • @RenéVogt the SetSecurityInfo Method Takes GPPermissionCollection object, and i cant declare GPPermissionCollection . what should i do know? – Khaled Rakhisi Aug 10 '17 at 10:51
  • @Matt the SetSecurityInfo Method Takes GPPermissionCollection object, and i cant declare GPPermissionCollection . what should i do know? – Khaled Rakhisi Aug 10 '17 at 10:52
  • @DavidG the SetSecurityInfo Method Takes GPPermissionCollection object, and i cant declare GPPermissionCollection . what should i do know? – Khaled Rakhisi Aug 10 '17 at 10:52
  • 1
    @HimBrombeere I disagree with that duplicate. The question is how to get this kind of collection to set new security policies, not about initializing local variables. – René Vogt Aug 10 '17 at 10:54
  • 1
    @KhaledRakhisi How about you **read the docs**? – DavidG Aug 10 '17 at 10:55

1 Answers1

3

You cannot create an instance of GPPermissionCollection, because its constructors are internal. You'll need to get that collection from your GPO via GetSecurityInfo():

GPDomain domain = new GPDomain(sDCName + "." + sDCExtention);
Gpo gpo_background = domain.CreateGpo("August-HCalendarGPO");

GPPermission gp = new GPPermission("Everyone", GPPermissionType.GpoEditDeleteModifySecurity, false) ;

// get permissions collection from gpo
GPPermissionCollection gppc = gpo_background.GetSecurityInfo();

gppc.Add(gp);
gpo_background.SetSecurityInfo(gppc);
René Vogt
  • 43,056
  • 14
  • 77
  • 99