Check if service is running

Written by leif. Posted in Dos, Programmering

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
sc query "%~1"|findstr "STATE.*:.*4.*RUNNING" >NUL
IF ERRORLEVEL 1 (
ECHO service %1 is stopped
goto :end
)
echo Service %1 is running
:end
EXIT /b
1231 views

Batch script, find hverdag og weekend

Written by leif. Posted in Dos, Programmering


@echo off

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

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

:week
echo Det er weekend

:end

1054 views

Convert FAT to NTFS command (CMD)

Written by leif. 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.

1160 views

Batch. ping scanner

Written by leif. Posted in Dos, Programmering, Tips

@ECHO OFF
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
)
GOTO :EOF

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


 

source: http://stackoverflow.com/questions/5037382/batch-file-loop-ping-output-to-file-hosts-that-are-up

 

1201 views

How to run Control Panel tools from command line

Written by leif. 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

1604 views

Dos batch – part of file name

Written by leif. 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

1318 views