Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1038
  • Last Modified:

Getting the security descriptor of a folder on a remote machine

Hi,

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.Quit
Else
    WScript.Echo "GetSecurityDescriptor succeeded"
End If

*********************************************

I get the following error:

GetSecurityDescriptor failed
424
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?

Thanks
0
Uncle_Chunky
Asked:
Uncle_Chunky
  • 2
2 Solutions
 
leakim971PluritechnicianCommented:
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)
Next

If Err <> 0 Then
    WScript.Echo "GetSecurityDescriptor failed" & VBCRLF & Err.Number & VBCRLF & Err.Description
    WScript.Quit
Else
    WScript.Echo "GetSecurityDescriptor succeeded"
End If

Open in new window

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

Reason
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.
0
 
Uncle_ChunkyAuthor Commented:
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

0
 
leakim971PluritechnicianCommented:
Thanks for the points! Happy new year!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now