Recent Changes - Search:

Main.SideBar (edit)



Windows

Here's a batch file that kills a windows task (job, application, whatever) if it has not written to a file for a certain amount of time (in this script 7 minutes). This can be run from the windows scheduler


@echo off
rem Kill everything and restart if the scheduled job has stopped

for /F "tokens=1,2 delims=: " %%t in ('time /t') do (
set cMin=%%u
set cHr=%%t
)

if %cMin% LSS 10 set cMin=%cMin:~1%
if %cHr% LSS 10 set cHr=%cHr:~1%
rem More than 7 minutes old
set /a ctime=%cHr%*60+%cMin%-7

for  %%d in (tmp_dif.txt) do for /f "tokens=4,5 delims=: " %%f in ( "%%~Td" ) do (
set fHr=%%f
set fMin=%%g
)

if %fHr% LSS 10 set fHr=%fHr:~1%
if %fMin% LSS 10 set fMin=%fMin:~1%
set /a ftime=%fHr%*60+%fMin%

if %ctime% LSS %ftime% goto END

echo killing the job
taskkill /F /T  /fi "WindowTitle eq SomeTitle"

:END



Here's an XP batch script to rename a file with the date/time (NB. a ":" in the time causes the rename to fail)

rem -- set rename the previous run with the date/time
FOR /f "tokens=1-3  " %%G IN ('DATE /T') DO (
SET _mm=%%H
SET _dd=%%I
SET _yy=%%G
)

:: Get the time
FOR /f "tokens=1,2 delims=: " %%G IN ('time/t') DO (
SET _hr=%%G
SET _min=%%H
)

REN "test.log" "test-%_yy%%_mm%%_dd%-%_hr%%_min%.log"

Windows has a WinHttpRequest? object that can be used from VB/VBA to retrieve information from the web into things like Excel. There are some examples out there so not recreated here, but the thing you may want to know is that there is a tool called proxyCfg that sets the proxy server name in the registry so that WinHttpRequest? can access the world outside a proxy server!


Here's a way of detecting if a drive letter exists (e.g. to detect if a USB drive or memory stick is plugged in) in a Windows batch file


echo off
if exist %1%\nul (
echo Found %1%
) else   (
echo No such drive
pause
)

Put it in a batch file and call the file with a drive letter (e.g. C: ) as a parameter - e.g.

driveCheck f:

It could be used with xcopy to back up files, or display an error if the drive is not connected


XCOPY is really useful for backing up files, say from a disk to a flash (usb/pen - I never know what they are called ) drive. It will copy only files with the archive bit set (therefore only the modified ones) if the /M flags is present. So

xcopy /EXCLUDE:exclude.txt /s /M /Y c:\work e:\

will copy everything that has changed beneath c:\work to the e: drive, except for things matched in exclude.txt. My exclude.txt looks like

.class
.jar
\lib\
.exe
.zip
.metadata
.jar
\classes\


Great tip from slashdot for restarting Explorer

Go to Start > Shutdown. When the dialog appears, hold CTRL+ALT+SHIFT and press Cancel. Explorer will cleanly unload all of it's resources and shutdown. To start it back up, open Task Manager (CTRL+SHIFT+ESC is one way) and go to File > New Task and run 'explorer'.


Run a batch file as a service

The windows resource kit includes a utility called srvany.exe which allows you to install a batch file (or any other executable) as service on windows, so it is particularly good for running java applications and app servers as services. NB. if you use this to install a Java service, stopping the service does not necessarily stop the Java App from running, it only stops SVRANY

It is a two stage process, first you install SVRANY as a service with a given name instsrv MyJavaApp? "c:\program Files\Resource Kit\srvany.exe"

Then you need to edit the registry key for the servive to tell it what to execute, ope reg edit, find HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyJavaApp Then edit parameters and add Value=Application, Data Type = REG_SZ, String = path\MyJavaApp.bat Also add Value = AppDirectory, Data Type = REG_SZ, String = path_to_run_in

Edit - History - Print - Recent Changes - Search
Page last modified on March 11, 2008, at 11:02 AM