I’m using this as a tracking method for how often an app is opened. Wrap this up with
app, and you can count how many times certain apps are opened.
@echo off
set RegKey=”HKLM\SOFTWARE\Tracking\AppName” /v “Counter”
set rValue=
setlocal enabledelayedexpansion
REG QUERY %RegKey%
if %ERRORLEVEL% EQU 0 goto :Main
if %ERRORLEVEL% EQU 1 goto :Add
:Add
cls
echo Key not found…Adding Key
REG ADD %RegKey% /d 0 /reg:64
ping -n 4 127.0.0.1>nul
:Main
cls
echo Retrieving Counter…
FOR /f “tokens=1,2,3” %%a In (‘REG QUERY %RegKey% /reg:64’) do (
set rValue=%%c
set /a rValue+=1 && REG ADD %RegKey% /d !rValue! /reg:64 /f
ping -n 4 127.0.0.1>nul
)
set RegKey=
set rValue=
Screenshot
Notes
Now, if you want an easy way to read the counter—in other scripting languages—you can just add echo !rValue!>c:\counter.tmp to the file above, at the end of :Main
Then, in your language of choice, just read the contents of counter.tmp.
Example in VBScript
on error resume next Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\counter.tmp",1) <strong>strCounter</strong> = objFileToRead.ReadAll() objFileToRead.Close Set objFileToRead = Nothing