folder security description

  • 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
                    SetUserRights = False
                End If
                Exit Function
            End If

    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();
      , "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 =, "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,"method") or you can wrap it in an ActiveXComponent and do a put or get on it.

    For reference : 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 =, "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 =, "get", sClass).getDispatch();
          Dispatch d1 =, "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 =, name).toString();
            System.out.println(prefix + "  property: " + name + " (" + origin + "): " + v);
          Dispatch d1 =, "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 + ")");

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks