memory resident program 
Author Message
 memory resident program

Hi there,

is there a way in VBScripting or another scripting language to make a
program memory resident?

thanks,

Rob



Tue, 31 Aug 2004 16:19:44 GMT  
 memory resident program

Quote:

> is there a way in vbscripting or another scripting language to make a
> program memory resident?

Hi

Not really, but what are you trying to do in more detail?

--
torgeir



Tue, 31 Aug 2004 16:40:18 GMT  
 memory resident program

Quote:
>>and what do you mean when you say "memory resident"?


: Hi there,
:
: is there a way in vbscripting or another scripting language to make a
: program memory resident?
:
: thanks,
:
: Rob
:
:


Tue, 31 Aug 2004 20:11:57 GMT  
 memory resident program
Okay,

what i try to do is the following:
If a file is saved in a certain directory i want to move that file to
another location the minute it is placed there. So i need a program that
keeps checking the directory on the present of files without keeping a large
amount of memory. So i thought that i needed a program that was in memory
all the time.

It can't use a great deal of memory though because we run on Terminal
Service (win2k). It will slow things down to much.
So, got any ideas?

Rob

Quote:

> > is there a way in vbscripting or another scripting language to make a
> > program memory resident?

> Hi

> Not really, but what are you trying to do in more detail?

> --
> torgeir



Tue, 31 Aug 2004 20:32:32 GMT  
 memory resident program

Quote:

> Okay,

> what i try to do is the following:
> If a file is saved in a certain directory i want to move that file to
> another location the minute it is placed there. So i need a program that
> keeps checking the directory on the present of files without keeping a large
> amount of memory. So i thought that i needed a program that was in memory
> all the time.

> It can't use a great deal of memory though because we run on Terminal
> Service (win2k). It will slow things down to much.
> So, got any ideas?

Hi

Running this script costs me 2.5 MB RAM:

Set oFSO = CreateObject("Scripting.FileSystemObject")

Do
  If oFSO.FileExists("c:\foo") Then
    WScript.Echo "File found!"
    ' copy it
    ' then delete it
  End If
  WScript.Sleep 200
Loop While True

It will loop forever (or until you manually "kill" cscript.exe or wscript.exe in
Task Manager")

--
torgeir



Tue, 31 Aug 2004 23:13:46 GMT  
 memory resident program
You can also write a script that uses WMI to register for a file system change notification event on a folder.  I've seen examples but don't recall enough of the details to go out searching for one ;-)...

In .NET it's relatively easy to do with the FileSystemWatcher class in the System.IO namespace.

FileSystemWatcher Class
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemIOFileS...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:


> > Okay,

> > what i try to do is the following:
> > If a file is saved in a certain directory i want to move that file to
> > another location the minute it is placed there. So i need a program that
> > keeps checking the directory on the present of files without keeping a large
> > amount of memory. So i thought that i needed a program that was in memory
> > all the time.

> > It can't use a great deal of memory though because we run on Terminal
> > Service (win2k). It will slow things down to much.
> > So, got any ideas?

> Hi

> Running this script costs me 2.5 MB RAM:

> Set oFSO = CreateObject("Scripting.FileSystemObject")

> Do
>   If oFSO.FileExists("c:\foo") Then
>     WScript.Echo "File found!"
>     ' copy it
>     ' then delete it
>   End If
>   WScript.Sleep 200
> Loop While True

> It will loop forever (or until you manually "kill" cscript.exe or wscript.exe in
> Task Manager")

> --
> torgeir



Wed, 01 Sep 2004 09:38:45 GMT  
 memory resident program

Quote:

> You can also write a script that uses WMI to register for a file system change notification event on a folder.  I've seen examples but don't recall enough of the details to go out searching for one ;-)...

Adding WMI into the "soup" isn't going to save the OP any memory, is it ;-)

I didn't find any complete example, but I built one:

      ---------------------  Script start ---------------------
' Script that will detect all new files in c:\test with a optmized query.

strQuery = "Select * From __InstanceCreationEvent Within 2 " _
           & "Where TargetInstance ISA 'cim_DirectoryContainsFile' " _
           & "AND TargetInstance.GroupComponent=" _
           & "'Win32_Directory.Name=""c:\\\\test""'"

  ' for remote, define a sComputerName variable and exchange the line
  ' above with this two ( in addition to the changes in the
  ' "GetObject("winmgmts:")" statement as well):
  ' & "AND TargetInstance.GroupComponent='\\\\" & sComputerName _
  ' & "\\root\\cimv2:Win32_Directory.Name=""c:\\\\test""'"

Set oEvents = GetObject("winmgmts:").ExecNotificationQuery (strQuery)

WScript.Echo "Waiting for events..."

