Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: Unparsable Query

HTVi
TV Discussion Newsgroups

Unparsable Query
Carolanne 4/27/2007 2:20:00 AM
I have a script that will notify me when new files are added to a folder.
This works really well when I test it on my local computer but I need it to
monitor a network share. When I replace the local path (C:\Test) with with
the path to the network directory (S:\Shared\ShielahS) I get the "unparsable
query error." Here is my code. ANY help is very greatly appreciated!

Option Explicit
'On Error Resume Next

'Environment Constants
Const STRFrom = "ITSupport[ at ]kennedyusa.com" 'This is the address the email
will appear from
Const STRTo="carols[ at ]kennedyusa.com" 'Recipients of the email
Const SMTP_SERVER = "192.180.200.39"


Dim objFSO
Dim strComputer
Dim objWMIService
Dim colMonitoredEvents
Dim objLatestEvent
Dim objMail
Dim objStartFolder
Dim objFolder


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!//" & _
strComputer & "/root/cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""C:\\\\Test""'")

Do
Set objLatestEvent = colMonitoredEvents.NextEvent
'Wscript.Echo objLatestEvent.TargetInstance.PartComponent
SendMail

Loop

Sub SendMail

Set objMail = CreateObject ("CDO.Message")
Set objFSO = CreateObject("Scripting.filesystemObject")

objMail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
SMTP_SERVER
objMail.Configuration.Fields.Item
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMail.Configuration.Fields.Update

objMail.From = STRFrom
objMail.To = STRTo
'objMail.CC=STRCC

objMail.Subject = "There is a new lease ready for review"
objMail.Textbody = "This is an autogenerated message. Please do not respond
to this messsage." & vbCRLF & _
"A new lease has been placed in the following location:
S:\ShielahS\IN\." & vbCRLF & vbCRLF & _
"File name:" & (Mid(objLatestEvent.TargetInstance.PartComponent,49))

objMail.Send

Set objMail = Nothing
End Sub




RE: Unparsable Query
urkec 4/27/2007 4:30:05 PM
I think you can replace

strComputer = "."

with

strComputer = "RemoteComputerName"

and then use local path:

& "'Win32_Directory.Name=""C:\\\\SomePath""'"

--
urkec


"Carolanne" wrote:

[Quoted Text]
> I have a script that will notify me when new files are added to a folder.
> This works really well when I test it on my local computer but I need it to
> monitor a network share. When I replace the local path (C:\Test) with with
> the path to the network directory (S:\Shared\ShielahS) I get the "unparsable
> query error." Here is my code. ANY help is very greatly appreciated!
>
> Option Explicit
> 'On Error Resume Next
>
> 'Environment Constants
> Const STRFrom = "ITSupport[ at ]kennedyusa.com" 'This is the address the email
> will appear from
> Const STRTo="carols[ at ]kennedyusa.com" 'Recipients of the email
> Const SMTP_SERVER = "192.180.200.39"
>
>
> Dim objFSO
> Dim strComputer
> Dim objWMIService
> Dim colMonitoredEvents
> Dim objLatestEvent
> Dim objMail
> Dim objStartFolder
> Dim objFolder
>
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!//" & _
> strComputer & "/root/cimv2")
> Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
> ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
> & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
> & "TargetInstance.GroupComponent= " _
> & "'Win32_Directory.Name=""C:\\\\Test""'")
>
> Do
> Set objLatestEvent = colMonitoredEvents.NextEvent
> 'Wscript.Echo objLatestEvent.TargetInstance.PartComponent
> SendMail
>
> Loop
>
> Sub SendMail
>
> Set objMail = CreateObject ("CDO.Message")
> Set objFSO = CreateObject("Scripting.filesystemObject")
>
> objMail.Configuration.Fields.Item
> ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
> objMail.Configuration.Fields.Item
> ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
> SMTP_SERVER
> objMail.Configuration.Fields.Item
> ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
> objMail.Configuration.Fields.Update
>
> objMail.From = STRFrom
> objMail.To = STRTo
> 'objMail.CC=STRCC
>
> objMail.Subject = "There is a new lease ready for review"
> objMail.Textbody = "This is an autogenerated message. Please do not respond
> to this messsage." & vbCRLF & _
> "A new lease has been placed in the following location:
> S:\ShielahS\IN\." & vbCRLF & vbCRLF & _
> "File name:" & (Mid(objLatestEvent.TargetInstance.PartComponent,49))
>
> objMail.Send
>
> Set objMail = Nothing
> End Sub
>
>
>
>
RE: Unparsable Query
Carolanne 4/27/2007 4:40:02 PM
That sort of works.

