Computing.Net > Forums > Programming > batch programming help reqd

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch programming help reqd

Reply to Message Icon

Name: soma.sen
Date: August 29, 2007 at 07:12:49 Pacific
OS: win2003
CPU/Ram: 1gb
Product: intel
Comment:

Hi i am new to batch programming
I just need to:
1. start Windows Task Manager inside my batch file
2. list all active processes
3. discover the wanted-processes (check by doing netstat -ano is port no 1099 being used if yes the get the PID and find the name of the process)
4. kill it

soma



Sponsored Link
Ads by Google

Response Number 1
Name: Shr0Om
Date: August 29, 2007 at 10:00:27 Pacific
Reply:

you can list processes with tasklist in XP. I guess its avaible in w2003 as well.

Anyway.. try this

::CODE
@echo off
for /f "tokens=1-5 delims= " %%a in ('netstat -o -n ^|find "1099"') do (set PID=%%e
call :KillPID)

:KillPID
taskkill /f /PID %PID%


0

Response Number 2
Name: ghostdog
Date: August 29, 2007 at 19:21:59 Pacific
Reply:

it seems you know what's the process name by using netstat..here's a vbscript to kill process. Its just an example. Don't use svchost.exe in your case
[code]
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'svchost.exe'")

For Each objProcess in colProcessList
objProcess.Terminate()
Next
[/code]


0

Response Number 3
Name: Balkrah (by Vaughan Newton)
Date: August 31, 2007 at 10:13:27 Pacific
Reply:

Scr0Om:
If you used your batch script the 'find' command could output a line with "1099" as the PID, instead of the port. Its unlikely, but anyway to fix this you could use

@echo off
setlocal EnableDelayedExpansion
for /f "tokens=1-5 delims= " %%a in ('netstat -on ^|find ":1099"') do (
set PID=%%e
taskkill /f /PID !PID!
)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch programming help reqd

Help Batch Program www.computing.net/answers/programming/help-batch-program/13919.html

Batch Programming www.computing.net/answers/programming/batch-programming/15718.html

batch programming www.computing.net/answers/programming/batch-programming/11097.html