Link to home
Start Free TrialLog in
Avatar of celtician
celticianFlag for American Samoa

asked on

Adapt windows 2003 server script to windows 2000 server

I have the next script for windows 2003 server, working very well, and i need to adapt it to work in windows 2000, when i try to execute it (as a .bat file) i get the next error

@echo off
setlocal enabledelayedexpansion
set Process=dllhost
set Limit=80
set LogFile=C:\Temp\dllhost.log
:loopPerf
set Usage=0
for /f "delims=" %%a in ('wmic.exe path Win32_PerfFormattedData_PerfProc_Process Where "Name='%Process%' or name like '%Process%#%%'" get PercentProcessorTime^,IDProcess /value ^| find.exe "="') do (
	for /f "tokens=1,2 delims==" %%w in ("%%a") do (
		set %%w=%%x
		if "%%w"=="PercentProcessorTime" (
			if !PercentProcessorTime! geq %Limit% (
				taskkill.exe /pid !IDProcess!
				>>"%LogFile%" echo [%Date%][%Time%] Killed %Process% with PID !IDProcess!.
			) else (
				echo usage for PID !IDProcess! at !PercentProcessorTime! at %time%
			)
		)
	)
)
ping.exe -n 61 localhost >NUL
goto loopPerf

Open in new window


Error returned:

WMIC not recognized as an internal or external command

I assume there must be some other interpreter instead of wmic??
Avatar of Neil Russell
Neil Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

My only comment would be..

Why are you using TWO outdated, unsupported, retired OSes?
Avatar of Qlemo
WMIC does not exist on W2000. Your best option is to run the script remotely, as you can access WMI from another PC (XP and above).
Avatar of celtician

ASKER

Theser servers are being used at my company, they will be replaced in a few weeks... so i just need this kind of patch working for this long.... but this is not a long term solution.
Avatar of oBdA
oBdA

I've changed the script to support remoting; it might work if you run it on your W2k3 server against the W2k machine.
@echo off
setlocal enabledelayedexpansion
set Server=acme
set Process=dllhost
set Limit=80
set LogFile=C:\Temp\dllhost.log
:loopPerf
set Usage=0
for /f "delims=" %%a in ('wmic.exe /node:%Server% path Win32_PerfFormattedData_PerfProc_Process Where "Name='%Process%' or name like '%Process%#%%'" get PercentProcessorTime^,IDProcess /value ^| find.exe "="') do (
	for /f "tokens=1,2 delims==" %%w in ("%%a") do (
		set %%w=%%x
		if "%%w"=="PercentProcessorTime" (
			if !PercentProcessorTime! geq %Limit% (
				taskkill.exe /s %Server% /pid !IDProcess! /f
				>>"%LogFile%" echo [%Server%][%Date%][%Time%] Killed %Process% with PID !IDProcess!.
			) else (
				echo [%Server%] Usage for PID !IDProcess! at !PercentProcessorTime! at %time%
			)
		)
	)
)
ping.exe -n 61 localhost >NUL
goto loopPerf

Open in new window

Ok so i must connect to the remote server from the script in the W2k3?

Is there any way i can check the connetion between servers first?

I like the idea, because the 2003 server has more resources available.
Well, the main resources are used by WMI, which will still be running on the target server.
This will query while in the monitoring loop:
@echo off
setlocal enabledelayedexpansion
set Server=acme
set Process=dllhost
set Limit=80
set LogFile=C:\Temp\dllhost.log
:loopPerf
ping.exe -4 -n 2 %Server% | find.exe /i "TTL" >NUL
if errorlevel 1 (
	echo [%Server%] Offline at %time%
) else (
	set Usage=0
	for /f "delims=" %%a in ('wmic.exe /node:%Server% path Win32_PerfFormattedData_PerfProc_Process Where "Name='%Process%' or name like '%Process%#%%'" get PercentProcessorTime^,IDProcess /value ^| find.exe "="') do (
		for /f "tokens=1,2 delims==" %%w in ("%%a") do (
			set %%w=%%x
			if "%%w"=="PercentProcessorTime" (
				if !PercentProcessorTime! geq %Limit% (
					taskkill.exe /s %Server% /pid !IDProcess! /f
					>>"%LogFile%" echo [%Server%][%Date%][%Time%] Killed %Process% with PID !IDProcess!.
				) else (
					echo [%Server%] Usage for PID !IDProcess! at !PercentProcessorTime! at %time%
				)
			)
		)
	)
)
ping.exe -n 3 localhost >NUL
goto loopPerf

