this program was written out a need to test if a certain program or batch file or another instance of the same program is running
use the program consname.bas to name your window caption
in using this program for a batch file
you would test for a application's(console running batch file) caption
the if the ERRLEVEL returns a 1 then the application(batch file) is already running(such as a backup routine)then usually abort the program because you do notwant another instance of the program running.
if the ERRLEVEL returns a 0 or otherwise, place the name in the caption using consname then continue with your statments in the batch file.
consname.exe and consname.bas are located in the attached zip file
ex of batch file handling
use the program consname.bas to name your window caption
in using this program for a batch file
you would test for a application's(console running batch file) caption
the if the ERRLEVEL returns a 1 then the application(batch file) is already running(such as a backup routine)then usually abort the program because you do notwant another instance of the program running.
if the ERRLEVEL returns a 0 or otherwise, place the name in the caption using consname then continue with your statments in the batch file.
consname.exe and consname.bas are located in the attached zip file
Code:
REM ISITRUNG,BAS REM compiled with pbcc4.4 powerbasic #COMPILE EXE #INCLUDE "WIN32API.INC" GLOBAL scompare$ GLOBAL foundrunning AS LONG FUNCTION EnumCallback (BYVAL hWnd AS LONG, lParam AS LONG) AS LONG DIM szCaption AS ASCIIZ * %MAX_PATH, Result AS LONG Result = GetWindowText(hWnd, szCaption, SIZEOF(szCaption)) IF TRIM$(szCaption) <> "" THEN Result = FindWindow ("", szCaption) IF scompare$="" THEN REM PRINT "hWnd: " & FORMAT$(Result) TAB(16) szCaption PRINT szCaption WAITKEY$ ELSE TEMP$=TRIM$(UCASE$(SZCAPTION)) DO WHILE INSTR(TEMP$," ") REPLACE " " WITH " " IN TEMP$ LOOP TEMP$=TRIM$(TEMP$) IF TEMP$=UCASE$(scompare$) THEN foundrunning=1& END IF END IF END IF FUNCTION = 1 END FUNCTION FUNCTION PBMAIN AS LONG LOCAL textsearched AS STRING scompare$=COMMAND$ scompare$=TRIM$(scompare$) textsearched=scompare$ DO WHILE INSTR(scompare$," ") REPLACE " " WITH " " IN scompare$ LOOP scompare$=TRIM$(scompare$) IF LEN(scompare$)=0 THEN PRINT:PRINT "list of applications running":PRINT STRING$(78,196) EnumWindows CODEPTR(EnumCallback), 0& IF LEN(scompare$)<> 0 AND foundrunning=0& THEN scompare$="command prompt - "+scompare$ EnumWindows CODEPTR(EnumCallback), 0& END IF IF LEN(scompare$)=0 THEN PRINT STRING$(78,196) PRINT "Check if application running? the name goes on the command tail" PRINT "ERRLEVEL 1 is returned if true, otherwise ERRLEVEL 0 is returned" ELSE IF foundrunning& THEN PRINT "*** "+textsearched+" *** application found running" PRINT "ERRLEVEL 1 returned" ELSE PRINT "*** "+textsearched+" *** did not find this application" PRINT "ERRLEVEL 0 returned" END IF END IF FUNCTION=foundrunning& 'WAITKEY$ END FUNCTION
Code:
CLS ECHO OFF isitrung test me IF ERRORLEVEL = 1 GOTO ABORT CONSNAME TEST ME CLS ECHO "program was not already running continue statements" PAUSE GOTO STOP :ABORT ECHO " this batch file was already running" pause :STOP exit
Comment