Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Win32_Directory.Name - Problem with Spaces / Blanks!

Reply
 
Old 07-30-2009   #1 (permalink)
Juan


 
 

Win32_Directory.Name - Problem with Spaces / Blanks!

Hi,


I used the following lines to detect changes within a folder. - I get an
email if a file is placed or deleted in a specific folder.

It works pretty fine if the path contains no spaces / blanks. - But it
doesn't work if there is a space in the path.

Here is the code:


Set colEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
&
"'Win32_Directory.Name=""c:\\\\Myfolder\\\\ImportantContent""'")

Do While True
strEmailBody = Now & VbCrLf
Set objEvent = colEvents.NextEvent()
Select Case objEvent.Path_.Class
Case "__InstanceCreationEvent"
strEmailBody = strEmailBody & "A new file was just created: " & _
objEvent.TargetInstance.PartComponent & VbCrLf
Case "__InstanceDeletionEvent"
strEmailBody = strEmailBody & "A file was just deleted: " & _
objEvent.TargetInstance.PartComponent
End Select
SbSendMailWithBlat()
Loop


I have to check a folder in the Program Files directory. I tried %20, double
and single quotes, Chr(32) but no success ...


Many thanks in advance



Juan

My System SpecsSystem Spec
Old 07-30-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Win32_Directory.Name - Problem with Spaces / Blanks!


"Juan" <Juan@xxxxxx> wrote in message
news:49F846A6-0E92-4127-86BA-C6DE3A50C2E3@xxxxxx
Quote:

> Hi,
>
>
> I used the following lines to detect changes within a folder. - I get an
> email if a file is placed or deleted in a specific folder.
>
> It works pretty fine if the path contains no spaces / blanks. - But it
> doesn't work if there is a space in the path.
>
> Here is the code:
>
>
> Set colEvents = objWMIService.ExecNotificationQuery _
> ("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE " _
> & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
> & "TargetInstance.GroupComponent= " _
> &
> "'Win32_Directory.Name=""c:\\\\Myfolder\\\\ImportantContent""'")
>
> Do While True
> strEmailBody = Now & VbCrLf
> Set objEvent = colEvents.NextEvent()
> Select Case objEvent.Path_.Class
> Case "__InstanceCreationEvent"
> strEmailBody = strEmailBody & "A new file was just created: " & _
> objEvent.TargetInstance.PartComponent & VbCrLf
> Case "__InstanceDeletionEvent"
> strEmailBody = strEmailBody & "A file was just deleted: " & _
> objEvent.TargetInstance.PartComponent
> End Select
> SbSendMailWithBlat()
> Loop
>
>
> I have to check a folder in the Program Files directory. I tried %20,
> double
> and single quotes, Chr(32) but no success ...
>
>
> Many thanks in advance
>
>
>
> Juan
Your single quotes are in the wrong place. No need for double quotes. The
single quotes should surround the name of the folder. I believe it should
be:

& "Win32_Directory.Name='c:\\Myfolder\\Program Files'")

And the backslashes only need to be doubled, unless I'm mistaken.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 07-31-2009   #3 (permalink)
Juan


 
 

Re: Win32_Directory.Name - Problem with Spaces / Blanks!

Dear Richard,

I still get "unparsable query", I changed the \\ to \\\\ - also "unparsable
query"

Do you have another idea?


thanks


Juan

"Richard Mueller [MVP]" wrote:
Quote:

>
> "Juan" <Juan@xxxxxx> wrote in message
> news:49F846A6-0E92-4127-86BA-C6DE3A50C2E3@xxxxxx
Quote:

> > Hi,
> >
> >
> > I used the following lines to detect changes within a folder. - I get an
> > email if a file is placed or deleted in a specific folder.
> >
> > It works pretty fine if the path contains no spaces / blanks. - But it
> > doesn't work if there is a space in the path.
> >
> > Here is the code:
> >
> >
> > Set colEvents = objWMIService.ExecNotificationQuery _
> > ("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE " _
> > & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
> > & "TargetInstance.GroupComponent= " _
> > &
> > "'Win32_Directory.Name=""c:\\\\Myfolder\\\\ImportantContent""'")
> >
> > Do While True
> > strEmailBody = Now & VbCrLf
> > Set objEvent = colEvents.NextEvent()
> > Select Case objEvent.Path_.Class
> > Case "__InstanceCreationEvent"
> > strEmailBody = strEmailBody & "A new file was just created: " & _
> > objEvent.TargetInstance.PartComponent & VbCrLf
> > Case "__InstanceDeletionEvent"
> > strEmailBody = strEmailBody & "A file was just deleted: " & _
> > objEvent.TargetInstance.PartComponent
> > End Select
> > SbSendMailWithBlat()
> > Loop
> >
> >
> > I have to check a folder in the Program Files directory. I tried %20,
> > double
> > and single quotes, Chr(32) but no success ...
> >
> >
> > Many thanks in advance
> >
> >
> >
> > Juan
>
> Your single quotes are in the wrong place. No need for double quotes. The
> single quotes should surround the name of the folder. I believe it should
> be:
>
> & "Win32_Directory.Name='c:\\Myfolder\\Program Files'")
>
> And the backslashes only need to be doubled, unless I'm mistaken.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>
My System SpecsSystem Spec
Old 07-31-2009   #4 (permalink)
Richard Mueller [MVP]


 
 

