.VBS script help (simple?)

Discussion in 'Software' started by ryancooper, Jun 12, 2005.

  1. ryancooper

    ryancooper Private E-2

    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 it will let me know and 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 to run three scripts (one for each folder) and I have more folders coming soon. Is there a way to combine more than one folder to the script below.

    As you can see it is looking in c:\\\\dsr

    I also need it to look in c:\\\\dsr\\\\Pete - c:\\\\dsr\\\\Rob And so on.


    Code:
    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""'")
    Do
       Set objLatestEvent = colMonitoredEvents.NextEvent
    Set WshShell = Wscript.CreateObject("Wscript.Shell")
    strAgentName = "Peedy"
    strAgentPath = "C:\Windows\Msagent\Chars\" & strAgentName & ".acs"
    Set objAgent = CreateObject("Agent.Control.2")
    
    objAgent.Connected = TRUE
    objAgent.Characters.Load strAgentName, strAgentPath
    Set objCharacter = objAgent.Characters.Character(strAgentName)
    
    objCharacter.Show
    
    WshShell.Popup "New Data available from the Laptop Salesmen." & vbcrlf &_
    "Please contact phil or ryan.",, "Service Alert!","4096"
    
    objCharacter.Play "GetAttention"
    objCharacter.MoveTo 500,400
    objCharacter.Play "Announce"
    objCharacter.Speak "New Data Is Ready For Conversion"
    objCharacter.Speak "Please tell Phil or Ryan... Goodbye."
    objCharacter.Hide
    
    Loop 
    Can someone help?
    Thanks a Million
     
  2. Kodo

    Kodo SNATCHSQUATCH

    you should skip this and use .NET and its' filesystemchecker object which is much more efficient and will require less headache's.
     
  3. ryancooper

    ryancooper Private E-2


    THank you for pointing that out but that doesn;t really help my problem. I have no idea what i am doing with this vbs and have never even looked at .net.

    :confused:
     
  4. Kodo

    Kodo SNATCHSQUATCH

    Well, that's why I was suggesting .NET over VB Scripting. If you know neither, then the more advanced and efficient would be the wiser solution to choose to learn.

    The filesystemwatcher in .NET has events that will fire when files are created, modifed etc. Ultimatlely, you are wasting your time with older technology that will be more difficult to manage and produce the solution you require compared to a .NET solution.

    Additionally , the FSW can watch sub-folders; or you can make an app with multiple FSW's in one app as opposed to three separate scripts running.

    The only requirements are that the system you use it on must be win2000 or higher , .NET framework installed and have NTFS file system.

    You can even load the ms agents like you're trying to do with relative ease.


    But if you really want to use VBScript you can try slapping a few paths into an array and looping your check replacing the path to check with an array element on each loop.

    Dim PathArr(3)

    PathArr(0)="c:\path1"
    PathArr(1)="c:\path2"
    PathArr(2)="c:\path3"
    PathArr(3)="c:\path4"
    'arrays are zero based


    then do something like

    for i=0 to ubound(PathArr,0)

    'run your code here
    'I'm abbreviating for simplicities sake

    Win32_Directory.Name=PathArr(i)

    next

    if you decide to go .NET, let me know.. I can get point you too all you need to know to do your stuff.
     
  5. ryancooper

    ryancooper Private E-2

    Thank you for your help and offer. . . As i know nothing about either and all i really need is this one script i am going to try to get it to work. I have 90% done so all i need is the last part. unless i can get someone to write it for me :D ($10 paypal?)

    Thanks!!
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds