Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Force user to enter correct file format [YYYYMMDD.txt]  (Read 9747 times)

0 Members and 1 Guest are viewing this topic.

newuserlh

    Topic Starter


    Rookie

    Force user to enter correct file format [YYYYMMDD.txt]
    « on: November 28, 2009, 10:46:20 AM »
    Hi all

    Thanks for all your help so far.
    I am looking to force user to re-enter the yyyymmdd.txt file if  input is wrong:

    Set objFS=CreateObject("Scripting.FileSystemObject")

    WScript.Echo "Enter log file date (YYYYMMDD.txt):"
       Do While Not WScript.StdIn.AtEndOfLine
          strFile = strFile & WScript.StdIn.Read(1)
       Loop
    s = Split(strFile,".")
    yr = Mid(s(0),1,4)
    mth = Mid(s(0),5,2)
    dy = Mid(s(0),7,2)

    If  (IsDate(yr&"/"&mth&"/"&dy) <> 0) AND s(UBound(s)) = "txt" Then
       WScript.Echo "Valid date and file extension"
       WScript.Echo yr&"/"&mth&"/"&dy&".txt"

       

    Else
       WScript.Echo "Invalid date and/or file extension"     
        WScript.Echo "Enter log file date (YYYYMMDD.txt):"
       Do While Not WScript.StdIn.AtEndOfLine
          strFile = strFile & WScript.StdIn.Read(1)
       Loop

    End if

    Is it a Do until loop? I'm not sure how to go about this one. I haven't programmed in this for a while!
    Also, when I want to pass this variable out to another batch program, is it just something like:
    wshshell.run "C:\test.bat " yr&"/"&mth&"/"&dy&".txt"  ??

    Thanks,
    Laura


    Salmon Trout

    • Guest
    Re: Force user to enter correct file format [YYYYMMDD.txt]
    « Reply #1 on: November 28, 2009, 12:09:27 PM »
    Code: [Select]
    Do While Valid=False
            Wscript.StdOut.Write "Filename (YYYYMMDD.txt) ? "
            strFile = Wscript.StdIn.ReadLine
            s = Split(strFile,".")
            yr = Mid(s(0),1,4)
            mth = Mid(s(0),5,2)
            dy = Mid(s(0),7,2)
            If  (IsDate(yr&"/"&mth&"/"&dy) <> 0) AND s(UBound(s)) = "txt" Then
                    Valid=True
            Else
                    Wscript.Echo "Incorrect input data"
            End If 
    Loop
    Wscript.Echo yr&mth&dy&".txt"

       

    I prefer to use

    wscript.StdOut.Write "Prompt"
    answer=Wscript.StdIn.ReadLine

    because then the user can type the answer on the same line as the question

    Note that you cannot have a filenames with slashes so I removed them.

    You can use FOR with single quotes like this to get the console output of the vbs (or any command or program) into a batch variable

    for /f "delims=" %%A in ( ' cscript //nologo scriptname.vbs ' ) do set inputfilename=%%A


    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Force user to enter correct file format [YYYYMMDD.txt]
    « Reply #2 on: November 28, 2009, 12:25:24 PM »
    If you Google:
    how to validate a date
    You will find there a re java scripts that do this.
    But, if you want it it batch...
    there are experts here who will help you.
    Just wait a bit. They took the weekend off. ;D

    newuserlh

      Topic Starter


      Rookie

      Re: Force user to enter correct file format [YYYYMMDD.txt]
      « Reply #3 on: November 28, 2009, 01:28:32 PM »
      Hi Salmon trout,

      Thanks for your useful response.
      I have tried your code and I'm getting an error back on one of the lines of code saying: Dates .vbs (7,1) ms runtime error:Subscript out of range [number:0]'
      Would this have anything to do with removing the "/" ?

      Also, for:
      for /f "delims=" %%A in ( ' cscript //nologo scriptname.vbs ' ) do set inputfilename=%%A
      I have set the variable to "variable" in my batch program.
      So Am I passing Wscript.Echo yr&mth&dy&".txt" here?



      Salmon Trout

      • Guest
      Re: Force user to enter correct file format [YYYYMMDD.txt]
      « Reply #4 on: November 28, 2009, 02:10:36 PM »
      valdate.vbs

      Code: [Select]
      Strfile=Wscript.arguments(0)
      s = Split(strFile,".")
      yr = Mid(s(0),1,4)
      mth = Mid(s(0),5,2)
      dy = Mid(s(0),7,2)
      If  (IsDate(yr&"/"&mth&"/"&dy) <> 0) AND s(UBound(s)) = "txt" Then
          Outstring="correct"
      Else
          Outstring="incorrect"
      End If 
      Wscript.Echo  Outstring

      batch code

      Code: [Select]
      @echo off
      :getname
      set /p inputfilename="Please input filename (YYYYMMDD.txt) ?"
      for /f "delims=" %%A in ( ' cscript //nologo valdate.vbs "%inputfilename%" ' ) do set result=%%A
      echo Filename format %result%
      if not "%result%"=="correct" goto getname
      REM code to run if filename is valid format goes here
      « Last Edit: November 28, 2009, 02:27:09 PM by Salmon Trout »

      Salmon Trout

      • Guest
      Re: Force user to enter correct file format [YYYYMMDD.txt]
      « Reply #5 on: November 28, 2009, 03:02:38 PM »
      I do not understand why you ask the user to input the .txt extension and then go to the trouble of validating it. I think it is adding unnecessary complication and inviting avoidable errors, as well as being sloppy programming, to ask the user for something which you know already. Why not just ask for the YYYYMMDD part, validate that, and then add the .txt part yourself?

      In fact you can make the batch write the vbs as well


      Code: [Select]
      @echo off
      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 UserInputDate="Date in format YYYYMMDD ? "
      For /f "delims=" %%A in ( 'dval.vbs "%UserInputDate%"' ) do set result=%%A
      del dval.vbs
      Echo Date format %result%
      If /i not "%result%"=="correct" goto loop
      Rem code to run if filename is valid format goes here
      Set filename=%UserInputDate%.txt
      « Last Edit: November 29, 2009, 02:43:51 AM by Salmon Trout »

      gh0std0g74



        Apprentice

        Thanked: 37
        Re: Force user to enter correct file format [YYYYMMDD.txt]
        « Reply #6 on: November 29, 2009, 07:08:42 AM »
        In fact you can make the batch write the vbs as well
        i don't understand why anyone would want to write this way. Its ugly and not easy to maintain. And do you need to create the script on the fly each time ? Just $0.02

        Salmon Trout

        • Guest
        Re: Force user to enter correct file format [YYYYMMDD.txt]
        « Reply #7 on: November 29, 2009, 07:40:59 AM »
        i don't understand why anyone would want to write this way. Its ugly and not easy to maintain. And do you need to create the script on the fly each time ? Just $0.02

        I agree, it is ugly and I don't generally do things this way myself, but there are people around seem to prefer that way of doing this sort of job, who see a vbscript as a kind of black box which extends batch capabilities.

        newuserlh

          Topic Starter


          Rookie

          Re: Force user to enter correct file format [YYYYMMDD.txt]
          « Reply #8 on: November 29, 2009, 04:02:23 PM »
          Hi guys,
          I understand what you mean about this. To be honest, this is a script that may be run on a ad-hoc basis, and will not require to be automated at all.
          The is parsing through a daily security log (20090930.txt for example), and I'm looking to get various meaningful reports out of them.. e.g Log on, log off information, special priviledges etc.
          I never even knew you could write in vbs with batch until now, so I guess I got a little carried away with it.

          You're great on this forum, thanks alot for your help.
          Laura

          gh0std0g74



            Apprentice

            Thanked: 37
            Re: Force user to enter correct file format [YYYYMMDD.txt]
            « Reply #9 on: November 29, 2009, 05:40:13 PM »
            Hi guys,
            I understand what you mean about this. To be honest, this is a script that may be run on a ad-hoc basis, and will not require to be automated at all.
            The is parsing through a daily security log (20090930.txt for example), and I'm looking to get various meaningful reports out of them.. e.g Log on, log off information, special priviledges etc.
            I never even knew you could write in vbs with batch until now, so I guess I got a little carried away with it.

            You're great on this forum, thanks alot for your help.
            Laura
            if you are going to be parsing a lot, then please do go and learn vbscript. It will make your parsing job easier. You can ditch batch for parsing tasks. Even better, if you have the privilege to do this, learn a better programming language, eg Perl/Python. they are good tools for sysadmin tasks...

            Geek-9pm


              Mastermind
            • Geek After Dark
            • Thanked: 1026
              • Gekk9pm bnlog
            • Certifications: List
            • Computer: Specs
            • Experience: Expert
            • OS: Windows 10
            Re: Force user to enter correct file format [YYYYMMDD.txt]
            « Reply #10 on: November 29, 2009, 09:41:04 PM »
            i don't understand why anyone would want to write this way. Its ugly and not easy to maintain. And do you need to create the script on the fly each time ? Just $0.02
            Because people like me can understand it. It is all in one place, no need to maintain two or more separate files. MS-DOS does not have an effective way to tie files together as pairs or triplets. So you need to put it all into one file.
            I hate it when a process has a bunch of files that are not bound together as a package.

            gh0std0g74



              Apprentice

              Thanked: 37
              Re: Force user to enter correct file format [YYYYMMDD.txt]
              « Reply #11 on: November 29, 2009, 10:00:43 PM »
              Because people like me can understand it. It is all in one place, no need to maintain two or more separate files.
              Not logical. If you want to talk about all in one place, why not all do in one language. Its cleaner and easier to troubleshoot/debug. Also, there are special steps you need to take in order to do hybrids of batch and vbs. Eg, taking care of escaping special characters used in vbscript. This makes your code even uglier. Putting batch and vbs together like that is cause for future trouble.

              Quote
              MS-DOS does not have an effective way to tie files together as pairs or triplets. So you need to put it all into one file.
              I hate it when a process has a bunch of files that are not bound together as a package.
              that's why there's a thing called "a better language"

              BC_Programmer


                Mastermind
              • Typing is no substitute for thinking.
              • Thanked: 1140
                • Yes
                • Yes
                • BC-Programming.com
              • Certifications: List
              • Computer: Specs
              • Experience: Beginner
              • OS: Windows 11
              Re: Force user to enter correct file format [YYYYMMDD.txt]
              « Reply #12 on: November 30, 2009, 03:09:34 AM »
              besides; even writing a VBS with batch, your still maintaining two files anyway; you just have to deduce for yourself what parts of the batch are really batch and which aren't.

              I was trying to dereference Null Pointers before it was cool.

              newuserlh

                Topic Starter


                Rookie

                Re: Force user to enter correct file format [YYYYMMDD.txt]
                « Reply #13 on: November 30, 2009, 05:19:48 AM »
                I do not understand why you ask the user to input the .txt extension and then go to the trouble of validating it. I think it is adding unnecessary complication and inviting avoidable errors, as well as being sloppy programming, to ask the user for something which you know already. Why not just ask for the YYYYMMDD part, validate that, and then add the .txt part yourself?

                In fact you can make the batch write the vbs as well


                Code: [Select]
                @echo off
                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 UserInputDate="Date in format YYYYMMDD ? "
                For /f "delims=" %%A in ( 'dval.vbs "%UserInputDate%"' ) do set result=%%A
                del dval.vbs
                Echo Date format %result%
                If /i not "%result%"=="correct" goto loop
                Rem code to run if filename is valid format goes here
                Set filename=%UserInputDate%.txt


                Hi there, Just on the 'Echo Date format %result%' line, it doesn't get printed on the screen for some reason, making the validation not correctly work.  The %result% does not get displayed on the screen for some reason.
                Is there some reason for this?

                Salmon Trout

                • Guest
                Re: Force user to enter correct file format [YYYYMMDD.txt]
                « Reply #14 on: November 30, 2009, 05:25:25 AM »
                Fixed an error which may or may not cause your problem - please try

                Code: [Select]
                @echo off
                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 UserInputDate="Date in format YYYYMMDD ? "
                For /f "delims=" %%A in ( 'dval.vbs "%UserInputDate%"' ) do set result=%%A
                Echo Date format %result%
                If /i not "%result%"=="correct" goto loop
                del dval.vbs
                Rem code to run if filename is valid format goes here
                Set filename=%UserInputDate%.txt


                newuserlh

                  Topic Starter


                  Rookie

                  Re: Force user to enter correct file format [YYYYMMDD.txt]
                  « Reply #15 on: November 30, 2009, 05:39:53 AM »
                  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.


                  Salmon Trout

                  • Guest
                  Re: Force user to enter correct file format [YYYYMMDD.txt]
                  « Reply #16 on: November 30, 2009, 05:46:59 AM »
                  Are you using the code inside a larger batch file, possibly in a loop?


                  newuserlh

                    Topic Starter


                    Rookie

                    Re: Force user to enter correct file format [YYYYMMDD.txt]
                    « Reply #17 on: November 30, 2009, 05:59:14 AM »
                    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

                    Salmon Trout

                    • Guest
                    Re: Force user to enter correct file format [YYYYMMDD.txt]
                    « Reply #18 on: November 30, 2009, 06:06:07 AM »
                    @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
                    :end1

                    newuserlh

                      Topic Starter


                      Rookie

                      Re: Force user to enter correct file format [YYYYMMDD.txt]
                      « Reply #19 on: November 30, 2009, 06:11:48 AM »
                      Still not working on my end for some reason  ???
                      Cannot get the variable to show at all  >:(

                      Salmon Trout

                      • Guest
                      Re: Force user to enter correct file format [YYYYMMDD.txt]
                      « Reply #20 on: November 30, 2009, 06:14:48 AM »
                      Code: [Select]
                      Set variable="%variable3%".txt
                      What does this line do?
                      « Last Edit: November 30, 2009, 06:29:58 AM by Salmon Trout »

                      Salmon Trout

                      • Guest
                      Re: Force user to enter correct file format [YYYYMMDD.txt]
                      « Reply #21 on: November 30, 2009, 06:39:28 AM »
                      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
                      :end1

                      newuserlh

                        Topic Starter


                        Rookie

                        Re: Force user to enter correct file format [YYYYMMDD.txt]
                        « Reply #22 on: November 30, 2009, 06:48:52 AM »
                        Ah I'm still confused. I'm not sure why the variable is still not displaying.
                        Thanks for your help.

                        Salmon Trout

                        • Guest
                        Re: Force user to enter correct file format [YYYYMMDD.txt]
                        « Reply #23 on: November 30, 2009, 06:52:32 AM »
                        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:


                        newuserlh

                          Topic Starter


                          Rookie

                          Re: Force user to enter correct file format [YYYYMMDD.txt]
                          « Reply #24 on: November 30, 2009, 07:34:22 AM »

                          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?

                          Salmon Trout

                          • Guest
                          Re: Force user to enter correct file format [YYYYMMDD.txt]
                          « Reply #25 on: November 30, 2009, 07:46:36 AM »
                          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=%%A

                          newuserlh

                            Topic Starter


                            Rookie

                            Re: Force user to enter correct file format [YYYYMMDD.txt]
                            « Reply #26 on: December 01, 2009, 05:41:55 AM »
                            Hi 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

                            Salmon Trout

                            • Guest
                            Re: Force user to enter correct file format [YYYYMMDD.txt]
                            « Reply #27 on: December 01, 2009, 06:05:23 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?


                            newuserlh

                              Topic Starter


                              Rookie

                              Re: Force user to enter correct file format [YYYYMMDD.txt]
                              « Reply #28 on: December 01, 2009, 06:34:10 AM »
                              Yeah it's running cscript now.  I had issues with the output there and changed the delim line.
                              It's sorted out now thankfully.