Check if service is running

Written by Leif Stenfeldt. Posted in Dos, Programmering

@echo off
sc query "%~1"|findstr "STATE.*:.*4.*RUNNING" >NUL
ECHO service %1 is stopped
goto :end
echo Service %1 is running

Batch script, find hverdag og weekend

Written by Leif Stenfeldt. Posted in Dos, Programmering

@echo off

FOR /F "skip=1" %%A IN ('WMIC Path Win32_LocalTime Get DayOfWeek' ) DO (
set DOW=%%A
goto :continue

if %DOW% EQU 0 goto :week
if %DOW% EQU 6 goto :week
echo Det er hverdag
goto :end

echo Det er weekend



Convert FAT to NTFS command (CMD)

Written by Leif Stenfeldt. Posted in Dos, Tips, Windows 8

Windows OS supports the conversion of a FAT volume to a NTFS volume without deleting the files on the drive. We can do this using the command convert. You can find syntax below.

convert drivename /FS:NTFS 

Example: To convert E: drive from FAT to NTFS, we can run the below command.

convert E: /FS:NTFS

Adding /X switch forces the command to unmount the volume if required.


Batch. ping scanner

Written by Leif Stenfeldt. Posted in Dos, Programmering, Tips

SET output=%USERPROFILE%\output.txt
IF EXIST “%output%” DEL “%output%”
FOR /L %%G IN (1, 1, 69) DO (
CALL :ping 192.168.%%G.3
CALL :ping 192.168.%%G.4

ping -n 1 %1 >NUL && ECHO %1>>”%output%”





How to run Control Panel tools from command line

Written by Leif Stenfeldt. Posted in Dos, Tips

To run a Control Panel tool in Windows, type the appropriate command in the Open box or at a command prompt.

NOTE: If you want to run a command from a command prompt, you must do so from the Windows folder. Also, note that your computer may not have all of the tools listed in this article, as your Windows installation may not include all of these components.
Control panel tool Command
Accessibility Options control access.cpl
Add New Hardware control sysdm.cpl add new hardware
Add/Remove Programs control appwiz.cpl
Date/Time Properties control timedate.cpl
Display Properties control desk.cpl


Dos batch – part of file name

Written by Leif Stenfeldt. Posted in Dos, Programmering, Tips

Calls one batch program from another.

CALL [drive:][path]filename [batch-parameters]

If Command Extensions are enabled, CALL changes as follows:

CALL command now accepts labels as the target of the CALL. The syntax is:

CALL :label arguments
A new batch file context is created with the specified arguments and control is passed to the statement after the label specified. You must “exit” twice by reaching the end of the batch script file twice. The first time you read the end, control will return to just after the CALL statement. The second time will exit the batch script. Type GOTO /? for a description of the GOTO :EOF extension that will allow you to “return” from a batch script.

In addition, expansion of batch script argument references (%0, %1, etc.) have been changed as follows:

%* in a batch script refers to all the arguments (e.g. %1 %2 %3 %4 %5 …)


Substitution of batch parameters (%n) has been enhanced. You can now use the below optional syntax:

%~1 expands %1 removing any surrounding quotes (“)
%~f1 expands %1 to a fully qualified path name
%~d1 expands %1 to a drive letter only