Category Archives: DOS

There are lots of great DOS scripting websites, but these are a collection of scripts that I’ve personally tested.

Killing a non responding window service

How to kill a non responding service using “sc” and “TaskKill”

C:\WINDOWS>sc queryex “My Service”

SERVICE_NAME: My Service TYPE : 110 WIN32_OWN_PROCESS (interactive)
STATE : 2 START_PENDING
(STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 6868
FLAGS :

C:\WINDOWS>taskkill /PID 6868 /F

SUCCESS: The process with PID 6868 has been terminated.

Reading Values from an Input File

More than occasionally you will find that you need to call the same DOS script with several different parameter values, say a list of names.
Create a looping bat file “LoopTest.bat”.
Note that this script checks thats the file exists and prints a nice dated report header too

 ::-----Init..... @echo off & setlocal  SET day=%date:~0,2% SET month=%date:~3,2% SET year=%date:~6,4% SET DT=%year%\%month%\%day%  @echo Running Loop Script on %DT%  ::-----BatchScript1....   ::-----Check Input File Exists  cd C:\DOS_Scripts  IF NOT EXIST GirlsNames.txt goto :fileDoesNotExist  For /F "delims=" %%i in (C:\DOS_Scripts\GirlsNames.txt) do call :callPrintGirlsNames "%%i"  goto eof  :callPrintGirlsNames  Set "NameOfGirl=%~1"  call C:\DOS_Scripts\PrintGirlsNames.bat %NameOfGirl%   goto eof  ::-----eo BatchScript1....   :fileDoesNotExist @ECHO Input File does not exist, End Program. :eof 

So, for every instance of a girl’s name “%%i” you will call PrintGirlsNames.bat

Heres the code for PrintGirlsNames.bat

@echo %1

Heres some names to put in your GirlsNames.txt file ….

 Joyce Judith Julia Juliana Julianna Julianne Julie Juliet Juliette Julissa Justice Justine Kacie Kaela Kaelyn Kaia Kaila Kailey Kailyn Kaitlin Kaitlyn Kaitlynn Kaiya Kaleigh Kaley Kali Kaliyah Kallie Kalyn Kamryn Kara Kari Karina Karissa Karla Karlee Karley Karli Karlie Karly Kasandra Kasey Kassandra Kassidy Katarina Kate Katelin Katelyn Katelynn Katerina Katharine Katherine Kathleen Kathryn Kathy Katie Katlyn Katrina Katy Kaya Kayla Kaylah Kaylee Kayleigh Kayley Kayli Kaylie Kaylin Kaylyn Kaylynn Keeley