Winbatch

Print

IIS Service Search Script

Script

As always the code presented here is for instructional purposes. These scripts will most likely need to be modified to run in your environment. Also as I believe firmly in "re-usable code" you may find pieces of your scripts incorporated into mine. If so and you would like credit use the "email me" link and let me know. I'll be happy to add your name. Likewise if you use my code in a public forum please give me credit.

NOTE: You can copy and paste the code below to a text file, just change the extension to ".wbt" so it will run in Winbatch.


About This Script

This Winbatch script is more of a skeleton that you can modify and use for a number of search and info gathering purposes. In it's current form it searches a list of systems and checks for the IIS service and reports on whether it exists or not. You can modify it to look for any thing you want and to run a program or script against any system it finds. Open it up and look at it. It's very self explanatory.


num=0

ListNum=0

astatusbar(0,"PingSys","Looking for live systems.%@CRLF% Number of Systems to search= %ListNum%",ListNum,num)

ListOfSystems=Fileopen(ListOfSystems,"read")

OutPutFile=Fileopen(OutPutFile,"append")

d=datetime()

errormode(@OFF)

while @true

system=Fileread(ListOfSystems)

if system=="*EOF*" then break

system0=strcat(system,".yourDomain.com")

png=ipping( system0,3)

if png==@true

Filewrite(OutPutFile,"%system% can be pinged");CHANGE THIS TO WHAT YOU WANT WRITTEN IN YOUR LOG FILE

;~~~~~~~~PLACE ACTIONS TO BE PERFORMED HERE~~~~~~~~~~~~~~

function=wntSvcStatus(system, "W3SVC", 1000 , 0)

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

system1=strcat("\\",system)

if function==@TRUE

Filewrite(OutPutFile,"%system% Service Found") ;CHANGE THIS TO WHAT YOU WANT WRITTEN IN YOUR LOG FILE if the service is found

else

Filewrite(OutPutFile,"%system% Service Not Found") ;CHANGE THIS TO WHAT YOU WANT WRITTEN IN YOUR LOG FILE if the service is not found

endif

if function==@TRUE

function1=wntSvcStatus(system1, "W3SVC", 1000 , 2)

switch function1

case 1

Filewrite(OutPutFile,"%system% SERVICE_STOPPED")

break

case 2

Filewrite(OutPutFile,"%system% SERVICE_START_PENDING")

break

case 3

Filewrite(OutPutFile,"%system% SERVICE_STOP_PENDING")

break

case 4

Filewrite(OutPutFile,"%system% SERVICE_RUNNING")

break

case 5

Filewrite(OutPutFile,"%system% SERVICE_CONTINUE_PENDING")

break

case 6

Filewrite(OutPutFile,"%system% SERVICE_PAUSE_PENDING")

break

case 7

Filewrite(OutPutFile,"%system% SERVICE_PAUSED")

break

endswitch

endif

endif

num=num+1

remains=listnum-num

astatusbar(1,"PingSys","Checking -> %system% %@CRLF%Systems remaining= %remains%",ListNum,num)

endwhile

astatusbar(2,"","","",0)

fileclose(ListOfSystems)

exit