|
Answer» I dont think so. It's not printing the %RESULT% and keeps going back to ' set /p variable="Please input filename (YYYYMMDD.txt) ?"' because "%result%" has an empty value.
Are you using the code inside a larger batch file, possibly in a loop?
No its not in a loop at all. I've tried it by itself also, and the same happens, I can't get the result variable to display.
Here is the whole of my code below: echo off
:BEGIN SET /p variable2=[Enter directory that Security Log reports are stored in] (e.g C:\seclogs):
IF EXIST "%variable2%" echo This Directory has been Found. IF EXIST "%variable2%" GOTO FileBegin
IF NOT EXIST "%variable2%" echo You are required to re-enter a directory name that exists: IF NOT EXIST "%variable2%" goto Begin :BEGINEND
:FileBegin
Echo Outstring="incorrect">dval.VBS Echo StrDate=Wscript.arguments(0)>>dval.vbs Echo y = Mid(StrDate,1,4)>>dval.vbs Echo m = Mid(StrDate,5,2)>>dval.vbs Echo d = Mid(StrDate,7,2)>>dval.vbs Echo If (IsDate(y^&"/"^&m^&"/"^&d) ^<^> 0) Then Outstring="correct">>dval.vbs Echo Wscript.Echo Outstring>>dval.vbs
:loop
set /p variable="Please input filename (YYYYMMDD.txt) ?" pause For /f "delims=" %%A in ( 'dval.vbs "%variable%"' ) do set result=%%A pause Echo Date format %result% pause If /i not "%result%"=="correct" goto loop del c:\dval.vbs
Set variable="%variable3%".txt IF EXIST "%variable2%\%variable%" echo This file has been Found. IF EXIST "%variable2%\%variable%" GOTO START
IF NOT EXIST "%variable2%\%variable%" echo You are required to re-enter a file name that exists: IF NOT EXIST "%variable2%\%variable%" goto loop
:start
ECHO. ECHO 1. Generate Report for list of user logoffs ECHO 2. Generate Report for list of network logons ECHO 3. Generate Report for list of users who logged in and logged out ECHO 4. Generate Report for Special permissions assigned to new logon
:choice set choice= set /p choice=Type the number to print text: if not '%choice%'=='' set choice=%choice:~0,1% if '%choice%'=='1' goto loggedout if '%choice%'=='2' goto networklogon if '%choice%'=='3' goto nwlogin_loggedout_users if '%choice%'=='4' goto specialprivs
ECHO "%choice%" is not valid please try again ECHO. goto choice
:loggedout echo Please wait while the report gets created.. find /n ",538," %variable2%\%variable% > %variable2%\userlogout_%Variable% SET /p dummy=%variable2%\userlogout_%variable% file has now been generated.. Press return to exit echo Goodbye. goto end1
:networklogon echo Please wait while the report gets created.. findstr /n ",540," %variable2%\%variable% > %variable2%\networklogon_%Variable% echo %variable2%\networklogon_%variable% has been generated. pause goto end1
:nwlogin_loggedout_users echo Please wait while the report gets created.. mkdir "%variable2%\tmp" find /n ",540," %variable2%\%variable% > %variable2%\tmp\logonlogout_%Variable%.tmp find /n ",538," %variable2%\tmp\logonlogout_%Variable%.tmp > %variable2%\logonlogout_%Variable% del /f %variable2%\tmp\logonlogout_%Variable%.tmp echo C:\logonlogout_%variable% has been generated. pause goto end1
:specialprivs echo Please wait while the report gets created.. find /n ",576," %variable2%\%variable% > %variable2%\specialprivs_%Variable% echo %variable2%\specialprivs_%variable% has been generated. pause goto end1 :end1 echo off
I ran your code & it showed me the %result% variable. I had to press a key twice though.
Take the 2 red pause statements out
:BEGIN SET /p variable2=[Enter directory that Security Log reports are stored in] (e.g C:\seclogs):
IF EXIST "%variable2%" echo This Directory has been Found. IF EXIST "%variable2%" GOTO FileBegin
IF NOT EXIST "%variable2%" echo You are required to re-enter a directory name that exists: IF NOT EXIST "%variable2%" goto Begin :BEGINEND
:FileBegin
Echo Outstring="incorrect">dval.vbs Echo StrDate=Wscript.arguments(0)>>dval.vbs Echo y = Mid(StrDate,1,4)>>dval.vbs Echo m = Mid(StrDate,5,2)>>dval.vbs Echo d = Mid(StrDate,7,2)>>dval.vbs Echo If (IsDate(y^&"/"^&m^&"/"^&d) ^<^> 0) Then Outstring="correct">>dval.vbs Echo Wscript.Echo Outstring>>dval.vbs
:loop
set /p variable="Please input filename (YYYYMMDD.txt) ?" pause For /f "delims=" %%A in ( 'dval.vbs "%variable%"' ) do set result=%%A pause Echo Date format %result% pause If /i not "%result%"=="correct" goto loop del c:\dval.vbs
Set variable="%variable3%".txt IF EXIST "%variable2%\%variable%" echo This file has been Found. IF EXIST "%variable2%\%variable%" GOTO START
IF NOT EXIST "%variable2%\%variable%" echo You are required to re-enter a file name that exists: IF NOT EXIST "%variable2%\%variable%" goto loop
:start
ECHO. ECHO 1. Generate Report for list of user logoffs ECHO 2. Generate Report for list of network logons ECHO 3. Generate Report for list of users who logged in and logged out ECHO 4. Generate Report for Special permissions assigned to new logon
:choice set choice= set /p choice=Type the number to print text: if not '%choice%'=='' set choice=%choice:~0,1% if '%choice%'=='1' goto loggedout if '%choice%'=='2' goto networklogon if '%choice%'=='3' goto nwlogin_loggedout_users if '%choice%'=='4' goto specialprivs
ECHO "%choice%" is not valid please try again ECHO. goto choice
:loggedout echo Please wait while the report gets created.. find /n ",538," %variable2%\%variable% > %variable2%\userlogout_%Variable% SET /p dummy=%variable2%\userlogout_%variable% file has now been generated.. Press return to exit echo Goodbye. goto end1
:networklogon echo Please wait while the report gets created.. findstr /n ",540," %variable2%\%variable% > %variable2%\networklogon_%Variable% echo %variable2%\networklogon_%variable% has been generated. pause goto end1
:nwlogin_loggedout_users echo Please wait while the report gets created.. mkdir "%variable2%\tmp" find /n ",540," %variable2%\%variable% > %variable2%\tmp\logonlogout_%Variable%.tmp find /n ",538," %variable2%\tmp\logonlogout_%Variable%.tmp > %variable2%\logonlogout_%Variable% del /f %variable2%\tmp\logonlogout_%Variable%.tmp echo C:\logonlogout_%variable% has been generated. pause goto end1
:specialprivs echo Please wait while the report gets created.. find /n ",576," %variable2%\%variable% > %variable2%\specialprivs_%Variable% echo %variable2%\specialprivs_%variable% has been generated. pause goto end1 :end1Still not working on my end for some reason Cannot get the variable to show at all
Code: [Select]Set variable="%variable3%".txt What does this line do?
Code: [Select]echo off
:BEGIN SET /p variable2=[Enter directory that Security Log reports are stored in] (e.g C:\seclogs):
IF EXIST "%variable2%" echo This Directory has been Found. IF EXIST "%variable2%" GOTO FileBegin
IF NOT EXIST "%variable2%" echo You are required to re-enter a directory name that exists: IF NOT EXIST "%variable2%" goto Begin :BEGINEND
:FileBegin
Echo Outstring="incorrect">dval.vbs Echo StrDate=Wscript.arguments(0)>>dval.vbs Echo y = Mid(StrDate,1,4)>>dval.vbs Echo m = Mid(StrDate,5,2)>>dval.vbs Echo d = Mid(StrDate,7,2)>>dval.vbs Echo If (IsDate(y^&"/"^&m^&"/"^&d) ^<^> 0) Then Outstring="correct">>dval.vbs Echo Wscript.Echo Outstring>>dval.vbs
:loop
set /p variable="Please input filename (YYYYMMDD.txt) ?" For /f "delims=" %%A in ( 'dval.vbs "%variable%"' ) do set result=%%A Echo Date format %result% If /i not "%result%"=="correct" goto loop
IF EXIST "%variable2%\%variable%" ( echo This file has been Found goto start )
echo File "%variable2%\%variable%" not found echo You are required to re-enter a file name that exists: goto loop
:start
ECHO. ECHO 1. Generate Report for list of user logoffs ECHO 2. Generate Report for list of network logons ECHO 3. Generate Report for list of users who logged in and logged out ECHO 4. Generate Report for Special permissions assigned to new logon
:choice set choice= set /p choice=Type the number to print text: if not '%choice%'=='' set choice=%choice:~0,1% if '%choice%'=='1' goto loggedout if '%choice%'=='2' goto networklogon if '%choice%'=='3' goto nwlogin_loggedout_users if '%choice%'=='4' goto specialprivs
ECHO "%choice%" is not valid please try again ECHO. goto choice
:loggedout echo Please wait while the report gets created.. find /n ",538," %variable2%\%variable% > %variable2%\userlogout_%Variable% SET /p dummy=%variable2%\userlogout_%variable% file has now been generated.. Press return to exit echo Goodbye. goto end1
:networklogon echo Please wait while the report gets created.. findstr /n ",540," %variable2%\%variable% > %variable2%\networklogon_%Variable% echo %variable2%\networklogon_%variable% has been generated. pause goto end1
:nwlogin_loggedout_users echo Please wait while the report gets created.. mkdir "%variable2%\tmp" find /n ",540," %variable2%\%variable% > %variable2%\tmp\logonlogout_%Variable%.tmp find /n ",538," %variable2%\tmp\logonlogout_%Variable%.tmp > %variable2%\logonlogout_%Variable% del /f %variable2%\tmp\logonlogout_%Variable%.tmp echo C:\logonlogout_%variable% has been generated. pause goto end1
:specialprivs echo Please wait while the report gets created.. find /n ",576," %variable2%\%variable% > %variable2%\specialprivs_%Variable% echo %variable2%\specialprivs_%variable% has been generated. pause goto end1 :end1Ah I'm still confused. I'm not sure why the variable is still not displaying. Thanks for your help.
Code: [Select][Enter directory that Security Log reports are stored in] (e.g C:\seclogs):s:\test This Directory has been Found. Please input filename (YYYYMMDD.txt) ?20091130.txt Date format correct This file has been Found
1. Generate Report for list of user logoffs 2. Generate Report for list of network logons 3. Generate Report for list of users who logged in and logged out 4. Generate Report for Special permissions assigned to new logon Type the number to print text:
Alright, I've got it working apart from an error on this line: for /f "delims=" %%A in ( 'cscript c:\dval.vbs "%variable%"' ) do set result=%%A
It says that 'The filename, directory name, or volume label syntax is incorrect'.
Any ideas?The vbs script is not being found. The batch is writing it to dval.vbs i.e. in the current directory (the same directory that the batch is in) but you have coded the calling line to look for c:\dval.vbs
EITHER: change all these dval.vbs to c:\dval.vbs
Code: [Select]Echo Outstring="incorrect">dval.vbs Echo StrDate=Wscript.arguments(0)>>dval.vbs Echo y = Mid(StrDate,1,4)>>dval.vbs Echo m = Mid(StrDate,5,2)>>dval.vbs Echo d = Mid(StrDate,7,2)>>dval.vbs Echo If (IsDate(y^&"/"^&m^&"/"^&d) ^<^> 0) Then Outstring="correct">>dval.vbs Echo Wscript.Echo Outstring>>dval.vbs OR: change c:\dval.vbs to dval.vbs
Code: [Select]for /f "delims=" %%A in ( 'cscript c:\dval.vbs "%variable%"' ) do set result=%%AHi ya, Thanks for all the information. I got it working anyway and it seems to be fine now. I disregarded the cb script popup boxes that displayed "incorrect" and "correct" and printed it out within the batch program.
I may have to do more complex things with these reports, like strip off certain information from the actual log text files. Is Perl the best to generate these kind of reports? Thanks, Laura
Quote from: newuserlh on DECEMBER 01, 2009, 05:41:55 AM I disregarded the cb script popup boxes that displayed "incorrect" and "correct" and printed it out within the batch program.
That is a clue that you are running the script with wscript.exe and not cscript.exe which explains the lack of output you were experiencing.
You are using the command
cscript.exe //nologo before the vbs script name?
Yeah it's running cscript now. I had issues with the output there and changed the DELIM line. It's sorted out now thankfully.
|