When I change "." to "RemoteComputer" and change
"'Win32_Directory.Name=""C:\\\\SomePath""'"
to "'Win32_Directory.Name=""S:\\\\SomePath""'" it looks at the network drive.

But what I need it to do is look at S:\\\\SomePath\\Subdirectory. It
doesn't like subdirectories. How can I get it to recognize directories
beyond the root? Thanks for your help urkec!

"urkec" wrote:

[Quoted Text]
> I think you can replace
>
> strComputer = "."
>
> with
>
> strComputer = "RemoteComputerName"
>
> and then use local path:
>
> & "'Win32_Directory.Name=""C:\\\\SomePath""'"
>
> --
> urkec
>
>
> "Carolanne" wrote:
>
> > I have a script that will notify me when new files are added to a folder.
> > This works really well when I test it on my local computer but I need it to
> > monitor a network share. When I replace the local path (C:\Test) with with
> > the path to the network directory (S:\Shared\ShielahS) I get the "unparsable
> > query error." Here is my code. ANY help is very greatly appreciated!
> >
> > Option Explicit
> > 'On Error Resume Next
> >
> > 'Environment Constants
> > Const STRFrom = "ITSupport[ at ]kennedyusa.com" 'This is the address the email
> > will appear from
> > Const STRTo="carols[ at ]kennedyusa.com" 'Recipients of the email
> > Const SMTP_SERVER = "192.180.200.39"
> >
> >
> > Dim objFSO
> > Dim strComputer
> > Dim objWMIService
> > Dim colMonitoredEvents
> > Dim objLatestEvent
> > Dim objMail
> > Dim objStartFolder
> > Dim objFolder
> >
> >
> > strComputer = "."
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!//" & _
> > strComputer & "/root/cimv2")
> > Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
> > ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
> > & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
> > & "TargetInstance.GroupComponent= " _
> > & "'Win32_Directory.Name=""C:\\\\Test""'")
> >
> > Do
> > Set objLatestEvent = colMonitoredEvents.NextEvent
> > 'Wscript.Echo objLatestEvent.TargetInstance.PartComponent
> > SendMail
> >
> > Loop
> >
> > Sub SendMail
> >
> > Set objMail = CreateObject ("CDO.Message")
> > Set objFSO = CreateObject("Scripting.filesystemObject")
> >
> > objMail.Configuration.Fields.Item
> > ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
> > objMail.Configuration.Fields.Item
> > ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
> > SMTP_SERVER
> > objMail.Configuration.Fields.Item
> > ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
> > objMail.Configuration.Fields.Update
> >
> > objMail.From = STRFrom
> > objMail.To = STRTo
> > 'objMail.CC=STRCC
> >
> > objMail.Subject = "There is a new lease ready for review"
> > objMail.Textbody = "This is an autogenerated message. Please do not respond
> > to this messsage." & vbCRLF & _
> > "A new lease has been placed in the following location:
> > S:\ShielahS\IN\." & vbCRLF & vbCRLF & _
> > "File name:" & (Mid(objLatestEvent.TargetInstance.PartComponent,49))
> >
> > objMail.Send
> >
> > Set objMail = Nothing
> > End Sub
> >
> >
> >
> >
RE: Unparsable Query
urkec 4/27/2007 5:32:01 PM
I think you need to include all four backslashes:

& "'Win32_Directory.Name=""c:\\\\SomePath\\\\SubDir""'")

--
urkec


"Carolanne" wrote:

[Quoted Text]
> That sort of works.
>
> When I change "." to "RemoteComputer" and change
> "'Win32_Directory.Name=""C:\\\\SomePath""'"
> to "'Win32_Directory.Name=""S:\\\\SomePath""'" it looks at the network drive.
>
> But what I need it to do is look at S:\\\\SomePath\\Subdirectory. It
> doesn't like subdirectories. How can I get it to recognize directories
> beyond the root? Thanks for your help urkec!
>
> "urkec" wrote:
>
> > I think you can replace
> >
> > strComputer = "."
> >
> > with
> >
> > strComputer = "RemoteComputerName"
> >
> > and then use local path:
> >
> > & "'Win32_Directory.Name=""C:\\\\SomePath""'"
> >
> > --
> > urkec
> >
> >
> > "Carolanne" wrote:
> >
> > > I have a script that will notify me when new files are added to a folder.
> > > This works really well when I test it on my local computer but I need it to
> > > monitor a network share. When I replace the local path (C:\Test) with with
> > > the path to the network directory (S:\Shared\ShielahS) I get the "unparsable
> > > query error." Here is my code. ANY help is very greatly appreciated!
> > >
> > > Option Explicit
> > > 'On Error Resume Next
> > >
> > > 'Environment Constants
> > > Const STRFrom = "ITSupport[ at ]kennedyusa.com" 'This is the address the email
> > > will appear from
> > > Const STRTo="carols[ at ]kennedyusa.com" 'Recipients of the email
> > > Const SMTP_SERVER = "192.180.200.39"
> > >
> > >
> > > Dim objFSO
> > > Dim strComputer
> > > Dim objWMIService
> > > Dim colMonitoredEvents
> > > Dim objLatestEvent
> > > Dim objMail
> > > Dim objStartFolder
> > > Dim objFolder
> > >
> > >
> > > strComputer = "."
> > > Set objWMIService = GetObject("winmgmts:" _
> > > & "{impersonationLevel=impersonate}!//" & _
> > > strComputer & "/root/cimv2")
> > > Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
> > > ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
> > > & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
> > > & "TargetInstance.GroupComponent= " _
> > > & "'Win32_Directory.Name=""C:\\\\Test""'")
> > >
> > > Do
> > > Set objLatestEvent = colMonitoredEvents.NextEvent
> > > 'Wscript.Echo objLatestEvent.TargetInstance.PartComponent
> > > SendMail
> > >
> > > Loop
> > >
> > > Sub SendMail
> > >
> > > Set objMail = CreateObject ("CDO.Message")
> > > Set objFSO = CreateObject("Scripting.filesystemObject")
> > >
> > > objMail.Configuration.Fields.Item
> > > ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
> > > objMail.Configuration.Fields.Item
> > > ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
> > > SMTP_SERVER
> > > objMail.Configuration.Fields.Item
> > > ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
> > > objMail.Configuration.Fields.Update
> > >
> > > objMail.From = STRFrom
> > > objMail.To = STRTo
> > > 'objMail.CC=STRCC
> > >
> > > objMail.Subject = "There is a new lease ready for review"
> > > objMail.Textbody = "This is an autogenerated message. Please do not respond
> > > to this messsage." & vbCRLF & _
> > > "A new lease has been placed in the following location:
> > > S:\ShielahS\IN\." & vbCRLF & vbCRLF & _
> > > "File name:" & (Mid(objLatestEvent.TargetInstance.PartComponent,49))
> > >
> > > objMail.Send
> > >
> > > Set objMail = Nothing
> > > End Sub
> > >
> > >
> > >
> > >
RE: Unparsable Query
Carolanne 4/27/2007 5:44:05 PM
Are you kidding me?! I can't believe it was something so simple. Well, now
I'm just embarrassed. It worked like a charm. Thanks again for your help!

"urkec" wrote:

[Quoted Text]
> I think you need to include all four backslashes:
>
> & "'Win32_Directory.Name=""c:\\\\SomePath\\\\SubDir""'")
>
> --
> urkec
>
>
> "Carolanne" wrote:
>
> > That sort of works.
> >
> > When I change "." to "RemoteComputer" and change
> > "'Win32_Directory.Name=""C:\\\\SomePath""'"
> > to "'Win32_Directory.Name=""S:\\\\SomePath""'" it looks at the network drive.
> >
> > But what I need it to do is look at S:\\\\SomePath\\Subdirectory. It
> > doesn't like subdirectories. How can I get it to recognize directories
> > beyond the root? Thanks for your help urkec!
> >
> > "urkec" wrote:
> >
> > > I think you can replace
> > >
> > > strComputer = "."
> > >
> > > with
> > >
> > > strComputer = "RemoteComputerName"
> > >
> > > and then use local path:
> > >
> > > & "'Win32_Directory.Name=""C:\\\\SomePath""'"
> > >
> > > --
> > > urkec
> > >
> > >
> > > "Carolanne" wrote:
> > >
> > > > I have a script that will notify me when new files are added to a folder.
> > > > This works really well when I test it on my local computer but I need it to
> > > > monitor a network share. When I replace the local path (C:\Test) with with
> > > > the path to the network directory (S:\Shared\ShielahS) I get the "unparsable
> > > > query error." Here is my code. ANY help is very greatly appreciated!
> > > >
> > > > Option Explicit
> > > > 'On Error Resume Next
> > > >
> > > > 'Environment Constants
> > > > Const STRFrom = "ITSupport[ at ]kennedyusa.com" 'This is the address the email
> > > > will appear from
> > > > Const STRTo="carols[ at ]kennedyusa.com" 'Recipients of the email
> > > > Const SMTP_SERVER = "192.180.200.39"
> > > >
> > > >
> > > > Dim objFSO
> > > > Dim strComputer
> > > > Dim objWMIService
> > > > Dim colMonitoredEvents
> > > > Dim objLatestEvent
> > > > Dim objMail
> > > > Dim objStartFolder
> > > > Dim objFolder
> > > >
> > > >
> > > > strComputer = "."
> > > > Set objWMIService = GetObject("winmgmts:" _
> > > > & "{impersonationLevel=impersonate}!//" & _
> > > > strComputer & "/root/cimv2")
> > > > Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
> > > > ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
> > > > & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
> > > > & "TargetInstance.GroupComponent= " _
> > > > & "'Win32_Directory.Name=""C:\\\\Test""'")
> > > >
> > > > Do
> > > > Set objLatestEvent = colMonitoredEvents.NextEvent
> > > > 'Wscript.Echo objLatestEvent.TargetInstance.PartComponent
> > > > SendMail
> > > >
> > > > Loop
> > > >
> > > > Sub SendMail
> > > >
> > > > Set objMail = CreateObject ("CDO.Message")
> > > > Set objFSO = CreateObject("Scripting.filesystemObject")
> > > >
> > > > objMail.Configuration.Fields.Item
> > > > ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
> > > > objMail.Configuration.Fields.Item
> > > > ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
> > > > SMTP_SERVER
> > > > objMail.Configuration.Fields.Item
> > > > ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
> > > > objMail.Configuration.Fields.Update
> > > >
> > > > objMail.From = STRFrom
> > > > objMail.To = STRTo
> > > > 'objMail.CC=STRCC
> > > >
> > > > objMail.Subject = "There is a new lease ready for review"
> > > > objMail.Textbody = "This is an autogenerated message. Please do not respond
> > > > to this messsage." & vbCRLF & _
> > > > "A new lease has been placed in the following location:
> > > > S:\ShielahS\IN\." & vbCRLF & vbCRLF & _
> > > > "File name:" & (Mid(objLatestEvent.TargetInstance.PartComponent,49))
> > > >
> > > > objMail.Send
> > > >
> > > > Set objMail = Nothing
> > > > End Sub
> > > >
> > > >
> > > >
> > > >

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen