Getting the security descriptor of a folder on a remote machine

Posted on 2009-12-31
Last Modified: 2012-05-08

I am trying to get the security descriptor of a folder on a remote machine with the following code:


On Error Resume Next

strServerName = Server123
strWMIGenSharePath = E:\\Data\\Test

Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServerName & "\root\cimv2")
Set objShareSec = objWMI.Get("Win32_LogicalFileSecuritySetting.Path=" & Chr(34) & strWMIGenSharePath & Chr(34))
Set retVal = objShareSec.GetSecurityDescriptor(objSD)
If Err <> 0 Then
    WScript.Echo "GetSecurityDescriptor failed" _
    & VBCRLF & Err.Number & VBCRLF & Err.Description
    WScript.Echo "GetSecurityDescriptor succeeded"
End If


I get the following error:

GetSecurityDescriptor failed
Object required

So it seems that it is not finding the Win32_LogicalFileSecuritySetting class for the folder but if I echo out the properties they do seem valid:

objShareSec.caption                            "Security settings of E:\DATA\Test"
objShareSec.controlflags                     "32772"
objShareSec.description                      "Security settings of E:\DATA\Test"
objShareSec.ownerpermissions          "-1"
objShareSec.path                                 "E:\DATA\Test"
objShareSec.settingid                           "null"

Can anyone explain what is happening here please?

Question by:Uncle_Chunky
    LVL 81

    Accepted Solution

    Hello Uncle Chunky,

    Try this :

    On Error Resume Next
    strServerName = "Server123"
    strWMIGenSharePath = "E:\\Data\\Test"
    Set objWMISvc = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strServerName & "\root\cimv2")
    strFileQuery = "SELECT * FROM Win32_LogicalFileSecuritySetting WHERE Path='" & strWMIGenSharePath & "'"
    Set objFile=objWMISvc.ExecQuery(strFileQuery)
    For Each objShareSec In objFile
    	retVal = objShareSec.GetSecurityDescriptor(objSD)
    If Err <> 0 Then
        WScript.Echo "GetSecurityDescriptor failed" & VBCRLF & Err.Number & VBCRLF & Err.Description
        WScript.Echo "GetSecurityDescriptor succeeded"
    End If

    Open in new window

    LVL 7

    Assisted Solution

    leakim is right.
    See line 4 of his post, you need to enclose the value of strWMIGenSharePath in quotes(").

    E:\\Data\\Test should be a textstring. If you don't enclose it WSH (the engine running your script) will beleive it's an internal or external object. Which it's not.
    Therefore it fails.

    Author Comment

    Yes, thanks. It was definitely a single quote issue. The following lines are now working okay for me.
    Set objShareSec = objWMI.Get("Win32_LogicalFileSecuritySetting='" & strWMIGenSharePath & "'")
    retVal = objShareSec.GetSecurityDescriptor(objSD) 

    Open in new window

    LVL 81

    Expert Comment

    Thanks for the points! Happy new year!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
    This article will show, step by step, how to integrate R code into a R Sweave document
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now