ryancooper Posted June 11, 2005 Share Posted June 11, 2005 (edited) Hello, I have a simple VBS script that lets me know when data has been added to a folder. This is so when a person adds data i do not have to keep looking every hour. THe script will announce to me that data has arrived.What i want to do is have it check several folders The script below checks one folder fine but i can not figure out how to have it check multiple folders. Right now i have 3 scripts i have to start on every computer. It would be easier to just have one. . . Can someone help? ALSO is it possable to have the alert pop to the front of the screen. This will help grab attention.Thanks a Million strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2")Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 300 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name=""f:\\\\dsr\\\\Pete""'")Do Set objLatestEvent = colMonitoredEvents.NextEvent Wscript.Echo "New DSR Data Availabel for Pete please contact Phil or Ryan. . . Thank You. Have a nice day!"LoopEach folder is located in hte f:\dsr directory. . . Thanks! Edited June 11, 2005 by ryancooper Link to comment Share on other sites More sharing options...
gunsmokingman Posted June 11, 2005 Share Posted June 11, 2005 Try This I Dont Know If It What You WantI have added a Inputbox for the User To Selection''''Script1Dim StrComputerDim Act : Set Act = CreateObject("Wscript.Shell")strComputer = "." function Question Z1 = Inputbox("If This Is Pete Please Type In 1" & vbcrlf &_ "If This Is Phil Please Type In 2" & vbcrlf &_ "If This Is Ryan Please Type In 3" & vbcrlf &_ "User Pleas Make A Selection", "User Selection",, 5900, 4700) If Z1 = "" Then Z2 = Act.popup ("Error No user Number Was Detected" & Vbcrlf & "Did You Want to Quit This" & Vbcrlf &_ "Yes To Continue With Script" & Vbcrlf & "No To Quit The Script", 5,"User Selected Nothing", 4 + 32) If Z2 = Vbyes Then Call Question Else End If If Z2 = Vbno Then UserQuit End If End If If Z1 = 1 Then call Pete End If If Z1 = 2 Then call Phil End If If Z1 = 3 Then call Ryan End If End Function Function Pete Act.popup "Hello Pete Please Wait" & Vbcrlf & "For The Script To complete", 3,"Processing", 0 + 32Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2")Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 300 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name=""f:\\\\dsr\\\\Pete""'")Do Set objLatestEvent = colMonitoredEvents.NextEvent Loop Act.popup "New DSR Data Availabel" & Vbcrlf &_ "For Pete please contact Phil or Ryan." & Vbcrlf &_ "Thank You. Have a nice day!", 5, "Script Completed",0 + 32 End Function Function Phil''''Script2 Act.popup "Hello Phil Please Wait" & Vbcrlf & "For The Script To complete", 3,"Processing", 0 + 32Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2")Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 300 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name=""f:\\\\dsr\\\\Phil""'")Do Set objLatestEvent = colMonitoredEvents.NextEventLoop Act.popup "New DSR Data Availabel" & Vbcrlf &_ "For Phil please contact Pete or Ryan." & Vbcrlf &_ "Thank You. Have a nice day!", 5, "Script Completed",0 + 32 End Function Function ryan ''''Script3 Act.popup "Hello Ryan Please Wait" & Vbcrlf & "For The Script To complete", 3,"Processing", 0 + 32Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2")Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 300 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name=""f:\\\\dsr\\\\Ryan""'")Do Set objLatestEvent = colMonitoredEvents.NextEventLoop Act.popup "New DSR Data Availabel" & Vbcrlf &_ "For Ryan please contact Phil or Pete." & Vbcrlf &_ "Thank You. Have a nice day!", 5, "Script Completed",0 + 32 End Function Function UserQuit Act.popup "User Selected To Quit", 4, "User Quit", 0 + 32 wscript.quit End Function Question Link to comment Share on other sites More sharing options...
ryancooper Posted June 11, 2005 Author Share Posted June 11, 2005 (edited) WOW looks like you puta lot of work into that and I want to thank you. I think you did more thant we need.LEt me explaine a little better. I have 5 salesmen on the road. When they get a order thy send it in to a folder on the server. Once the file is on the server we know to go ahead and process the order.What I want to do is have the script running on all of our computers so when a file is placed in f:\dsr\pete or f:\dsr\rob or f:\dsr\mike or f:\dsr\deniceit will pop up a alert tellimg me data is available. .. The script above works for one folder but I have to run four scripts (one for each folder) to get it to monitor all of them.Thanks for any more help you can give me!Ryan Edited June 11, 2005 by ryancooper Link to comment Share on other sites More sharing options...
ryancooper Posted June 11, 2005 Author Share Posted June 11, 2005 (edited) Here is some of the things i have tried that did not work strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2")Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 300 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name=""c:\\\\dsr\Rob""'")Do Set objLatestEvent = colMonitoredEvents.NextEvent Wscript.Echo "New DSR Data Availabel for Rob please contact Phil or Ryan. . . Thank You. Have a nice day!"Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 300 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name=""c:\\\\dsr\Pete""'")Do Set objLatestEvent = colMonitoredEvents.NextEvent Wscript.Echo "New DSR Data Availabel for Pete please contact Phil or Ryan. . . Thank You. Have a nice day!"LoopstrComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2")Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 300 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name=""c:\\\\dsr\Pete""'") & "'Win32_Directory.Name=""c:\\\\dsr\Rob""'")Do Set objLatestEvent = colMonitoredEvents.NextEvent Wscript.Echo "New DSR Data Availabel please contact Phil or Ryan. . . Thank You. Have a nice day!"LoopstrComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2")Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 300 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name=""c:\\\\dsr\Pete""'")Do Set objLatestEvent = colMonitoredEvents.NextEvent Wscript.Echo "New DSR Data Availabel for Pete please contact Phil or Ryan. . . Thank You. Have a nice day!" & "'Win32_Directory.Name=""c:\\\\dsr\Rob""'")Do Set objLatestEvent = colMonitoredEvents.NextEvent Wscript.Echo "New DSR Data Availabel for Rob please contact Phil or Ryan. . . Thank You. Have a nice day!"LoopI could go on for a while but none of them work. . . Edited June 11, 2005 by ryancooper Link to comment Share on other sites More sharing options...
gunsmokingman Posted June 11, 2005 Share Posted June 11, 2005 (edited) That script does a loop for Pete, Phil, Ryan They Have To Input The Right Number For Each User As To Location YouHave To Make Sure They Are Correct As I Used Only The First Post As My Template To Make My Script.There Are 4 Function That The Input Box ControlsA Error Or Cancel FunctionAnd A Function For Each Of The Above Listed Users.& "'Win32_Directory.Name=""f:\\\\dsr\\\\Pete""'")& "'Win32_Directory.Name=""f:\\\\dsr\\\\Phil""'")& "'Win32_Directory.Name=""f:\\\\dsr\\\\Ryan""'") Edited June 11, 2005 by gunsmokingman Link to comment Share on other sites More sharing options...
Fredledingue Posted June 11, 2005 Share Posted June 11, 2005 What's so difficult, just set an array of folder location, then loop through the array until the last one. Link to comment Share on other sites More sharing options...
ryancooper Posted June 12, 2005 Author Share Posted June 12, 2005 What's so difficult, just set an array of folder location, then loop through the array until the last one.<{POST_SNAPBACK}>sounds like you understand what i would like to do. BUT How do i do that? Link to comment Share on other sites More sharing options...
ryancooper Posted June 12, 2005 Author Share Posted June 12, 2005 That script does a loop for Pete, Phil, Ryan They Have To Input The Right Number For Each User As To Location YouHave To Make Sure They Are Correct As I Used Only The First Post As My Template To Make My Script.There Are 4 Function That The Input Box ControlsA Error Or Cancel FunctionAnd A Function For Each Of The Above Listed Users.& "'Win32_Directory.Name=""f:\\\\dsr\\\\Pete""'")& "'Win32_Directory.Name=""f:\\\\dsr\\\\Phil""'")& "'Win32_Directory.Name=""f:\\\\dsr\\\\Ryan""'")<{POST_SNAPBACK}>I tryed adding your input to the code and gor a error: (changed to c: for testing at home)strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2")Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 3 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _& "'Win32_Directory.Name=""c:\\\\dsr""'")& "'Win32_Directory.Name=""c:\\\\dsr\\\\Phil""'")& "'Win32_Directory.Name=""c:\\\\dsr\\\\Ryan""'")Do Set objLatestEvent = colMonitoredEvents.NextEventSet WshShell = Wscript.CreateObject("Wscript.Shell")WshShell.Popup "Click me Quick!",, "My Popup Dialogue box"Loop Link to comment Share on other sites More sharing options...
ryancooper Posted June 12, 2005 Author Share Posted June 12, 2005 That script does a loop for Pete, Phil, Ryan They Have To Input The Right Number For Each User As To Location YouHave To Make Sure They Are Correct As I Used Only The First Post As My Template To Make My Script.There Are 4 Function That The Input Box ControlsA Error Or Cancel FunctionAnd A Function For Each Of The Above Listed Users.& "'Win32_Directory.Name=""f:\\\\dsr\\\\Pete""'")& "'Win32_Directory.Name=""f:\\\\dsr\\\\Phil""'")& "'Win32_Directory.Name=""f:\\\\dsr\\\\Ryan""'")<{POST_SNAPBACK}>I understand what you were doing. . . What i need is the same 4 folders monitored on all my computers. Reguardless of who is at the computer. ...Make sence? One script monitores 4 folders for data then returns a message when any of those folders gets changed. . .Thanks!! Link to comment Share on other sites More sharing options...
Fredledingue Posted June 13, 2005 Share Posted June 13, 2005 This is how to do an array:'---------------- Array set up---------------------------Dim x(4)x(0)= "somelocation1"x(1)= "somelocation2"x(2)= "somelocation3"x(3)= "somelocation4"x(4)= "somelocation5"'---------------Loop through the array --------------For i = 0 To 4 Msgbox x(i)Next Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now