Re: Win32_Directory.Name - Problem with Spaces / Blanks!

I'm not familiar with WMI monitoring scripts but I found this link using the
identical query:

http://www.microsoft.com/technet/scr...5/hey0404.mspx

This shows your syntax is essentially correct, but does not explain why a
space in the path would cause a problem. In fact, since that path is already
in quotes, I would not expect an error. Instead, I wonder if this a
permission issue. See if the scripts works with another folder created by
you with spaces in the name. On newer OS's like Vista, users lack
permissions in special folders like "C:\Program Files".

Note the query is the concatenation of several strings. Within any string a
quote character is represented by two quote characters. For example the
string:

strValue = "This is an ""Example""."

Resolves into:

This is an "Example".

You can check this by echoing the string to the command prompt with
Wscript.Echo. In your case the last string in the query is:

"'Win32_Directory.Name=""c:\\\\Myfolder\\\\ImportantContent""'"

and this resolves into the following (again check by echoing the value at a
command prompt):

'Win32_Directory.Name="c:\\\\Myfolder\\\\ImportantContent"'

The quadrupled slashes are another issue. In WMI queries, doubled slashes
resolve to single slashes. In any case, the path is definitely enclosed in
quotes, so spaces should not be a problem (as far as I know).

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
"Juan" <Juan@xxxxxx> wrote in message
news:E6190053-4182-4893-8444-1DC6A8E70FF3@xxxxxx
Quote:

> Dear Richard,
>
> I still get "unparsable query", I changed the \\ to \\\\ - also
> "unparsable
> query"
>
> Do you have another idea?
>
>
> thanks
>
>
> Juan
>
> "Richard Mueller [MVP]" wrote:
>
Quote:

>>
>> "Juan" <Juan@xxxxxx> wrote in message
>> news:49F846A6-0E92-4127-86BA-C6DE3A50C2E3@xxxxxx
Quote:

>> > Hi,
>> >
>> >
>> > I used the following lines to detect changes within a folder. - I get
>> > an
>> > email if a file is placed or deleted in a specific folder.
>> >
>> > It works pretty fine if the path contains no spaces / blanks. - But it
>> > doesn't work if there is a space in the path.
>> >
>> > Here is the code:
>> >
>> >
>> > Set colEvents = objWMIService.ExecNotificationQuery _
>> > ("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE " _
>> > & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
>> > & "TargetInstance.GroupComponent= " _
>> > &
>> > "'Win32_Directory.Name=""c:\\\\Myfolder\\\\ImportantContent""'")
>> >
>> > Do While True
>> > strEmailBody = Now & VbCrLf
>> > Set objEvent = colEvents.NextEvent()
>> > Select Case objEvent.Path_.Class
>> > Case "__InstanceCreationEvent"
>> > strEmailBody = strEmailBody & "A new file was just created: " & _
>> > objEvent.TargetInstance.PartComponent & VbCrLf
>> > Case "__InstanceDeletionEvent"
>> > strEmailBody = strEmailBody & "A file was just deleted: " & _
>> > objEvent.TargetInstance.PartComponent
>> > End Select
>> > SbSendMailWithBlat()
>> > Loop
>> >
>> >
>> > I have to check a folder in the Program Files directory. I tried %20,
>> > double
>> > and single quotes, Chr(32) but no success ...
>> >
>> >
>> > Many thanks in advance
>> >
>> >
>> >
>> > Juan
>>
>> Your single quotes are in the wrong place. No need for double quotes. The
>> single quotes should surround the name of the folder. I believe it should
>> be:
>>
>> & "Win32_Directory.Name='c:\\Myfolder\\Program Files'")
>>
>> And the backslashes only need to be doubled, unless I'm mistaken.
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>>

My System SpecsSystem Spec
Old 07-31-2009   #5 (permalink)
Juan


 
 

Re: Win32_Directory.Name - Problem with Spaces / Blanks!

Hi,


