Jump to content

Problem with apostrophe and single quote


Recommended Posts

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

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

 

"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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...