Probleme script VBS : "Out Of memory"

exki -  
 mustang -
Hello !

Bon j'utilise un petit programme en vbs pour surveiller la presence d'un process mais au bout d'un certain nombre de jour, il ne marche plus et j'ai un message d'erreur. Help me !!!!

Le programme :

Do
strComputer = "."
Set objSWbemServices = GetObject("winmgmts:" &_
"{impersonationLevel=impersonate}!" &_
"\\" & strComputer & "\root\cimv2")

Set objEventSource = objSWbemServices.ExecNotificationQuery( _
"SELECT * FROM __InstanceOperationEvent " &_
"WITHIN 1 " &_
"WHERE TargetInstance " &_
"ISA 'Win32_Process' " &_
"AND TargetInstance.Name = 'OmsServer.exe'")

Set objEventObject = objEventSource.NextEvent()
Select Case objEventObject.Path_.Class
Case "__InstanceCreationEvent"
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run ("C:\outils\batchs\message.bat " & 1)
Case "__InstanceDeletionEvent"
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run ("C:\outils\batchs\message.bat " & 2)
End Select
Loop


Le message d'erreur :

Line 7
Char 1
Error Out of memory

Code : 80041006
Source : SWbemServices


Merci @ vous tous
A voir également:

2 réponses

Lord Mathius Messages postés 24 Date d'inscription   Statut Membre Dernière intervention  
 
Bonjour exki
Je pense que ton pb vient du fait que tu ne sort jamais de la boucle. donc ton script charge en memoire et fini par saturer la memoir.

car si je voit bien tu declare ton objet a chaque boucle ce qui n'est pas tres propre en faire.

essaye plutot ca :

Do 
 strComputer = "." 
 Set objSWbemServices = GetObject("winmgmts:" &_ 
 "{impersonationLevel=impersonate}!" &_ 
 "\\" & strComputer & "\root\cimv2")  

 Set objEventSource = objSWbemServices.ExecNotificationQuery( _ 
 "SELECT * FROM __InstanceOperationEvent " &_ 
 "WITHIN 1 " &_ 
 "WHERE TargetInstance " &_ 
 "ISA 'Win32_Process' " &_ 
 "AND TargetInstance.Name = 'OmsServer.exe'") 

 For I = 1 To 10000


  Set objEventObject = objEventSource.NextEvent() 
  Select Case objEventObject.Path_.Class 
  Case "__InstanceCreationEvent" 
  Set WshShell = WScript.CreateObject("WScript.Shell") 
  WshShell.Run ("C:\outils\batchs\message.bat " & 1) 
  Case "__InstanceDeletionEvent" 
  Set WshShell = WScript.CreateObject("WScript.Shell") 
  WshShell.Run ("C:\outils\batchs\message.bat " & 2) 
  End Select 
 Next
 Set objEventSource = nothing
 Set objSWbemServices = nothing
Loop 

bon courage
Lord Mathius a votre service. 
0
mustang
 
Il ne manquerait pas:

Set WshShell = nothing

dans la boucle for!?
0