it wasn't a permission issue. And it wasn't a problem of WQL.
The problem was in BLAT.EXE! I opened filemon and I saw that Blat.exe failed
with communicating to some DLLs.

I changed the sending method from Blat.exe to VBScript (CDO) and now it is
working.


Anyway - thanks for your fast replies.



Juan

"Richard Mueller [MVP]" wrote:
Quote:

> I'm not familiar with WMI monitoring scripts but I found this link using the
> identical query:
>
> http://www.microsoft.com/technet/scr...5/hey0404.mspx
>
> This shows your syntax is essentially correct, but does not explain why a
> space in the path would cause a problem. In fact, since that path is already
> in quotes, I would not expect an error. Instead, I wonder if this a
> permission issue. See if the scripts works with another folder created by
> you with spaces in the name. On newer OS's like Vista, users lack
> permissions in special folders like "C:\Program Files".
>
> Note the query is the concatenation of several strings. Within any string a
> quote character is represented by two quote characters. For example the
> string:
>
> strValue = "This is an ""Example""."
>
> Resolves into:
>
> This is an "Example".
>
> You can check this by echoing the string to the command prompt with
> Wscript.Echo. In your case the last string in the query is:
>
> "'Win32_Directory.Name=""c:\\\\Myfolder\\\\ImportantContent""'"
>
> and this resolves into the following (again check by echoing the value at a
> command prompt):
>
> 'Win32_Directory.Name="c:\\\\Myfolder\\\\ImportantContent"'
>
> The quadrupled slashes are another issue. In WMI queries, doubled slashes
> resolve to single slashes. In any case, the path is definitely enclosed in
> quotes, so spaces should not be a problem (as far as I know).
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
> "Juan" <Juan@xxxxxx> wrote in message
> news:E6190053-4182-4893-8444-1DC6A8E70FF3@xxxxxx
Quote:

> > Dear Richard,
> >
> > I still get "unparsable query", I changed the \\ to \\\\ - also
> > "unparsable
> > query"
> >
> > Do you have another idea?
> >
> >
> > thanks
> >
> >
> > Juan
> >
> > "Richard Mueller [MVP]" wrote:
> >
Quote:

> >>
> >> "Juan" <Juan@xxxxxx> wrote in message
> >> news:49F846A6-0E92-4127-86BA-C6DE3A50C2E3@xxxxxx
> >> > Hi,
> >> >
> >> >
> >> > I used the following lines to detect changes within a folder. - I get
> >> > an
> >> > email if a file is placed or deleted in a specific folder.
> >> >
> >> > It works pretty fine if the path contains no spaces / blanks. - But it
> >> > doesn't work if there is a space in the path.
> >> >
> >> > Here is the code:
> >> >
> >> >
> >> > Set colEvents = objWMIService.ExecNotificationQuery _
> >> > ("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE " _
> >> > & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
> >> > & "TargetInstance.GroupComponent= " _
> >> > &
> >> > "'Win32_Directory.Name=""c:\\\\Myfolder\\\\ImportantContent""'")
> >> >
> >> > Do While True
> >> > strEmailBody = Now & VbCrLf
> >> > Set objEvent = colEvents.NextEvent()
> >> > Select Case objEvent.Path_.Class
> >> > Case "__InstanceCreationEvent"
> >> > strEmailBody = strEmailBody & "A new file was just created: " & _
> >> > objEvent.TargetInstance.PartComponent & VbCrLf
> >> > Case "__InstanceDeletionEvent"
> >> > strEmailBody = strEmailBody & "A file was just deleted: " & _
> >> > objEvent.TargetInstance.PartComponent
> >> > End Select
> >> > SbSendMailWithBlat()
> >> > Loop
> >> >
> >> >
> >> > I have to check a folder in the Program Files directory. I tried %20,
> >> > double
> >> > and single quotes, Chr(32) but no success ...
> >> >
> >> >
> >> > Many thanks in advance
> >> >
> >> >
> >> >
> >> > Juan
> >>
> >> Your single quotes are in the wrong place. No need for double quotes. The
> >> single quotes should surround the name of the folder. I believe it should
> >> be:
> >>
> >> & "Win32_Directory.Name='c:\\Myfolder\\Program Files'")
> >>
> >> And the backslashes only need to be doubled, unless I'm mistaken.
> >>
> >> --
> >> Richard Mueller
> >> MVP Directory Services
> >> Hilltop Lab - http://www.rlmueller.net
> >> --
> >>
> >>
> >>
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Display blanks and does not go to sleep Vista hardware & devices
display blanks out Vista hardware & devices
Tv out blanks computer screen Vista hardware & devices
params containing blanks PowerShell
Vista Screen Blanks Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46