You only have to set 'ProcessName' variable inside a script with the process name (i.e. calc.exe) that you want to find.
@ECHO OFF
SET ProcessName=calc.exe
SET Counter=0
FOR /F "delims=\\ " %%c IN ('NET VIEW ^|FIND "\\"') DO (
PING -n 1 -l 10 -w 100 %%c |FIND /I "TTL" >NUL
IF NOT ERRORLEVEL 1 (
ECHO Processing: %%c
TASKLIST /S %%c /V /FI "IMAGENAME eq %ProcessName%" /FO LIST |FIND /I "PID" >NUL
IF NOT ERRORLEVEL 1 (
SET /A Counter+=1
ECHO =================================>>ProcessInfo.txt
ECHO Machine: %%c >>ProcessInfo.txt
ECHO =================================>>ProcessInfo.txt
ECHO Date: %DATE% Time: %TIME% >>ProcessInfo.txt
FOR /F "tokens=3" %%u IN ('REG QUERY "\\%%c\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName ^|FIND /I "REG_SZ"') DO (
ECHO Logged-in username: %%u >>ProcessInfo.txt)
TASKLIST /S %%c /V /FI "IMAGENAME eq %ProcessName%" /FO LIST >>ProcessInfo.txt
ECHO.>>ProcessInfo.txt)))
IF %Counter% GTR 0 (
ECHO. &ECHO Found %Counter% machine^(s^) with running '%ProcessName%' process.
ECHO For more info check 'ProcessInfo.txt' on %CD%) ELSE (
ECHO. &ECHO No machine found with '%ProcessName%' running.)
:ExitScript
ECHO.
PAUSE
SET ProcessName=calc.exe
SET Counter=0
FOR /F "delims=\\ " %%c IN ('NET VIEW ^|FIND "\\"') DO (
PING -n 1 -l 10 -w 100 %%c |FIND /I "TTL" >NUL
IF NOT ERRORLEVEL 1 (
ECHO Processing: %%c
TASKLIST /S %%c /V /FI "IMAGENAME eq %ProcessName%" /FO LIST |FIND /I "PID" >NUL
IF NOT ERRORLEVEL 1 (
SET /A Counter+=1
ECHO =================================>>ProcessInfo.txt
ECHO Machine: %%c >>ProcessInfo.txt
ECHO =================================>>ProcessInfo.txt
ECHO Date: %DATE% Time: %TIME% >>ProcessInfo.txt
FOR /F "tokens=3" %%u IN ('REG QUERY "\\%%c\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName ^|FIND /I "REG_SZ"') DO (
ECHO Logged-in username: %%u >>ProcessInfo.txt)
TASKLIST /S %%c /V /FI "IMAGENAME eq %ProcessName%" /FO LIST >>ProcessInfo.txt
ECHO.>>ProcessInfo.txt)))
IF %Counter% GTR 0 (
ECHO. &ECHO Found %Counter% machine^(s^) with running '%ProcessName%' process.
ECHO For more info check 'ProcessInfo.txt' on %CD%) ELSE (
ECHO. &ECHO No machine found with '%ProcessName%' running.)
:ExitScript
ECHO.
PAUSE
No comments:
Post a Comment