folder security description

Help
Anonymous
2011-01-24
2013-11-07

  • Anonymous
    2011-01-24

    Hi all, i try make this code using java jacob.

    Dim strPath
        strPath = Replace(strFolder, ":\", ":\\")
        Set ObjSecurity = GetObject("winmgmts:Win32_LogicalFileSecuritySetting." & "path='" & strPath & "'")
        RetVal = objSecurity.GetSecurityDescriptor(objSD)
        DACL = objSD.DACL
        For Each objACE in DACL
            Set Trustee = objACE.Trustee
            If Trustee.Name = "SESAPFTP" Then
                objACE.AccessMask = intRights 'Read Access
                objACE.AceType = intAceType 'Allow or Deny
                objACE.AceFlags = 3 'Inheritance to sub-folders and files
                If objSecurity.SetSecurityDescriptor(objSD) = 0 Then
                    SetUserRights = True
                Else
                    SetUserRights = False
                End If
                Exit Function
            End If
        Next
    

    this my code, someone can help me ?

    ActiveXComponent component = new ActiveXComponent("winmgmts:Win32_LogicalFileSecuritySetting.path='C:\\\\'");
                ActiveXComponent sd = new ActiveXComponent("winmgmts:Win32_SecurityDescriptor");
                System.out.println(Dispatch.get(component.getObject(), "Caption").getString());
                Variant v = new Variant();
                v.putDispatchRef(sd.getObject());
                Dispatch.call(component.getObject(), "GetSecurityDescriptor", v);
                Variant owner = Dispatch.get(sd, "Owner");
                System.out.println(Dispatch.get(owner.toDispatch(), "Name").getString());
    
     
  • Christian
    Christian
    2012-10-03

    If you are looking to access the Win32_ class called Win32_SecurityDescriptor you have to connect to WMI first. I tend to do something like this (don't have to use a dispatch can use an ActiveXComponent but I prefer the lower level)

        
    ActiveXComponent wbemLocator = new ActiveXComponent("WbemScripting.SWbemLocator");
    Dispatch wbemServices = wbemLocator.invoke("ConnectServer", new Variant(host), new Variant("root\\cimv2"), new Variant(username), new Variant(getPassword())).toDispatch();
    

    Once you have that you can use it to get access to the classes

    Dispatch securityDispatch =  Dispatch.call(wbemServices, "get", new Variant("Win32_Process")).toDistpatch();//REPLACED "Win32_Process" with Win32_LogicalFileSecuritySetting
    

    Once you have a dispatch to the class you can use it to do get and set any property you want by using Dispatch.call(dispatch,"method") or you can wrap it in an ActiveXComponent and do a put or get on it.

    For reference : http://msdn.microsoft.com/en-us/library/windows/desktop/aa394084(v=vs.85).aspx Win32_ classes

     
  • Doug Wegscheid
    Doug Wegscheid
    2013-11-07

    Why doesn't this work? I can't seem to pick up the 'out' parameter in sd. The sd object has all the right properties, but the values are all null....

    Variant objFolderSecuritySettings = sC.invoke("Get", "Win32_LogicalFileSecuritySetting='u:\\'");
    dumpElement(sC.getObject(), objFolderSecuritySettings.getDispatch(), "ObjectfolderSecurity"); // shows correct properties and methods!
    
    ActiveXComponent sd = new ActiveXComponent("winmgmts:Win32_SecurityDescriptor");
    Variant v = new Variant(sd, true);
    
    // try to call GetSecurityDescriptor with an out parameter (v or sd)
    Variant getSecurityDescriptorRc = Dispatch.call(objFolderSecuritySettings.getDispatch(), "GetSecurityDescriptor", v);
    dumpElement (sC.getObject(), sd.getObject(), "sd"); // shows the properties and path, but all properties have null values
    
    ...
    
    static void dumpElement(Dispatch top, Dispatch dItem, String prefix) {
        Dispatch dPath = Dispatch.get(dItem, "Path_").getDispatch();
        String sClass = Dispatch.get(dPath, "Class").getString();
        System.out.println(prefix + " path: " + sClass);
    
        Dispatch dObj = Dispatch.call(top, "get", sClass).getDispatch();
        {
          Dispatch d1 = Dispatch.call(dObj, "Properties_").getDispatch();
          EnumVariant en1 = new EnumVariant(d1);
          while (en1.hasMoreElements()) {
            Dispatch dProp = en1.nextElement().getDispatch();
            String name = Dispatch.get(dProp, "name").getString();
            String origin = Dispatch.get(dProp, "origin").getString();
            String v = Dispatch.call(dItem, name).toString();
            System.out.println(prefix + "  property: " + name + " (" + origin + "): " + v);
          }
        }
        {
          Dispatch d1 = Dispatch.call(dObj, "Methods_").getDispatch();
          EnumVariant en1 = new EnumVariant(d1);
          while (en1.hasMoreElements()) {
            Dispatch dProp = en1.nextElement().getDispatch();
            String name = Dispatch.get(dProp, "name").getString();
            String origin = Dispatch.get(dProp, "origin").getString();
            System.out.println(prefix + "  method: " + name + " (" + origin + ")");
          }
        }
    
      }