Link to home
Start Free TrialLog in
Avatar of ReneGe
ReneGeFlag for Canada

asked on

Batch File to VBScript

Hi there,

I need to convert the following batch file to VBscript.

Thanks for your help,
Rene

 
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION


SET TMP1=%~n0_TMP1.txt
SET TMP2=%~n0_TMP2.txt
SET WaitTime=60

SET LogFolder=.\LOGS
SET LogFile=%LogFolder%\%~n0.log

IF EXIST "%TMP1%" DEL "%TMP1%"
IF EXIST "%TMP2%" DEL "%TMP2%"

ECHO ^>READING RUNNING TASKS FOR THE FIRST TIME
CALL :GetDateTime
(FOR /F "tokens=1,9* delims=," %%A IN ('TASKLIST /NH /v /FO CSV /FI "USERNAME ne NT AUTHORITY\SYSTEM"') DO ECHO %%~A,%%~B)>>"%TMP1%"



:Home

REM READING INI FILE
	IF EXIST "%~n0.ini" FOR /F "tokens=1,2 delims==" %%A IN (%~n0.ini) DO SET %%A=%%B

IF NOT EXIST "%LogFolder%" MD "%LogFolder%"

ECHO WAIT TIME=%WaitTime%
ECHO LOG FOLDER="%LogFolder%"
ECHO LOG FILE="%LogFile%"
ECHO.

ECHO ^>Waiting
CHOICE /D Y /T 05 >NUL
CLS

ECHO ^>READING CURRENT TASKS
(FOR /F "tokens=1,9* delims=," %%A IN ('TASKLIST /NH /v /FO CSV /FI "USERNAME ne NT AUTHORITY\SYSTEM"') DO ECHO %%~A,%%~B)>>"%TMP2%"

CALL :GetDateTime

ECHO ^>ARE THERE NEW RUNNERS?
REM ARE THERE NEW RUNNERS?
FOR /F "tokens=1,2 delims=," %%A IN ('findstr /V /G:"%TMP1%" "%TMP2%"') DO IF "%%B" NEQ "N/D" ECHO %TheDate%,%TheTime%,+,%username%,%%A,%%B>>%LogFile%

ECHO ^>ARE THERE CLOSED RUNNERS?
REM ARE THERE CLOSED RUNNERS?
FOR /F "tokens=1,2 delims=," %%A IN ('findstr /V /G:"%TMP2%" "%TMP1%"') DO IF "%%B" NEQ "N/D" ECHO %TheDate%,%TheTime%,-,%username%,%%A,%%B>>%LogFile%

MOVE /Y "%TMP2%" "%TMP1%">NUL

GOTO Home


:GetDateTime
REM READ DATE
	FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') DO (
		IF %%A GTR 0 (
		SET Day=0%%A
		SET Hour=0%%B
		SET Min=0%%C
		SET Month=0%%D
		SET Sec=0%%E
		SET Year=%%F
	)
)
SET Day=%Day:~-2%
SET Hour=%Hour:~-2%
SET Min=%Min:~-2%
SET Month=%Month:~-2%
SET Sec=%Sec:~-2%

SET TheDate=%Year%-%Month%-%Day%
SET TheTime=%Hour%.%Min%.%Sec%

EXIT /b

Open in new window

Avatar of ovolume
ovolume
Flag of United States of America image

Microsoft publishes several utilities to monitor processes. See http://technet.microsoft.com/en-us/sysinternals/.
Avatar of ReneGe

ASKER

Thanks ovolume, but none of them does what I need to do.

Cheers,
Rene
The included batch instructions create a log file listing any new or terminated processes. Is that all that is needed or is additional functionality desired?
Avatar of ReneGe

ASKER

Yep!

I need to have this in VBScript because with a batch file, I was unable to get the unicode french caracters to the output file correctly.

Also, I need their Window Title and if possible, to get this info from a remote Domain PC as well.

By the way, I'v tried to get the remote window title using WMIC, tasklist, psexec and Power Shell v2.0 and no luck here.

Thanks for helping
Avatar of ReneGe

ASKER

Just wanted to know if you were on it?

Thanks and cheers,
Rene
Yes, I will have a working VBScript for you this week.
Avatar of ReneGe

ASKER

Thanks a million!
ASKER CERTIFIED SOLUTION
Avatar of ovolume
ovolume
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ReneGe

ASKER

I tried it and it did not work. I'll give you details a bit later.

Thanks a million,
Rene
Did it work as-is, without replacing the strServer variable (i.e., strServer = ".")? I ran the script successfully on Windows 7 32bit, XP and Server 2003 R2.  
Avatar of ReneGe

ASKER

I replaced the wrong strServer. What a bummer!!

I'll try it right now and let you know.
Avatar of ReneGe

ASKER

Ok, it does work. Sorry for that.

Issues:
-I need to log changes that occured every 15 seconds
-Need to log the Window Title
-Need to laungh it with cscript as (for example): cscript "monitorapps.vbs" "pcname1"
-When launghing, no computer name is defined, monitor apps on the PC it's running.

Thanks a trillion
Avatar of ReneGe

ASKER

Wow, I missed my las one. lets try again:
-When launghing, if no computer name is defined, it must monitor the apps on the PC it's running.

Avatar of ReneGe

ASKER

Thanks a million for your help.