Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 1st, 2012, 05:19 AM
kadara kadara is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 1 kadara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 16 sec
Reputation Power: 0
VBScript File monitor

Hi,
I would like to monitor a text file. Currently I use the following vbscript code:

Code:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
'    ("SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE " _
'        & "TargetInstance ISA 'CIM_DataFile' and " _
'            & "TargetInstance.Name='U:\\Programming\\Hydra\\Label\\LogFile01.txt'")

strPnrPath01 = "U:\\Programming\\Test05\\Test01.txt"

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("SELECT * FROM __InstanceOperationEvent WITHIN 20 WHERE " _
        & "TargetInstance ISA 'CIM_DataFile' and " _
            & "TargetInstance.Name='" & strPnrPath01 & "'")


Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
    'WScript.Echo "File: " & objLatestEvent.TargetInstance.Name
    'WScript.Echo "New size: " & objLatestEvent.TargetInstance.FileSize
    'Wscript.Echo "Old size: " & objLatestEvent.PreviousInstance.FileSize
    
    	Select Case objLatestEvent.Path_.Class
			'Case "__InstanceCreationEvent"
			'	WScript.Echo Now & vbTab & MyFile & " was created" & vbCrlf      
			'Case "__InstanceDeletionEvent"     
			'	WScript.Echo Now & vbTab & MyFile & " was deleted" & vbCrLf
			Case "__InstanceModificationEvent"
				If objLatestEvent.TargetInstance.LastModified <> objLatestEvent.PreviousInstance.LastModified Then
						'WScript.Echo Now & vbTab & MyFile & " was modified" & vbCrLf
						MsgBox "File was modified."
						
				End If
		End Select

    
Loop

Set objWMIService = Nothing
Set colMonitoredEvents = Nothing
Set objLatestEvent = Nothing


The text file is modified 5 or 6 times in a minute or two, and I would like to be notified only after the last file modification (the attached code notifies me after the first modification). How could I do that? (The text file modification procedure: the file is being changed many times - about 5 or 6 times - in a minute, after that minute the file is unchanged in the next several hours).

Reply With Quote
  #2  
Old November 1st, 2012, 06:26 PM
couttsj couttsj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 165 couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 16 h 44 m 37 sec
Reputation Power: 43
The "Timer" function returns the number of seconds since midnight. After the first detection, you would put your script into a loop and check when the desired time has expired. InVB6 I would normally use a DoEvents function within that loop, but I don't believe that it works in VBScript, and I also believe that it is not necessary because VBScript is a Pseudo language. Make sure to account for a change that might occur at midnight.

J.A. Coutts

Reply With Quote
  #3  
Old November 30th, 2012, 04:17 AM
toddyaww toddyaww is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 8 toddyaww Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 h 28 m 48 sec
Reputation Power: 0
File monitor

Which S/W is create with the help of Visual basic then this s/w setting change like size change according to used monitor.
Comments on this post
medialint disagrees: What the .... ?????

Reply With Quote
  #4  
Old January 1st, 2013, 05:47 AM
Incidentals Incidentals is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 89 Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Day 4 h 23 m 19 sec
Reputation Power: 156
why do you monitor file

what is the size and contents of the file

it may be just as easy to read it

here to help

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > File monitor

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap