YawStar Posted April 21, 2018 Share Posted April 21, 2018 I have a script that can get file owner. When i get owner name of normal file ( without apostrophe ) is OK. But when i get owner name of file named with apostrophe, there is an error occured. I am using ObjGet("winmgmts:") and the error line is $oWMIService.Get("Win32_LogicalFileSecuritySetting='" & $FGO_Path & "'") There is compicate with apostrophe and single quote. I change $oWMIService.Get("Win32_LogicalFileSecuritySetting='" & $FGO_Path & "'") to $oWMIService.Get("Win32_LogicalFileSecuritySetting=" & '"' & $FGO_Path & '"') but it is not OK. Please any suggestion to my script. Here is my script Dim $objSD $File_Path = @ScriptDir & "\Dir With Space\Test file with apostrophe' character.txt" $oWMIService = ObjGet("winmgmts:") $oFolderSecuritySettings = $oWMIService.Get("Win32_LogicalFileSecuritySetting='" & $FGO_Path & "'") ;Error show this style $oFolderSecuritySettings = $oWMIService.Get("Win32_LogicalFileSecuritySetting=" & '"' & $FGO_Path & '"') $intRetVal = $oFolderSecuritySettings.GetSecurityDescriptor($objSD) If $intRetVal = 0 Then MsgBox (0, "", "Owner: " & $objSD.Owner.Domain & "\" & $objSD.Owner.Name) Else MsgBox (0, "", "Couldn't retrieve security descriptor.") EndIf Link to comment Share on other sites More sharing options...
ripdad Posted April 21, 2018 Share Posted April 21, 2018 try this... Local $sFile = @ScriptDir & "\Dir With Space\Test file with apostrophe' character.txt" Local $objWMI = ObjGet('winmgmts:root\cimv2') Local $objItem = $objWMI.Get('Win32_LogicalFileSecuritySetting.Path="' & StringReplace($sFile, '\', '\\') & '"') Local $objSD, $nResult = $objItem.GetSecurityDescriptor($objSD) ; If $nResult = 0 Then MsgBox(0, '', 'Owner: ' & $objSD.Owner.Domain & '\' & $objSD.Owner.Name) Else MsgBox(0, '', "Couldn't retrieve security descriptor.") EndIf YawStar 1 "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
YawStar Posted April 21, 2018 Author Share Posted April 21, 2018 Thank you ripdad. It is working. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now