Open in new window

I think i should authenticate somehow into the remote host, shouldn't i?

im not asked for user/password anywhere.

I get the next error when running the script:

Error:
Código ( CODE) = 0x800706ba
Descripción (descriptioN) = El servidor RPC no está disponible. (RPC server not available)
Recurso (resource) = Win32

Open in new window

Assuming those machines are in the same domain, and you're logged on as Domain Admin, it should work.
Check if the Windows Remote Management service (or something similar; it's been too long since I had a W2k machine in front of me) is running on the W2k server. If it's set to Manual or Disabled, set it to Automatic and start it, then try again.
they are in the same domain, have different IPs but i really dont know the permissions of the user i use to log in (i assume its an admin), ill check it with the systems department.

isn't there any way of adapting the script to a w2k machine and run it locally instead?
Converting the script to VBS should work, but needs some effort. Usually it is much easier to check for remote WMIC access.
Well, wmic.exce just isn't available on Windows 2000.
But you need to be a local administrator anyway to kill a process that wasn't started by you, so once remote management is enabled, this should work remotely as well.
Ok, today ill get an answer from the systems department, unfortunately this company is so large, that internal bureaucracy takes so long. :(
i got an answer, they dont give support to W2K anylonger as the machines will be shut down these months...

So back to the first question, isn't it possible to adapt it?
You set up Performance Monitoring for dllhost, and define a trigger action if the CPU load is more than the limit for x minutes. The action is just the taskkill.

This is the proper way to do it. Should work on W2000 and above.
celtician,
did you check the Windows Remote Management service on the W2k machine?

Qlemo,
Relevant word being "should" - in my experience, performance monitoring tasks are hit and miss, leaning towards the miss (at least on W2k/W2k3). Especially after a reboot of the machine, the alert might or just might not fire.
And taskkill.exe only came with XP/W2k3 and later.
Stupid me, of course taskkill is not available on W2k.
Never had issues with perfmon tasks, but didn't use them that much to disagree.
Im checking if that service is enabled... i assume this has nothing to do with remote desktop (which i use to connect to the machine, as i dont have phisical access) right???
WinRM is not related to RDP, celtician.
Ok i have enabled it (my  systems department) and confirmed to be so, however i still get this error:

Error:
Código (code) = 0x800706ba
Descripción = El servidor RPC no está disponible. (RCP server is not available)
Recurso (resource) = Win32

Shoud i use in the script the other server's name or the IP??
So any hints?? the Windows Remote Management has been enabled yet... but it keeps failing to work.
So you're trying to connect from the W2k3 machine to the W2k machine?
Can you start wbemtest.exe locally on the W2k machine and connect to the root\cimv2 namespace?
Are both machines in the same subnet?
Any active (soft- or hardware) firewall between them?
I really don't have physical access to these machines, i know they are in the same building and internal corporate network but i do not know anything else (fierworks, subnets. etc...) besides their IP addresses.

is there any way i can make an easy check of the connection between them?

I really would prefer adapting the script to the local machine instead... i think it would be easier...
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the answer OBdA

When executing it (locally in the W2k machine) from the cmd window (i renamed the script as myscript.vbs and placed it in the root folder c:/), i get the next error:

C:\>cscript.exe /nologo "C:\myscript.vbs"
C:\myscript.vbs(10, 2) SWbemObjectSet: Non specified Error

Open in new window


What should i check?
I think i should open another question to solve this, as the adaptation has been made, but now the problems that may arise may have nothing to do!