|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Unparsable QueryThis 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 = "ITSupp***@kennedyusa.com" 'This is the address the email will appear from Const STRTo="car***@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 I think you can replace
strComputer = "." with strComputer = "RemoteComputerName" and then use local path: & "'Win32_Directory.Name=""C:\\\\SomePath""'" -- Show quoteHide quoteurkec "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 = "ITSupp***@kennedyusa.com" 'This is the address the email > will appear from > Const STRTo="car***@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 > > > > 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! Show quoteHide quote "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 = "ITSupp***@kennedyusa.com" 'This is the address the email > > will appear from > > Const STRTo="car***@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 > > > > > > > > I think you need to include all four backslashes:
& "'Win32_Directory.Name=""c:\\\\SomePath\\\\SubDir""'") -- Show quoteHide quoteurkec "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 = "ITSupp***@kennedyusa.com" 'This is the address the email > > > will appear from > > > Const STRTo="car***@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 > > > > > > > > > > > > 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! Show quoteHide quote "urkec" wrote: > 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 = "ITSupp***@kennedyusa.com" 'This is the address the email > > > > will appear from > > > > Const STRTo="car***@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 > > > > > > > > > > > > > > > >
Remove all members in local Power User Group
Delete Parent registry key based on subkey data fire script in remote servers logevent command bombs scheduled task Move files WScript error REMOTE LOGIN & Data Extraction Mouse equivalent for sendkeys Remove members from local administrators group Scripting change to the Power Management Schedule Task Options |
|||||||||||||||||||||||