' now wait for events ...
Do While True             ' loop indefinitely
  Set oNTEvent = oEvents.NextEvent.TargetInstance ' retrieve event
  WScript.Echo "Data: " & oNTEvent.PartComponent
Loop

' Will give you an output on this format for each new file:
' \\<computername>\root\cimv2:CIM_DataFile.Name="c:\\test\\New.txt"

      ---------------------  Script end ---------------------

To "kill" this script in a nice way, I recommend this procedure:

From a command prompt, run:
1)
net stop "Windows Management Instrumentation"
2)
net start "Windows Management Instrumentation"

Why should you do this, and not just kill cscript.exe/wscript.exe from the task list, you might ask?

Well, you could, but my experience is that WMI in that case a lot of times gets "crazy" and starts eating all my memory until my computer "jumps off a cliff".

--
torgeir



Thu, 02 Sep 2004 08:16:00 GMT  
 memory resident program
my solution script on the basis of your script with async notification

'start script ------------
username=""
password=""
comp_name=""

set locator = CreateObject("Wbemscripting.SWbemLocator")
locator.security_.impersonationLevel = 3 'impersonate
set connector =
locator.ConnectServer(Comp_Name,"root/cimv2",username,password)

wql = "Select * From __InstanceCreationEvent Within 2 " _
           & "Where TargetInstance ISA 'cim_DirectoryContainsFile' " _
           & "AND TargetInstance.GroupComponent=" _
           & "'Win32_Directory.Name=""c:\\\\test""'"

set sink = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
connector.ExecNotificationQueryAsync sink, wql
wscript.echo "wait for events"
sink.Cancel()

'--------------Event Function ----------

Sub SINK_OnObjectReady(objObject, objAsyncContext)
WScript.Echo "File Created" & objObject.targetinstance.Partcomponent
set o = connector.get(objObject.targetinstance.Partcomponent)
wscript.echo o.name
End Sub

' end script -------------------------

Ingo


Quote:

> > You can also write a script that uses WMI to register for a file system

change notification event on a folder.  I've seen examples but don't recall
enough of the details to go out searching for one ;-)...
Quote:

> Adding WMI into the "soup" isn't going to save the OP any memory, is it
;-)

> I didn't find any complete example, but I built one:

>       ---------------------  Script start ---------------------
> ' Script that will detect all new files in c:\test with a optmized query.

> strQuery = "Select * From __InstanceCreationEvent Within 2 " _
>            & "Where TargetInstance ISA 'cim_DirectoryContainsFile' " _
>            & "AND TargetInstance.GroupComponent=" _
>            & "'Win32_Directory.Name=""c:\\\\test""'"

>   ' for remote, define a sComputerName variable and exchange the line
>   ' above with this two ( in addition to the changes in the
>   ' "GetObject("winmgmts:")" statement as well):
>   ' & "AND TargetInstance.GroupComponent='\\\\" & sComputerName _
>   ' & "\\root\\cimv2:Win32_Directory.Name=""c:\\\\test""'"

> Set oEvents = GetObject("winmgmts:").ExecNotificationQuery (strQuery)

> WScript.Echo "Waiting for events..."

> ' now wait for events ...
> Do While True             ' loop indefinitely
>   Set oNTEvent = oEvents.NextEvent.TargetInstance ' retrieve event
>   WScript.Echo "Data: " & oNTEvent.PartComponent
> Loop

> ' Will give you an output on this format for each new file:
> ' \\<computername>\root\cimv2:CIM_DataFile.Name="c:\\test\\New.txt"

>       ---------------------  Script end ---------------------

> To "kill" this script in a nice way, I recommend this procedure:

> From a command prompt, run:
> 1)
> net stop "Windows Management Instrumentation"
> 2)
> net start "Windows Management Instrumentation"

> Why should you do this, and not just kill cscript.exe/wscript.exe from the

task list, you might ask?
Quote:

> Well, you could, but my experience is that WMI in that case a lot of times

gets "crazy" and starts eating all my memory until my computer "jumps off a
cliff".

- Show quoted text -

Quote:

> --
> torgeir



Fri, 03 Sep 2004 21:04:54 GMT  
 memory resident program
Just for fun, here's an HTA version...

<html>
<title>WatchFolder</title>
<hta:application
  id="WatchFolder"        applicationname="WatchFolderHTA"  
  singleinstance="yes"    windowstate="minimize"    
  caption="yes"           showintaskbar="yes"
  sysmenu="yes"           scroll="yes"
/>

<object id="mysink" style="display:none;"
   classid="clsid:75718C9A-F029-11D1-A1AC-00C04FB6C223"></object>

<script language="vbscript">

username=""
password=""
comp_name=""

set locator = CreateObject("Wbemscripting.SWbemLocator")
locator.security_.impersonationLevel = 3 'impersonate
set connector = _
locator.ConnectServer(Comp_Name,"root/cimv2",username,password)

