Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making the variable as an input variable - Simple coding help

Status
Not open for further replies.

Sasstraliss

Programmer
Apr 7, 2009
21
AU
Here's the code.

Code:
'This script stops a process from running on a remote machine.

strComputer = (InputBox(" ", "Internet Explorer (Not Responding)"))
If strComputer <> "" And strComputer <> "q" And strComputer <> "e" And strComputer <> "exit" Then

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

Set colMonitoredProcesses = objWMIService. _        
    ExecNotificationQuery("select * from __instancecreationevent " _ 
        & " within 1 where TargetInstance isa 'Win32_Process'")
i = 0

Do While i = 0
    Set objLatestProcess = colMonitoredProcesses.NextEvent
    If objLatestProcess.TargetInstance.Name = "notepad.exe" Then
        objLatestProcess.TargetInstance.Terminate
    End If
Loop

End If

Here's what I want.

I would like to keep the inputbox for the computer name, but after you hit enter on that, I would like another input box to appear asking for the name of the process to prevent.

As the code is currently, you have to manually edit the script to change the process name.

I tried making the process name as an inputbox, but failed miserably.

And help on this would be greatly appreciated, thanks in advance.
 
Use something similar to:
Code:
'This script stops a process from running on a remote machine.

Dim strComputer, strProc

strComputer = (InputBox(" ", "Internet Explorer (Not Responding)"))
If strComputer <> "" And strComputer <> "q" And strComputer <> "e" And strComputer <> "exit" Then

[red]strProc = (InputBox("Enter Process", "Enter Process", "notepad.exe"))[/red]

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

Set colMonitoredProcesses = objWMIService. _
    ExecNotificationQuery("select * from __instancecreationevent " _
        & " within 1 where TargetInstance isa 'Win32_Process'")
i = 0

Do While i = 0
    Set objLatestProcess = colMonitoredProcesses.NextEvent
    If objLatestProcess.TargetInstance.Name = [red]strProc[/red] Then
        objLatestProcess.TargetInstance.Terminate
    End If
Loop

End If
I've left it to you to validate the entry in the inputbox.

Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top