#200072 - 2010-09-27 05:27 PM
How to prevent character echo
|
StuR
Fresh Scripter
Registered: 2010-09-27
Posts: 7
Loc: Dallas, Texas
|
While I can prevent character echo with the REDIRECTOUTPUT command, as soon as I re-enable output, I get numeric character echo on the console.
Here's an example script:
;--------------------------------
$out = GETCHR("Enter password: ") $out = GETCHR("Enter it again: ") exit
Function GetChr($prompt) ? $prompt REDIRECTOUTPUT("NUL") GET $cmd FLUSHKB REDIRECTOUTPUT("") EndFunction
;--------------------------
Regards, Stuart.
|
|
Top
|
|
|
|
#200074 - 2010-09-27 07:51 PM
Re: How to prevent character echo
[Re: Allen]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
Welcome to KORG!
You're not catching the return codes, as Allen pointed out with the reference to the FAQ. You might want to use a UDF to gather the input so the password doesn't echo to the screen, such as:;;
;;======================================================================
;;
;;FUNCTION GetStr()
;;
;;ACTION returns a string, according to defined rules
;;
;;AUTHOR Glenn Barnas
;;
;;VERSION 1.0 / 2001/11/14
;;
;;SYNTAX GetStr(Count, [Secure],[Allowed])
;;
;;PARAMETERS Count - REQUIRED - specifies how many chars can be accepted
;; Secure - OPTIONAL - Char to display instead of the chars typed
;; Allowed - Optional - a string defining which chars will be accepted.
;;
;;REMARKS
;;
;;RETURNS String
;;
;;DEPENDENCIES none
;;
;;TESTED WITH W2K, WXP, W2K3
;;
;;EXAMPLES
;;
Function GetStr($_Count, Optional $_Secure, OPTIONAL $_Allowed)
Dim $_CC, $_SF, $_PC
$_CC = 0 ; character count
$GetStr = '' ; init return string
$_SF = 1 ; string flag
; include backspace and return in string of allowed characters
If $_Allowed <> ''
$_Allowed = $_Allowed + Chr(8) + Chr(13)
EndIf
While $_SF ; loop until done
Get $_PC ; get 1 character
If $_Allowed <> '' ; If allowed string is defined
If InStr($_Allowed, $_PC) = 0 ;And ($_PC <> Chr(13) or $_PC <> Chr(8))
$_PC = '' ; char must be one of allowed
EndIf
EndIf
Select
Case $_PC = Chr(8) ; handle backspace
Chr(8) + ' ' + Chr(8) ; erase character
$_CC = $_CC - 1 ; reduce count
If $_CC > 0 ; shorten or clear string
$GetStr = Left($GetStr, $_CC)
Else
$GetStr = ''
EndIf
Case $_PC = Chr(13) ; handle Return
$_SF = 0
Case $_PC = '' ; handle non-allowed chars
Beep
Case 1 ; got a char
If $_Secure
$_Secure ; print alt char if secure
Else
$_PC ; otherwise print the char
EndIf
$GetStr = $GetStr + $_PC ; add it to the string
$_CC = $_CC + 1 ; increment char count
EndSelect
; Exit if character-count is reached
If $_Count > 0 and $_CC = $_Count
$_SF = 0
EndIf
Loop
Exit 0
EndFunction Using ' Enter password: '
$Pw1 = GetStr(99,'*')
@CRLF
'Confirm password: '
$Pw2 = GetStr(99,'*')
@CRLF
If $Pw1 <> $Pw2
'Passwords do not match!' @CRLF
EndIf Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#200075 - 2010-09-27 07:58 PM
Re: How to prevent character echo
[Re: Allen]
|
StuR
Fresh Scripter
Registered: 2010-09-27
Posts: 7
Loc: Dallas, Texas
|
Thanks Glenn. Finally hit me! I wasn't using the $x = Function() form of the command! Duh...
p.s. I started using Kix back in 1998 under WinNT 3.1 and recently started using it again this time under Win PE 3.0. Love the Kix2Exe tool too!
Regards
Stuart.
Edited by StuR (2010-09-27 08:22 PM)
|
|
Top
|
|
|
|
#200079 - 2010-09-28 03:21 AM
Re: How to prevent character echo
[Re: StuR]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
1998 - and it only took you 12 years to join us? Better late then never, I guess!
I'm just wrapping up a large PE 3.0 based deployment project that uses Kix scripts to prep the HD, deploy a WIM image (one if 2k3, two if 2k8/W7 for Sys and Boot), and then perform an automated system build after the installer answers a few questions about what role the server will play, the languages to install, hostname, IP settings, and such. The image, install tool, and several application packages and hotfixes that must be installed before network connection are all on the PE disk. Just one DVD to init, lay down the image, add/remove components, apply security policy, and install apps...
The PE 3.0 is a breeze to work with - I've really enjoyed working with it compared to Bart and other PE versions.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#200081 - 2010-09-28 11:51 AM
Re: How to prevent character echo
[Re: Glenn Barnas]
|
BradV
Seasoned Scripter
  
Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
|
Windows PE? Windows Peasant Edition? I just googled it. Never heard of it till now. See, you can learn something new.
|
|
Top
|
|
|
|
#200100 - 2010-09-29 04:41 PM
Re: How to prevent character echo
[Re: Glenn Barnas]
|
StuR
Fresh Scripter
Registered: 2010-09-27
Posts: 7
Loc: Dallas, Texas
|
1998 - and it only took you 12 years to join us?  Better late then never, I guess! I'm just wrapping up a large PE 3.0 based deployment project that uses Kix scripts to prep the HD, deploy a WIM image (one if 2k3, two if 2k8/W7 for Sys and Boot), and then perform an automated system build after the installer answers a few questions about what role the server will play, the languages to install, hostname, IP settings, and such. The image, install tool, and several application packages and hotfixes that must be installed before network connection are all on the PE disk. Just one DVD to init, lay down the image, add/remove components, apply security policy, and install apps... The PE 3.0 is a breeze to work with - I've really enjoyed working with it compared to Bart and other PE versions. Glenn
HA - I don't remember Internet forums being around back then. Guess they were.
BTW, I think I found a coding error (gasp) in that nice character input function you referenced in this thread.
Here's the code fragment in question:
Case $_PC = Chr(8) ; handle backspace Chr(8) + ' ' + Chr(8) ; erase character $_CC = $_CC - 1 ; reduce count If $_CC > 0 ; shorten or clear string $GetStr = Left($GetStr, $_CC) Else $GetStr = '' EndIf --------- And here's my modification to prevent overwriting the prompt string with backspace characters when the string is empty:
Case $_PC = Chr(8) ; handle backspace If $_CC > 0 ; shorten or clear string $_CC = $_CC - 1 ; reduce count $GetStr = Left($GetStr, $_CC) Chr(8) + ' ' + Chr(8) ; erase character Else $GetStr = '' EndIf
---------------
Regards,
Stuart.
|
|
Top
|
|
|
|
#200104 - 2010-09-29 05:26 PM
Re: How to prevent character echo
[Re: Glenn Barnas]
|
StuR
Fresh Scripter
Registered: 2010-09-27
Posts: 7
Loc: Dallas, Texas
|
Wow - thanks! I wrote that back in 2001 or so and really rarely used it since.. just had it in the toolchest. I'll make the update.
Glenn
It fit the bill perfectly for me as I needed a password function. Very nicely done.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 483 anonymous users online.
|
|
|