Need help converting VBScript WMI query to WinBatch

Started by jtrask, June 17, 2015, 11:56:43 AM

Previous topic - Next topic

jtrask

Usually, when I query WMI, I'm able to cut/paste/tweak one of my previous UDFs, but I've stumbled upon a VB example on the Internet that is doing something I've never seen before. 

I'm not sure what to make of the example is doing what looks like WMI stuff BEFORE querying WMI via objWMIService.  I'm also not sure what to make of the RetVal line.  I though it was just checking for a value, but is it actually creating the object wmiSecurityDescriptor? That name is used later.  If so, would I do the same with wmiSecurityDescriptor = ObjectGet('winmgmts:Win32_LogicalFileSecuritySetting.path="':vstrfolderpath:'"').  I'm guessing not, 'cause it aint workin'. I get "Initiate Failed"

folderpath = Replace(FolderName, "\", "\\")

objectpath = "winmgmts:Win32_LogicalFileSecuritySetting.path='" & folderpath & "'"

'Get the security set for the object
Set wmiFileSecSetting = GetObject(objectpath)

'verify that the get was successful
RetVal = wmiFileSecSetting.GetSecurityDescriptor(wmiSecurityDescriptor)
If Err Then
     MsgBox ("GetSecurityDescriptor failed" & vbCrLf & Err.Number & vbCrLf & Err.Description)
     Err.Clear
End If

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery("SELECT * FROM Win32_Directory WHERE Name ='" & _
    folderpath & "'")
For Each objFolder In colFolders
     
    ' Retrieve the DACL array of Win32_ACE objects.
    DACL = wmiSecurityDescriptor.DACL

td

You need to remove the VB concatenation operators.

Code (winbatch) Select
strPath = "c:\\Temp"
wmiFileSecSetting = GetObject("winmgmts:Win32_LogicalFileSecuritySetting.path='":strPath:"'")


and it looks like the ReVal variable is ignored.  You do need to instantiate the wmiSecurityDescriptor variable (wmiSecurityDescriptor=0) before you call the GetSecurityDescriptor method because it is an 'out' parameter.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

jtrask

That's what I was doing, but I just realized that my problem is that I'm not using a valid path.

I'm trying to get the files system permissions to a folder on a remote machine.  I'm passing it a path that is local to the remote machines - E:\Data\backup. When I pass it C:\Users - a path valid on my computer - that line doesn't crash.

I'm coming to the conclusion that this may not be the way to go about what I'm doing.  I will open a new thread to discuss how I can do what I want to do.