Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Monitor content of a specific file every 2 seconds

Reply
 
Old 02-05-2009   #1 (permalink)
Leon


 
 

Monitor content of a specific file every 2 seconds

Hi Group

Is there a way to manipulate Windows standard scheduler to run a
script every 2' second?

The script is reading a file only containing a "flag" 1 or 0.

Cheers

My System SpecsSystem Spec
Old 02-05-2009   #2 (permalink)
Dirk Stegemann


 
 

Re: Monitor content of a specific file every 2 seconds

Hi,
Quote:

> Is there a way to manipulate Windows standard scheduler to run a
> script every 2' second?
>
> The script is reading a file only containing a "flag" 1 or 0.

i think it should be even easier to take one script sleeping for two secconds..

wscript.sleep 2000

regards Dirk

My System SpecsSystem Spec
Old 02-05-2009   #3 (permalink)
Pegasus \(MVP\)


 
 

Re: Monitor content of a specific file every 2 seconds


"Leon" <kim.zethsen@xxxxxx> wrote in message
news:62eaa25a-1a56-4a87-88d4-0b963e8ebe41@xxxxxx
Quote:

> Hi Group
>
> Is there a way to manipulate Windows standard scheduler to run a
> script every 2' second?
>
> The script is reading a file only containing a "flag" 1 or 0.
>
> Cheers
I don't think you can modify the Task Scheduler to do this (and the
overheads in getting it to run a task once every 2 seconds are possibly
prohibitive), but you could use this method:
How Can I Check Every 30 Minutes to See If a File Has Been Modified?

http://www.microsoft.com/technet/scr...7/hey0723.mspx


My System SpecsSystem Spec
Old 02-05-2009   #4 (permalink)
Leon


 
 

Re: Monitor content of a specific file every 2 seconds

On 5 Feb., 22:42, "Dirk Stegemann" <dsgra...@xxxxxx> wrote:
Quote:

> Hi,
>
Quote:

> > Is there a way to manipulate Windows standard scheduler to run a
> > script every 2' second?
>
Quote:

> > The script is reading a file only containing a "flag" 1 or 0.
>
> i think it should be even easier to take one script sleeping for two secconds..
>
> wscript.sleep 2000
>
> regards Dirk
Hi Dirk

I have thought about monitoring like the code hereunder (I really am
new in this) which are just monitoring new files...
But you are tight that sounds much more simple.

************************************************************************************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 0.1 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""c:\\\\scripts""'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo objLatestEvent.TargetInstance.PartComponent
Loop
************************************************************************************

Thanks Dirk
:-)

My System SpecsSystem Spec
Old 02-05-2009   #5 (permalink)
Todd Vargo


 
 

Re: Monitor content of a specific file every 2 seconds

Leon wrote:
Quote:

> Hi Group
>
> Is there a way to manipulate Windows standard scheduler to run a
> script every 2' second?
>
> The script is reading a file only containing a "flag" 1 or 0.
Why not just run the script in an endless loop?
What exactly does the script do besides read a flag file?

More information is essentially necessary.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)


My System SpecsSystem Spec
Old 02-05-2009   #6 (permalink)
Leon


 
 

Re: Monitor content of a specific file every 2 seconds

On 5 Feb., 22:44, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> "Leon" <kim.zeth...@xxxxxx> wrote in message
>
> news:62eaa25a-1a56-4a87-88d4-0b963e8ebe41@xxxxxx
>
Quote:

> > Hi Group
>
Quote:

> > Is there a way to manipulate Windows standard scheduler to run a
> > script every 2' second?
>
Quote:

> > The script is reading a file only containing a "flag" 1 or 0.
>
Quote:

> > Cheers
>
> I don't think you can modify the Task Scheduler to do this (and the
> overheads in getting it to run a task once every 2 seconds are possibly
> prohibitive), but you could use this method:
> How Can I Check Every 30 Minutes to See If a File Has Been Modified?
>
> http://www.microsoft.com/technet/scr.../qanda/jul07/h...
Hi Pegasus

No - the thing is - that another system (online scada) is raising a
flag on a specifik event and writes to the file whereafter I have to
alert some users at once on that event

Cheers
My System SpecsSystem Spec
Old 02-05-2009   #7 (permalink)
Leon


 
 

Re: Monitor content of a specific file every 2 seconds

On 5 Feb., 22:51, "Todd Vargo" <tlva...@xxxxxx> wrote:
Quote:

> Leon wrote:
Quote:

> > Hi Group
>
Quote:

> > Is there a way to manipulate Windows standard scheduler to run a
> > script every 2' second?
>
Quote:

> > The script is reading a file only containing a "flag" 1 or 0.
>
> Why not just run the script in an endless loop?
> What exactly does the script do besides read a flag file?
>
> More information is essentially necessary.
>
> --
> Todd Vargo
> (Post questions to group only. Remove "z" to email personal messages)
Essentially you're right.
I just want to check if the file have been modified an if so read the
content. Thats bassically it.
Can be done as you mentioned.

I also want to name the proces so I can se in it windows task manager
under processes.
Not only wscript.exe - but something like "monitoring_folder" - just
so I can see it and so that a another vbs script (from standard
scheduler every minut) can monitor that this is running.
My System SpecsSystem Spec
Old 02-05-2009   #8 (permalink)
Al Dunbar


 
 

Re: Monitor content of a specific file every 2 seconds


"Leon" <kim.zethsen@xxxxxx> wrote in message
news:813a1495-8ac2-42f2-ba06-bab4150322f0@xxxxxx
Quote:

> On 5 Feb., 22:51, "Todd Vargo" <tlva...@xxxxxx> wrote:
Quote:

>> Leon wrote:
Quote:

>> > Hi Group
>>
Quote:

>> > Is there a way to manipulate Windows standard scheduler to run a
>> > script every 2' second?
>>
Quote:

>> > The script is reading a file only containing a "flag" 1 or 0.
>>
>> Why not just run the script in an endless loop?
>> What exactly does the script do besides read a flag file?
>>
>> More information is essentially necessary.
>>
>> --
>> Todd Vargo
>> (Post questions to group only. Remove "z" to email personal messages)
>
> Essentially you're right.
> I just want to check if the file have been modified an if so read the
> content. Thats bassically it.
No it isn't. Elsethread you said the script needs to "alert some users" as
soon as the flag file is changed by "another system (online scada)". How
many users, and how do you need to alert them?

/Al
Quote:

> Can be done as you mentioned.
>
> I also want to name the proces so I can se in it windows task manager
> under processes.
> Not only wscript.exe - but something like "monitoring_folder" - just
> so I can see it and so that a another vbs script (from standard
> scheduler every minut) can monitor that this is running.

My System SpecsSystem Spec
Old 02-05-2009   #9 (permalink)
Ruediger Roesler


 
 

Re: Monitor content of a specific file every 2 seconds

Leon <kim.zethsen@xxxxxx> typed:
Quote:

> I just want to check if the file have been modified an if so read the
> content. Thats bassically it.
> Can be done as you mentioned.
Try this one (provide the path to the file as the first argument):

' MoniFile.vbs
Option Explicit

Const Archive = 32, ForReading = 1
Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")

If WScript.Arguments.Count > 0 Then
Do While fso.FileExists(WScript.Arguments(0))
With fso.GetFile(WScript.Arguments(0))
If .Attributes And Archive Then
With .OpenAsTextStream(ForReading, vbUseDefault)
WScript.Echo .ReadAll
.Close
End With
.Attributes = .Attributes Xor Archive
End If
End With
WScript.Sleep 2000
Loop
End If
Quote:

> I also want to name the proces so I can se in it windows task manager
> under processes.
> Not only wscript.exe - but something like "monitoring_folder" - just
> so I can see it and so that a another vbs script (from standard
> scheduler every minut) can monitor that this is running.
Don't know, sorry.

--
ЯR

My System SpecsSystem Spec
Old 02-06-2009   #10 (permalink)
Leon


 
 

Re: Monitor content of a specific file every 2 seconds

On 6 Feb., 02:00, "Ruediger Roesler"
<administra...@xxxxxx> wrote:
Quote:

> Leon <kim.zeth...@xxxxxx> typed:
>
Quote:

> > I just want to check if the file have been modified an if so read the
> > content. Thats bassically it.
> > Can be done as you mentioned.
>
> Try this one (provide the path to the file as the first argument):
>
> ' MoniFile.vbs
> Option Explicit
>
> Const Archive = 32, ForReading = 1
> Dim fso
>
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> If WScript.Arguments.Count > 0 Then
> Â* Â* Do While fso.FileExists(WScript.Arguments(0))
> Â* Â* Â* Â* With fso.GetFile(WScript.Arguments(0))
> Â* Â* Â* Â* Â* Â* If .Attributes And Archive Then
> Â* Â* Â* Â* Â* Â* Â* Â* With .OpenAsTextStream(ForReading, vbUseDefault)
> Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* WScript.Echo .ReadAll
> Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* .Close
> Â* Â* Â* Â* Â* Â* Â* Â* End With
> Â* Â* Â* Â* Â* Â* Â* Â* .Attributes = .Attributes Xor Archive
> Â* Â* Â* Â* Â* Â* End If
> Â* Â* Â* Â* End With
> Â* Â* Â* Â* WScript.Sleep 2000
> Â* Â* Loop
> End If
>
Quote:

> > I also want to name the proces so I can se in it windows task manager
> > under processes.
> > Not only wscript.exe - but something like "monitoring_folder" - just
> > so I can see it and so that a another vbs script (from standard
> > scheduler every minut) can monitor that this is running.
>
> Don't know, sorry.
>
> --
> ЯR
OK .-) Thank you for your answers and taking time.
Have a nice weekend

Leon
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Set specific apps to work on secondary monitor? General Discussion
Internet Explorer Content Advisor - Allow or Block Specific Websites Tutorials
Set-Content not updating file after get-content and forEach-Object PowerShell
About adding content to the same file using "add-content" PowerShell
Weirdness with get-content | replace | set-content - file content is deleted!! PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46