wql = "Select * From __InstanceCreationEvent Within 2 " _
           & "Where TargetInstance ISA 'cim_DirectoryContainsFile' " _
           & "AND TargetInstance.GroupComponent=" _
           & "'Win32_Directory.Name=""c:\\\\test""'"

connector.ExecNotificationQueryAsync mysink, wql

</script>

<script language="vbscript" for="mysink"
  event="OnObjectReady(objObject, objAsyncContext)">

s = "[" & time() & "] "
set o = connector.get(objObject.targetinstance.Partcomponent)
s = s & o.name & "<br>"
output.insertAdjacentHTML "beforeEnd",s

</script>

<style>
body {
  font:x-small 'courier new';
  color:black;background-color:white;
  }
</style>
</head>
<body>
<div id="output"></div>
</body>
</html>

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:

> my solution script on the basis of your script with async notification

> 'start script ------------
> username=""
> password=""
> comp_name=""

> set locator = CreateObject("Wbemscripting.SWbemLocator")
> locator.security_.impersonationLevel = 3 'impersonate
> set connector =
> locator.ConnectServer(Comp_Name,"root/cimv2",username,password)

> wql = "Select * From __InstanceCreationEvent Within 2 " _
>            & "Where TargetInstance ISA 'cim_DirectoryContainsFile' " _
>            & "AND TargetInstance.GroupComponent=" _
>            & "'Win32_Directory.Name=""c:\\\\test""'"

> set sink = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
> connector.ExecNotificationQueryAsync sink, wql
> wscript.echo "wait for events"
> sink.Cancel()

> '--------------Event Function ----------

> Sub SINK_OnObjectReady(objObject, objAsyncContext)
> WScript.Echo "File Created" & objObject.targetinstance.Partcomponent
> set o = connector.get(objObject.targetinstance.Partcomponent)
> wscript.echo o.name
> End Sub

> ' end script -------------------------

> Ingo




> > > You can also write a script that uses WMI to register for a file system
> change notification event on a folder.  I've seen examples but don't recall
> enough of the details to go out searching for one ;-)...

> > Adding WMI into the "soup" isn't going to save the OP any memory, is it
> ;-)

> > I didn't find any complete example, but I built one:

> >       ---------------------  Script start ---------------------
> > ' Script that will detect all new files in c:\test with a optmized query.

> > strQuery = "Select * From __InstanceCreationEvent Within 2 " _
> >            & "Where TargetInstance ISA 'cim_DirectoryContainsFile' " _
> >            & "AND TargetInstance.GroupComponent=" _
> >            & "'Win32_Directory.Name=""c:\\\\test""'"

> >   ' for remote, define a sComputerName variable and exchange the line
> >   ' above with this two ( in addition to the changes in the
> >   ' "GetObject("winmgmts:")" statement as well):
> >   ' & "AND TargetInstance.GroupComponent='\\\\" & sComputerName _
> >   ' & "\\root\\cimv2:Win32_Directory.Name=""c:\\\\test""'"

> > Set oEvents = GetObject("winmgmts:").ExecNotificationQuery (strQuery)

> > WScript.Echo "Waiting for events..."

> > ' now wait for events ...
> > Do While True             ' loop indefinitely
> >   Set oNTEvent = oEvents.NextEvent.TargetInstance ' retrieve event
> >   WScript.Echo "Data: " & oNTEvent.PartComponent
> > Loop

> > ' Will give you an output on this format for each new file:
> > ' \\<computername>\root\cimv2:CIM_DataFile.Name="c:\\test\\New.txt"

> >       ---------------------  Script end ---------------------

> > To "kill" this script in a nice way, I recommend this procedure:

> > From a command prompt, run:
> > 1)
> > net stop "Windows Management Instrumentation"
> > 2)
> > net start "Windows Management Instrumentation"

> > Why should you do this, and not just kill cscript.exe/wscript.exe from the
> task list, you might ask?

> > Well, you could, but my experience is that WMI in that case a lot of times
> gets "crazy" and starts eating all my memory until my computer "jumps off a
> cliff".

> > --
> > torgeir



Sat, 04 Sep 2004 03:51:09 GMT  
 memory resident program
I like that...

Just for fun, here's an HTA version...

<html>
<title>WatchFolder</title>
<hta:application
  id="WatchFolder"        applicationname="WatchFolderHTA"  
  singleinstance="yes"    windowstate="minimize"    
  caption="yes"           showintaskbar="yes"
  sysmenu="yes"           scroll="yes"
/>

<object id="mysink" style="display:none;"
   classid="clsid:75718C9A-F029-11D1-A1AC-00C04FB6C223"></object>

<script language="vbscript">

username=""
password=""
comp_name=""

set locator = CreateObject("Wbemscripting.SWbemLocator")
locator.security_.impersonationLevel = 3 'impersonate
set connector = _
locator.ConnectServer(Comp_Name,"root/cimv2",username,password)

wql = "Select * From __InstanceCreationEvent Within 2 " _
           & "Where TargetInstance ISA 'cim_DirectoryContainsFile' " _
           & "AND TargetInstance.GroupComponent=" _
           & "'Win32_Directory.Name=""c:\\\\test""'"

connector.ExecNotificationQueryAsync mysink, wql

</script>

<script language="vbscript" for="mysink"
  event="OnObjectReady(objObject, objAsyncContext)">

s = "[" & time() & "] "
set o = connector.get(objObject.targetinstance.Partcomponent)
s = s & o.name & "<br>"
output.insertAdjacentHTML "beforeEnd",s

</script>

<style>
body {
  font:x-small 'courier new';
  color:black;background-color:white;
  }
</style>
</head>
<body>
<div id="output"></div>
</body>
</html>

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:

> my solution script on the basis of your script with async notification

> 'start script ------------
> username=""
> password=""
> comp_name=""

> set locator = CreateObject("Wbemscripting.SWbemLocator")
> locator.security_.impersonationLevel = 3 'impersonate
> set connector =
> locator.ConnectServer(Comp_Name,"root/cimv2",username,password)

> wql = "Select * From __InstanceCreationEvent Within 2 " _
>            & "Where TargetInstance ISA 'cim_DirectoryContainsFile' " _
>            & "AND TargetInstance.GroupComponent=" _
>            & "'Win32_Directory.Name=""c:\\\\test""'"

> set sink = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
> connector.ExecNotificationQueryAsync sink, wql
> wscript.echo "wait for events"
> sink.Cancel()

> '--------------Event Function ----------

> Sub SINK_OnObjectReady(objObject, objAsyncContext)
> WScript.Echo "File Created" & objObject.targetinstance.Partcomponent
> set o = connector.get(objObject.targetinstance.Partcomponent)
> wscript.echo o.name
> End Sub

> ' end script -------------------------

> Ingo




> > > You can also write a script that uses WMI to register for a file system
> change notification event on a folder.  I've seen examples but don't recall
> enough of the details to go out searching for one ;-)...

> > Adding WMI into the "soup" isn't going to save the OP any memory, is it
> ;-)

> > I didn't find any complete example, but I built one:

> >       ---------------------  Script start ---------------------
> > ' Script that will detect all new files in c:\test with a optmized query.

> > strQuery = "Select * From __InstanceCreationEvent Within 2 " _
> >            & "Where TargetInstance ISA 'cim_DirectoryContainsFile' " _
> >            & "AND TargetInstance.GroupComponent=" _
> >            & "'Win32_Directory.Name=""c:\\\\test""'"

> >   ' for remote, define a sComputerName variable and exchange the line
> >   ' above with this two ( in addition to the changes in the
> >   ' "GetObject("winmgmts:")" statement as well):
> >   ' & "AND TargetInstance.GroupComponent='\\\\" & sComputerName _
> >   ' & "\\root\\cimv2:Win32_Directory.Name=""c:\\\\test""'"

> > Set oEvents = GetObject("winmgmts:").ExecNotificationQuery (strQuery)

> > WScript.Echo "Waiting for events..."

> > ' now wait for events ...
> > Do While True             ' loop indefinitely
> >   Set oNTEvent = oEvents.NextEvent.TargetInstance ' retrieve event
> >   WScript.Echo "Data: " & oNTEvent.PartComponent
> > Loop

> > ' Will give you an output on this format for each new file:
> > ' \\<computername>\root\cimv2:CIM_DataFile.Name="c:\\test\\New.txt"

> >       ---------------------  Script end ---------------------

> > To "kill" this script in a nice way, I recommend this procedure:

> > From a command prompt, run:
> > 1)
> > net stop "Windows Management Instrumentation"
> > 2)
> > net start "Windows Management Instrumentation"

> > Why should you do this, and not just kill cscript.exe/wscript.exe from the
> task list, you might ask?

> > Well, you could, but my experience is that WMI in that case a lot of times
> gets "crazy" and starts eating all my memory until my computer "jumps off a
> cliff".

> > --
> > torgeir



Sat, 04 Sep 2004 07:40:33 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. How PROGRAMMATICALLY ShutDown a memory resident program ?

2. Making a VB Memory Resident Program?

3. Memory Resident Program

4. How SHUTDOWN a memory resident program ?

5. API Hot Key call in VB program to activate another resident program

6. Memory Resident Applications

7. Memory Resident

8. Calling memory-resident procedures

9. Memory Resident (2nd Post)

10. Memory Resident QB

11. memory resident database

12. How make prg on resident memory

 

 
Powered by phpBB® Forum Software