Loading ...
Sorry, an error occurred while loading the content.

re : getting a batchfile to prompt user for a password

Expand Messages
  • Derek Byrne
    Hi, I m wondering if its possible to get a batch file to prompt a user for an input, and take that input and use it in the rest of the batch file. So far, I
    Message 1 of 3 , Jul 1, 2002
    • 0 Attachment
      Hi,
      I'm wondering if its possible to get a batch file to prompt a user for an
      input, and take that input and use it in the rest of the batch file.
      So far, I have the following batch file setup, but it requires me to edit
      the batch file first to update the password.

      @echo off
      set password=blah
      net use z: \\server\path /user:domain\administrator %password%

      This works fine, but was wondering if I could get the batch file to ask me
      for the admin password, as I don't like keeping passwords in
      unprotected/insecure batch files.

      Thanks,

      DerekB


      Meteor Web Site : Http://www.meteor.ie
      **********************************************************************
      This email and any files transmitted with it are confidential and
      intended solely for the use of the individual or entity to whom they
      are addressed. If you have received this email in error please notify
      the system manager.

      This footnote also confirms that this email message has been swept by
      MIMEsweeper for the presence of computer viruses.

      www.mimesweeper.com
      **********************************************************************
    • Michael Marquart
      W2k/XP @echo off set /p password=Enter Admin Password: net use z: server path /user:domain administrator %password% On Mon, 1 Jul 2002 13:25:03 +0100, Derek
      Message 2 of 3 , Jul 1, 2002
      • 0 Attachment
        W2k/XP

        @echo off
        set /p password=Enter Admin Password:
        net use z: \\server\path /user:domain\administrator %password%




        On Mon, 1 Jul 2002 13:25:03 +0100, Derek Byrne <Derek.Byrne@...>
        wrote:

        >Hi,
        > I'm wondering if its possible to get a batch file to prompt a user for an
        >input, and take that input and use it in the rest of the batch file.
        > So far, I have the following batch file setup, but it requires me to edit
        >the batch file first to update the password.
        >
        > @echo off
        > set password=blah
        > net use z: \\server\path /user:domain\administrator %password%
        >
        > This works fine, but was wondering if I could get the batch file to ask me
        >for the admin password, as I don't like keeping passwords in
        >unprotected/insecure batch files.
        >
        > Thanks,
        >
        >DerekB
      • Bob Bissinnar
        At 01:25 PM 7/1/2002 +0100, Derek Byrne Writes ... Greetings Derek, I enjoy putting scripts in my batches to prompt for input and have listed below some that
        Message 3 of 3 , Jul 1, 2002
        • 0 Attachment
          At 01:25 PM 7/1/2002 +0100, Derek Byrne Writes
          > I'm wondering if its possible to get a batch file to prompt a user for an
          >input, and take that input and use it in the rest of the batch file.
          > So far, I have the following batch file setup, but it requires me to edit
          >the batch file first to update the password.

          Greetings Derek,

          I enjoy putting scripts in my batches to prompt for input and have listed below
          some that I've used in the past.

          I want to point out that I use Win98 and I am the only user so I have not
          tested
          these batch files in other OS's or with multiple users. (I do this for fun!)

          Maybe one of these days I'll move up to W2k and made use of the batch
          enhancements
          as demonstrated in Michael Marquart's example. <grin>

          My personal favorite is Timo Salmi's use of Qbasic for a password!

          Good luck and best wishes!

          ####### Using AWK OR GAWK
          @echo off
          echo Type Your Password and Press Enter:
          awk "BEGIN{getline;print \"set pwd=\"$0;exit}">%temp%.\_tmp$$$.bat
          for %%c in (call del) do %%c %temp%.\_tmp$$$.bat
          echo Your Password is [%pwd%]
          set pwd=

          ####### Using Qbasic
          ::Timo Salmi's Batch Faq. Source Item #148
          ::ftp://ftp.garbo.uwasa.fi/pc/link/tsbat.zip
          @echo off
          echo %0 | find /i ".bat" > nul
          set prog_=%0
          if errorlevel==1 set prog_=%0.bat
          set skip=
          find "'Q%skip%B" <%prog_% > tmp$$$.bas
          goto _jump
          PRINT "Type Your Password and Press Enter: "; 'QB
          DO UNTIL 1 = 2 'QB
          LET a$ = INKEY$ 'QB
          IF NOT LEN(a$) = 0 THEN 'QB
          IF ASC(a$) = 13 THEN GOTO 1 'QB
          PRINT "*"; 'QB
          LET w$ = w$ + a$ 'QB
          END IF 'QB
          LOOP 'QB
          1 OPEN "tmp$$$.bat" FOR OUTPUT AS #1 'QB
          PRINT #1, "@set pwd=" + w$ 'QB
          CLOSE #1 'QB
          SYSTEM 'QB
          :_jump
          qbasic /run tmp$$$.bas
          call tmp$$$.bat
          echo.
          cls
          echo Your Password is [%pwd%]
          for %%f in (tmp$$$.bas tmp$$$.bat) do if exist %%f del %%f
          for %%v in (prog_ pwd) do set %%v=

          ####### Using FC
          @echo off
          ::Adaptation of a routine by Tom Lavedas to get user input. Source
          ::http://www.pressroom.com/~tglbatch/
          echo Type Your Password and Press Enter:
          fc con nul /LB1 /n |date |find "1:"> %temp%.\set_pwd.bat
          echo :loop > %temp%.\enter.bat
          echo set pwd=%%5>> %temp%.\enter.bat
          echo SHIFT >> %temp%.\enter.bat
          echo if not "%%5"=="" goto loop >> %temp%.\enter.bat
          path> %temp%.\tmp_path.bat
          path %temp%.\;%path%
          for %%c in (call del) do %%c %temp%.\set_pwd.bat
          for %%c in (call del) do %%c %temp%.\tmp_path.bat
          del %temp%.\enter.bat
          echo Your Password is [%pwd%]
          set pwd=

          ####### Using SED
          ::Batch file will not run with sed15, I used
          ::sed302b ren to sed.exe
          ::ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/sed302b.zip
          @echo off
          echo Type Your Password and Press Enter:
          sed -n "s/^/Set pwd=/p;q">%temp%.\_tmp$$$.bat
          for %%c in (call del) do %%c %temp%.\_tmp$$$.bat
          echo Your Password is [%pwd%]
          set pwd=

          ####### Using Win95cmd
          @echo off
          echo.@set /P input=Type Your Password and Press Enter: >%temp%.\input.bat
          echo.@... pwd=%%input%%%%"%%>%%"%%%temp%.\_marker$.bat>>%temp%.\input.bat
          win95cmd /c %temp%.\input.bat
          call %temp%.\_marker$.bat
          echo Your Password is [%pwd%]
          for %%a in (%temp%.\_marker$ %temp%.\input) do if exist %%a.bat del %%a.bat
          set pwd=

          ####### Using Windows Scripting
          ::Source http://www.fpschultze.de/bsh.htm#a14
          ::Frank-Peter Schultze
          @echo off
          set amp=&
          if '==%amp%' set amp=^^^&
          echo wscript.echo "set pwd=" %amp% inputbox("Type Your Password and Press
          Enter or Click OK","Password")>%temp%.\$tmpo.vbs
          cscript //nologo //I %temp%.\$tmpo.vbs > %temp%.\$tmpo.bat
          call %temp%.\$tmpo.bat
          del %temp%.\$tmpo.*
          echo Your password is %pwd%
          for %%a in (amp pwd) do set %%a=




          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.