Hello,
I am currently trying to write a script to scan through all folders and
subfolders on a drive and return me their trustee information (who has
permission to view folder). I have written a script which seems to work
until it comes accross a folder name with an apostrophe in such as
"C:\O'Brien" This returns me an invalid path error as the apostrophe is
a reserved character and it stops reading after the apostrophe. I have
looked online for solutions and the only solution I have come accross
is to put a backslash before the apostrophe such as "C:\O\'Brien. I
have tried this but the same error occurs. If I enter a On Error Resume
Next code at the top of my script it will run through and appear to
work but the information it returns for the apostrophe folders is
incorrect - simply gives the previous folders information again. Can
anyone help me? The script I am using is the following:


strComputer = "."


Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")

Set colFolders = objWMIService.ExecQuery("Select * from Win32_Directory
WHERE Drive = 'G:' ")

For Each objFolder in colFolders

strFolder = objFolder.Name

Wscript.Echo objFolder.Name
path = objFolder.Name

Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set objFile = objWMIService.Get("Win32_LogicalFileSecuritySetting='"&
path & "'")

If objFile.GetSecurityDescriptor(objSD) = 0 Then

Wscript.Echo "Owner: " & objSD.Owner.Name
Wscript.Echo

For Each objAce in objSD.DACL
Wscript.Echo "Trustee: " & objAce.Trustee.Domain & "\" &
objAce.Trustee.Name
Next

End If

Next


Thanks for any help provided.

Re: Apostrophe problem when retrieving folder security details by Richard

Richard
Sun Nov 12 10:18:02 CST 2006

Hi,

Try replacing the single apostrophe with two:

path = Replace(objFolder.Name, "'", "''")

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

<Gemma.M.OBrien@googlemail.com> wrote in message
news:1163347635.395011.266280@h54g2000cwb.googlegroups.com...
> Hello,
> I am currently trying to write a script to scan through all folders and
> subfolders on a drive and return me their trustee information (who has
> permission to view folder). I have written a script which seems to work
> until it comes accross a folder name with an apostrophe in such as
> "C:\O'Brien" This returns me an invalid path error as the apostrophe is
> a reserved character and it stops reading after the apostrophe. I have
> looked online for solutions and the only solution I have come accross
> is to put a backslash before the apostrophe such as "C:\O\'Brien. I
> have tried this but the same error occurs. If I enter a On Error Resume
> Next code at the top of my script it will run through and appear to
> work but the information it returns for the apostrophe folders is
> incorrect - simply gives the previous folders information again. Can
> anyone help me? The script I am using is the following:
>
>
> strComputer = "."
>
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer &
> "\root\cimv2")
>
> Set colFolders = objWMIService.ExecQuery("Select * from Win32_Directory
> WHERE Drive = 'G:' ")
>
> For Each objFolder in colFolders
>
> strFolder = objFolder.Name
>
> Wscript.Echo objFolder.Name
> path = objFolder.Name
>
> Set objWMIService = GetObject("winmgmts:\\" & strComputer &
> "\root\cimv2")
> Set objFile = objWMIService.Get("Win32_LogicalFileSecuritySetting='"&
> path & "'")
>
> If objFile.GetSecurityDescriptor(objSD) = 0 Then
>
> Wscript.Echo "Owner: " & objSD.Owner.Name
> Wscript.Echo
>
> For Each objAce in objSD.DACL
> Wscript.Echo "Trustee: " & objAce.Trustee.Domain & "\" &
> objAce.Trustee.Name
> Next
>
> End If
>
> Next
>
>
> Thanks for any help provided.
>



Re: Apostrophe problem when retrieving folder security details by Gemma

Gemma
Sun Nov 12 10:35:58 CST 2006

Hi Richard,
I have just tried your suggestion and got the following error message
still:

GDriveTrustees.vbs(21, 1) SWbemServicesEx: Invalid object path

The 21st line of my code in this instance was the
Set objFile = objWMIService.Get("Win32_LogicalFileSecuritySetting='"&
path & "'")

When I print the folder path out from the Win32_Directory class it
works but trying to use an apostrophe in a folder path for the
Win32_LogicalFileSecuritySetting class it falls over. I am completely
baffled by this as vbscript can handle an apostrophe in one class but
not another.

Thanks for any help.
Gemma


Richard Mueller wrote:

> Hi,
>
> Try replacing the single apostrophe with two:
>
> path = Replace(objFolder.Name, "'", "''")
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>
> <Gemma.M.OBrien@googlemail.com> wrote in message
> news:1163347635.395011.266280@h54g2000cwb.googlegroups.com...
> > Hello,
> > I am currently trying to write a script to scan through all folders and
> > subfolders on a drive and return me their trustee information (who has
> > permission to view folder). I have written a script which seems to work
> > until it comes accross a folder name with an apostrophe in such as
> > "C:\O'Brien" This returns me an invalid path error as the apostrophe is
> > a reserved character and it stops reading after the apostrophe. I have
> > looked online for solutions and the only solution I have come accross
> > is to put a backslash before the apostrophe such as "C:\O\'Brien. I
> > have tried this but the same error occurs. If I enter a On Error Resume
> > Next code at the top of my script it will run through and appear to
> > work but the information it returns for the apostrophe folders is
> > incorrect - simply gives the previous folders information again. Can
> > anyone help me? The script I am using is the following:
> >
> >
> > strComputer = "."
> >
> >
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" & strComputer &
> > "\root\cimv2")
> >
> > Set colFolders = objWMIService.ExecQuery("Select * from Win32_Directory
> > WHERE Drive = 'G:' ")
> >
> > For Each objFolder in colFolders
> >
> > strFolder = objFolder.Name
> >
> > Wscript.Echo objFolder.Name
> > path = objFolder.Name
> >
> > Set objWMIService = GetObject("winmgmts:\\" & strComputer &
> > "\root\cimv2")
> > Set objFile = objWMIService.Get("Win32_LogicalFileSecuritySetting='"&
> > path & "'")
> >
> > If objFile.GetSecurityDescriptor(objSD) = 0 Then
> >
> > Wscript.Echo "Owner: " & objSD.Owner.Name
> > Wscript.Echo
> >
> > For Each objAce in objSD.DACL
> > Wscript.Echo "Trustee: " & objAce.Trustee.Domain & "\" &
> > objAce.Trustee.Name
> > Next
> >
> > End If
> >
> > Next
> >
> >
> > Thanks for any help provided.
> >


Re: Apostrophe problem when retrieving folder security details by Richard

Richard
Sun Nov 12 12:20:24 CST 2006

I suggested doubling the apostrophe's because that's what is done when
dealing with SQL queries. WMI uses Windows Query Language, WQL, which is
similar in that string values are enclosed in single quotes (apostrophe's).
However, I found the following link that says that apostrophe's in WQL are
escaped with the backslash character, as you first tried:

http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec04/hey1217.mspx

I tested your script and neither method worked. However, I got it to work
when I used objWMIService.ExecQuery instead of objWMIService.Get. Here is
the version I used. Note that I also double backslashes:
=================
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory WHERE Drive = 'C:' ")

For Each objFolder in colFolders

strFolder = objFolder.Name
strFolder = Replace(strFolder, "\", "\\")
strFolder = Replace(strFolder, "'", "\'")
Wscript.Echo "Folder: " & strFolder

Set colFiles = objWMIService.ExecQuery _
("SELECT * FROM Win32_LogicalFileSecuritySetting WHERE Path = '" _
& strFolder & "'")
For Each objFile in colFiles
If objFile.GetSecurityDescriptor(objSD) = 0 Then
Wscript.Echo "Owner: " & objSD.Owner.Name
For Each objAce in objSD.DACL
Wscript.Echo "Trustee: " & objAce.Trustee.Domain _
& "\" & objAce.Trustee.Name
Next
End If
Next
Next

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

<Gemma.M.OBrien@googlemail.com> wrote in message
news:1163349357.800192.42990@h54g2000cwb.googlegroups.com...
> Hi Richard,
> I have just tried your suggestion and got the following error message
> still:
>
> GDriveTrustees.vbs(21, 1) SWbemServicesEx: Invalid object path
>
> The 21st line of my code in this instance was the
> Set objFile = objWMIService.Get("Win32_LogicalFileSecuritySetting='"&
> path & "'")
>
> When I print the folder path out from the Win32_Directory class it
> works but trying to use an apostrophe in a folder path for the
> Win32_LogicalFileSecuritySetting class it falls over. I am completely
> baffled by this as vbscript can handle an apostrophe in one class but
> not another.
>
> Thanks for any help.
> Gemma
>
>
> Richard Mueller wrote:
>
>> Hi,
>>
>> Try replacing the single apostrophe with two:
>>
>> path = Replace(objFolder.Name, "'", "''")
>>
>> --
>> Richard
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>>
>> <Gemma.M.OBrien@googlemail.com> wrote in message
>> news:1163347635.395011.266280@h54g2000cwb.googlegroups.com...
>> > Hello,
>> > I am currently trying to write a script to scan through all folders and
>> > subfolders on a drive and return me their trustee information (who has
>> > permission to view folder). I have written a script which seems to work
>> > until it comes accross a folder name with an apostrophe in such as
>> > "C:\O'Brien" This returns me an invalid path error as the apostrophe is
>> > a reserved character and it stops reading after the apostrophe. I have
>> > looked online for solutions and the only solution I have come accross
>> > is to put a backslash before the apostrophe such as "C:\O\'Brien. I
>> > have tried this but the same error occurs. If I enter a On Error Resume
>> > Next code at the top of my script it will run through and appear to
>> > work but the information it returns for the apostrophe folders is
>> > incorrect - simply gives the previous folders information again. Can
>> > anyone help me? The script I am using is the following:
>> >
>> >
>> > strComputer = "."
>> >
>> >
>> > Set objWMIService = GetObject("winmgmts:" _
>> > & "{impersonationLevel=impersonate}!\\" & strComputer &
>> > "\root\cimv2")
>> >
>> > Set colFolders = objWMIService.ExecQuery("Select * from Win32_Directory
>> > WHERE Drive = 'G:' ")
>> >
>> > For Each objFolder in colFolders
>> >
>> > strFolder = objFolder.Name
>> >
>> > Wscript.Echo objFolder.Name
>> > path = objFolder.Name
>> >
>> > Set objWMIService = GetObject("winmgmts:\\" & strComputer &
>> > "\root\cimv2")
>> > Set objFile = objWMIService.Get("Win32_LogicalFileSecuritySetting='"&
>> > path & "'")
>> >
>> > If objFile.GetSecurityDescriptor(objSD) = 0 Then
>> >
>> > Wscript.Echo "Owner: " & objSD.Owner.Name
>> > Wscript.Echo
>> >
>> > For Each objAce in objSD.DACL
>> > Wscript.Echo "Trustee: " & objAce.Trustee.Domain & "\" &
>> > objAce.Trustee.Name
>> > Next
>> >
>> > End If
>> >
>> > Next
>> >
>> >
>> > Thanks for any help provided.
>> >
>