Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Should Be Easy

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,56832
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Should Be Easy
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Should Be Easy - 2/19/2008 3:37:21 AM   
  scrambled2k3

 

Posts: 4
Score: 0
Joined: 2/19/2008
Status: offline
I'm new to VB scripting and this is what i'm trying to do. I'm want to create a script that monitors a single folder on a PC for files that are added to it. Whenever a file that ends in ".idx" is inserted into the folder, I want it to execute a ".exe" file. For the time being I'm just trying to get it to echo the fact that a file that ends in '.idx' was inserted. Here is my code thus far:

*************************************************************
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=""d:\\\\scripts""'")

Set colFiles = objWMIService.ExecQuery _
("Select * from 'Win32_Directory.Name=""d:\\\\scripts""' where FileName Like '%.idx'" )
For Each objFile in colFiles
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo objLatestEvent.TargetInstance.PartComponent
Loop
*************************************************************

Any help will be greatly appreciated...Thanks!
 
 
Post #: 1
 
 RE: Should Be Easy - 2/19/2008 5:01:01 AM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I think you might be using the wrong class....you might look at using CIM_DataFile and if you are going to be using the instancecreationevent then you will not be using the set colFiles = xxxxx or the For Each...Next

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to scrambled2k3)
 
 
Post #: 2
 
 RE: Should Be Easy - 2/19/2008 5:24:26 AM   
  scrambled2k3

 

Posts: 4
Score: 0
Joined: 2/19/2008
Status: offline
Thanks for the reply. Like I said I'm new to this. I tried changing it to what's below, but it gives me an "SWbemServicesEx: Not Found" error. Am I atleast on the right track? What can I do differently to make this work?

**********************************************************************
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=""d:\\\\scripts""' and " _
& "FileName Like '%.idx'")

Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo objLatestEvent.TargetInstance.PartComponent
Loop

*********************************************************************

Thanks!!!

< Message edited by scrambled2k3 -- 2/19/2008 5:29:50 AM >

(in reply to scrambled2k3)
 
 
Post #: 3
 
 RE: Should Be Easy - 2/19/2008 5:41:41 AM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
It should be more like this....


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to scrambled2k3)
 
 
Post #: 4
 
 RE: Should Be Easy - 2/19/2008 6:11:25 AM   
  scrambled2k3

 

Posts: 4
Score: 0
Joined: 2/19/2008
Status: offline
I have no clue why, but the code you just gave me is returning a "compilation error: Invalid Character".

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: Should Be Easy - 2/19/2008 6:21:45 AM   
  ebgreen


Posts: 4971
Score: 31
Joined: 7/12/2005
Status: online
On what line?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to scrambled2k3)
 
 
Post #: 6
 
 RE: Should Be Easy - 2/19/2008 6:27:06 AM   
  scrambled2k3

 

Posts: 4
Score: 0
Joined: 2/19/2008
Status: offline
(12, 1)

UPDATE: Ignore that....I found it! Thanks!!

< Message edited by scrambled2k3 -- 2/19/2008 6:29:51 AM >

(in reply to ebgreen)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Should Be Easy Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts