Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Array to initialize

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Array to initialize
  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 >>
 Array to initialize - 2/13/2006 5:03:36 AM   
  vb_blue

 

Posts: 8
Score: 0
Joined: 2/13/2006
Status: offline
Hi Everyone,

I am new to this forum. I am just learning VBScript my self to my project. We have requirement in my project to code on VB script. I want to kill three processes name "wrun.exe", "crvw.exe" and "six_agnt.exe" on four machines QA1,QA2,QA3 and QA4. As i want to initialize these in arrays and call in While or For loop. Can anybody suggent me how to do this?

Thanks,
Vijay B
 
 
Post #: 1
 
 RE: Array to initialize - 2/13/2006 5:12:31 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
This will setup the arrays for you and process them. To kill the processes, search the forum for "wmi remote kill"


      

_____________________________

"... 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 vb_blue)
 
 
Post #: 2
 
 RE: Array to initialize - 2/13/2006 6:36:04 AM   
  vb_blue

 

Posts: 8
Score: 0
Joined: 2/13/2006
Status: offline
Thanks for your reply.

I implemented the code in the following to kill the processes in the four machines, but i am getting error on line number 17 and Char 45. Can you please rectify me the error in the following code.

Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strProcessKill, strInput
Dim arrProcesses
Dim arrMachines
Dim strMachine
Dim strProcess
arrProcesses = Array("wrun.exe","crvw.exe","six_agnt.exe")
arrMachines = Array("QA1","QA2","QA3","QA4")

For Each strMachine In arrMachines
Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" _& arrMachines(strMachine) & "\root\cimv2")
For Each strProcess In arrProcesses
 Set colProcess = objWMIService.ExecQuery _("Select * from Win32_Process Where Name = " & arrProcesses(strProcess) )
 For Each objProcess in colProcess
      Msgbox "Winrunner processes:" & arrProcesses(strProcess)
      objProcess.Terminate()
  Next
 WSCript.Echo "Just killed process " & arrProcesses_& " on " & arrMachines(strMachine)
Next
Next
WScript.Quit
' End of WMI Example of a Kill Process

(in reply to vb_blue)
 
 
Post #: 3
 
 RE: Array to initialize - 2/13/2006 7:03:04 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
What is the error you get?

_____________________________

"... 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 vb_blue)
 
 
Post #: 4
 
 RE: Array to initialize - 2/13/2006 7:18:08 AM   
  vb_blue

 

Posts: 8
Score: 0
Joined: 2/13/2006
Status: offline
I have got the error "Invalid character" on line 17 and Char 45 for the above code.

(in reply to vb_blue)
 
 
Post #: 5
 
 RE: Array to initialize - 2/13/2006 7:35:01 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
If you run this code, does it display the correct process name, or do you get an error:

Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strProcessKill, strInput
Dim arrProcesses
Dim arrMachines
Dim strMachine
Dim strProcess
arrProcesses = Array("wrun.exe","crvw.exe","six_agnt.exe")
arrMachines = Array("QA1","QA2","QA3","QA4")

For Each strMachine In arrMachines
Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" _& arrMachines(strMachine) & "\root\cimv2")
For Each strProcess In arrProcesses
 Set colProcess = objWMIService.ExecQuery _("Select * from Win32_Process Where Name = " & arrProcesses(strProcess) )
 For Each objProcess in colProcess
      Msgbox "Winrunner processes:" & arrProcesses(strProcess)
      MsgBox objProcess.Name
  Next
 WSCript.Echo "Just killed process " & arrProcesses_& " on " & arrMachines(strMachine)
Next
Next
WScript.Quit
' End of WMI Example of a Kill Process

_____________________________

"... 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 vb_blue)
 
 
Post #: 6
 
 RE: Array to initialize - 2/13/2006 7:43:17 AM   
  vb_blue

 

Posts: 8
Score: 0
Joined: 2/13/2006
Status: offline
Yes! i am getting error "Invalid character" on line 12 and Char 44.

(in reply to vb_blue)
 
 
Post #: 7
 
 RE: Array to initialize - 2/13/2006 7:45:22 AM   
  vb_blue

 

Posts: 8
Score: 0
Joined: 2/13/2006
Status: offline
Its not displaying the process name. I am getting error "Invalid character" on line 12

(in reply to vb_blue)
 
 
Post #: 8
 
 RE: Array to initialize - 2/13/2006 8:19:34 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Oops...straight syntaxt error that I didn't see...try this code:

 Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strProcessKill, strInput
Dim arrProcesses
Dim arrMachines
Dim strMachine
Dim strProcess
arrProcesses = Array("wrun.exe","crvw.exe","six_agnt.exe")
arrMachines = Array("QA1","QA2","QA3","QA4")

For Each strMachine In arrMachines
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & arrMachines(strMachine) & "\root\cimv2")
For Each strProcess In arrProcesses
 Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & arrProcesses(strProcess)
 For Each objProcess in colProcess
      Msgbox "Winrunner processes:" & arrProcesses(strProcess)
      objProcess.Terminate()
  Next
 WSCript.Echo "Just killed process " & arrProcesses & " on " & arrMachines(strMachine)
Next
Next
WScript.Quit
' End of WMI Example of a Kill Process

_____________________________

"... 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 vb_blue)
 
 
Post #: 9
 
 RE: Array to initialize - 2/13/2006 8:28:58 AM   
  vb_blue

 

Posts: 8
Score: 0
Joined: 2/13/2006
Status: offline
I ran the script. I am getting error "Type mismatch: 'QA' " on line 12 and Char 1 for the below code you asked to try.

(in reply to vb_blue)
 
 
Post #: 10
 
 RE: Array to initialize - 2/13/2006 8:31:12 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
You were trying to use the machine name as the index of the array to get the machine name. Try this:
 Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strProcessKill, strInput
Dim arrProcesses
Dim arrMachines
Dim strMachine
Dim strProcess
arrProcesses = Array("wrun.exe","crvw.exe","six_agnt.exe")
arrMachines = Array("QA1","QA2","QA3","QA4")

For Each strMachine In arrMachines
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strMachine & "\root\cimv2")
For Each strProcess In arrProcesses
 Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = '" & strProcess & "'"
 For Each objProcess in colProcess
      MsgBox "Winrunner processes:" & arrProcesses(strProcess)
      objProcess.Terminate()
  Next
 WSCript.Echo "Just killed process " & arrProcesses & " on " & arrMachines(strMachine)
Next
Next
WScript.Quit
' End of WMI Example of a Kill Process

_____________________________

"... 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 vb_blue)
 
 
Post #: 11
 
 RE: Array to initialize - 2/13/2006 9:31:28 AM   
  vb_blue

 

Posts: 8
Score: 0
Joined: 2/13/2006
Status: offline
I need to pass the machines and processes name that i declared in the array.

(in reply to vb_blue)
 
 
Post #: 12
 
 RE: Array to initialize - 2/13/2006 9:34:43 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
That is what the code I posted does.

_____________________________

"... 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 vb_blue)
 
 
Post #: 13
 
 RE: Array to initialize - 2/13/2006 9:57:19 AM   
  vb_blue

 

Posts: 8
Score: 0
Joined: 2/13/2006
Status: offline
This is working perfectly fine. Thank you very much for your help.

(in reply to vb_blue)
 
 
Post #: 14
 
 
 
  

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 >> Array to initialize 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