
December 12th, 2012, 08:57 PM
|
|
|
|
Problem with winmgmts
Hi, the following code works. If you enter a non existant directory for strFolderName it will err with 424.
Code:
On Error Resume Next
strFolderName = "C:\test"
Set objWMIService = GetObject("winmgmts:")
Set objFolderSecuritySettings = objWMIService.Get("Win32_LogicalFileSecuritySetting='" & strFolderName & "'")
intRetVal = objFolderSecuritySettings.GetSecurityDescriptor(objSD)
If err.number = 424 Then
MsgBox err.number
End If
err.clear
The following code does not work
Code:
'On Error Resume Next
test()
Sub test()
strFolderName = "C:\test"
Set objWMIService = GetObject("winmgmts:")
Set objFolderSecuritySettings = objWMIService.Get("Win32_LogicalFileSecuritySetting='" & strFolderName & "'")
info = objFolderSecuritySettings.GetSecurityDescriptor(objSD)
If err.number = 424 Then
MsgBox err.number
End If
err.clear
End Sub
Error test2.vbs(8, 2) SWbemServicesEx: Not found
I need run the code within a function or sub but whenever I put it in one the error comes up.
Please do not reply saying there is an easyer way to check is a directory exists because that is not the goal of the script.
|