Dark Developments Where Knowledge Meets Power

12Jun/120

BATCH – Check Network Connection

Posted by Dark#Basics

BATCH - Check Network Connection

A couple of days ago we've installed a ThinClient at one of our customers. The point of the TC is to start a web browser in FullScreen mode and preform as an information screen. The website itself refreshes at a certain time displaying new information. The problem was that the network connection was done wireless and thus when the client is booted we'll need to check the network connection before running the browser. The following BATCH script did the trick.

Select All Code:
1
2
3
4
5
6
7
8
@echo off
set ip=8.8.8.8
 
:check_loop
ping -n 1 %ip%
if %ERRORLEVEL% NEQ 0 goto check_loop
 
START [PATH TO CHROME-LNK]
Filed under: Batch, Programming No Comments
9Aug/112

BATCH – Single Instance

Posted by Dark#Basics

Batch-script for single instance verification, can be used in combination with Task Schedular.

Select All Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
@echo off
REM ProcessName
SET PROCESS=notepad.exe
REM Path of the program
SET PROGRAMPATH=C:\WINDOWS\System32\notepad.exe
REM Check the amount of running processes
tasklist /FI "IMAGENAME eq %PROCESS%" | find /I /C "%PROCESS%" >> PCOUNT.DAT
SET /P PCOUNT=< PCOUNT.DAT
del PCOUNT.DAT
REM If 0, start instance
IF %PCOUNT% EQU 0 ( "%PROGRAMPATH%" )
REM If 2 or more, kill instances and start new instance
IF %PCOUNT% GEQ 2 ( TASKKILL /F /IM %PROCESS% /T && "%PROGRAMPATH%")