| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 125282 | 2012-06-18 10:01:00 | Any Windows scripting gurus? | somebody (208) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 1282542 | 2012-06-18 10:01:00 | I need a .bat script to run on a Windows Server 2k3 machine to help work around some limitations of a legacy server application. In particular, it needs to: - Check if a particular process is running (blah.exe) under a particular account (myapplicationserviceaccount). There should be 4 copies of blah.exe run as myapplicationserviceaccount - If there are no "blah.exe" processes running as myapplicationserviceaccount, it should run startmyapplication.bat which will start them - If there are fewer than 4 copies of blah.exe running as myapplicationserviceaccount, it will terminate the remaining blah.exe processes, then run startmyapplication.bat If this was on a Unix/Linux environment it would be easy, but I don't know my way around Windows scripting very well. Currently I have a script which uses qprocess.exe to detect if there is one or more instance of blah.exe running, but I can't find any way to count the number of blah.exe processes running (noting that blah.exe MUST be run by myapplicationserviceaccount). Any pointers/ideas/suggestions? No I can't use PowerShell, and no I can't install Cygwin. |
somebody (208) | ||
| 1282543 | 2012-06-18 10:09:00 | for /f "tokens=*" %%a in ('<qprocess_test>^| find -c "processname"') do set processcount=%%a if not %processcount%==4 then do stuff maybe helps? |
fred_fish (15241) | ||
| 1282544 | 2012-06-18 10:20:00 | Brilliant! Thanks fred_fish - just what I was after. | somebody (208) | ||
| 1282545 | 2012-06-18 11:01:00 | "tokens=*" may be superfluous, or may need to = the count field. I can't recall the output format of find -c as I replaced it with a win32 grep a long time ago :) |
fred_fish (15241) | ||
| 1282546 | 2012-06-18 20:31:00 | Thanks - "find /C" returns a count - there doesn't seem to be a "find -c" Any idea how I'd kill off unwanted blah.exe processes? |
somebody (208) | ||
| 1282547 | 2012-06-18 22:09:00 | Thanks - "find /C" returns a count - there doesn't seem to be a "find -c" Oh, yeah ... more mental cobwebs (grep -c is count) Any idea how I'd kill off unwanted blah.exe processes? pskill (technet.microsoft.com) |
fred_fish (15241) | ||
| 1282548 | 2012-06-19 08:36:00 | Perfect - thanks for your help. | somebody (208) | ||
| 1 | |||||