none
Simple CMD Batch Script : Prompt for a Password and hide it. RRS feed

  • Question

  • I am sure this will be very easy for you clever scripting guys out there, here's a couple of questions.

    I have wrote this little script for some wireless laptops that we are not going to join our domain, but we'd like our students to access to thier home drives, and shared resources.

    ===============================
    echo off
    net use z: /delete
    net use t: /delete
    echo                Your Intake Year                                                                       
    echo    Y7=2008      Y8=2007      Y9=2006      Y10=2005      Y11=2004
    echo  Please type your Intake Year below
    set /p Group=
    echo        Please Type your Username  (example astudent120589)
    echo Please Type your Username
    set /p usern=
    echo "Please Type your Password"
    set /p password=
    echo Your username is %usern%
    echo Your Group is %Group%
    pause
    net use Z: "\\Server\User Storage\Pupils\%Group%\%usern%" /User:ourdomaim\%usern% %password% /PERSISTENT:NO
    net use T: "\\Server\student shared$" /User:ourdomain\%usern% %password% /PERSISTENT:NO

    ================================

    1. It works but i'd prefer to hide the password as they type it? is it possible?
    2. I'd also prefer to ask for thier year group, so they just type 7,8,9,10 or 11 instend of thier intake group, but I don't know how to script this?
    3. Also what is the command to set the path of MY documents to Z: drive, so applications trying to save will pick z: as it's default location.

    Any help or suggestions on how to improve this script would be great. 

    Thank you.

    Steve, Chaucer BEC, Sheffield UK 


    Steve Audus, Chaucer BEC, Sheffield, UK
    Saturday, February 28, 2009 4:13 PM

Answers

  • There's an old Scripting Guy post which shows you a VBScript solution for this - but it won't work in Vista and above.
    Here's a quick HTA I wrote though which should do the trick.

    <html>
    <head>
    <title>Drive Mapper</title>
    <HTA:APPLICATION 
         APPLICATIONNAME="Drive Mapper"
         SCROLL="no"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="normal"
    >
    <STYLE>
    body {
    	padding-top:20px;
    	text-align:center;
    }
    td,input	{
    	font-family:Verdana;
    	font-size:12pt;
    }
    a	{
    	font-size:9pt;
    	font-family:Verdana;
    }
    </STYLE>
    <SCRIPT LANGUAGE=VBScript>
    Set objNetwork = CreateObject("Wscript.Network")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Sub Window_OnLoad
    	Dim X, Y, strComputer, objWMIService, colItems, objItem, intHorizontal, strYear
    	X=500
    	Y=300
    	window.resizeTo X,Y
    		' resize the HTA
    	strComputer = "."
    	Set objWMIService = GetObject("Winmgmts:\\" & strComputer & "\root\cimv2")
    	Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
    	For Each objItem in colItems
    		intHorizontal = objItem.ScreenWidth
    		intVertical = objItem.ScreenHeight
    	Next
    	window.moveTo (intHorizontal - X) / 2, (intVertical - Y) / 2
    		' centre it
    	txtName.value=objNetwork.UserName
    	txtName.focus
    End Sub
    
    Sub btnConfigure_OnClick
    	If txtName.value="" Then
    		MsgBox "Please enter your name",16,"ERROR"
    		txtName.focus
    		Exit Sub
    	End If
    	If txtPassword.value="" Then
    		MsgBox "Please enter your password",16,"ERROR"
    		txtPassword.focus
    		Exit Sub
    	End If	
    	MapDrive "Z:","\\Server\User Storage\Pupils\" & lisYear.value & "\" & txtName
    	MapDrive "T:","\\Server\student shared$"
    	MsgBox "Network resources have been mapped",64,"DONE"
    End Sub
    
    Sub MapDrive(DriveLetter,DrivePath)
    	If objFSO.DriveExists(DriveLetter) Then
    		objNetwork.RemoveNetworkDrive DriveLetter,true
    	End If
    	objNetwork.MapNetworkDrive DriveLetter, DrivePath, false, txtName.value,txtPassword.value
    End Sub
    </SCRIPT>
    </head>
    <body>
    <table>
    <tr>
    	<td>What is your intake year?</td>
    	<td><select size="1" name="lisYear" id="lisYear">
    			<option value="Y7">2008</option>
    			<option value="Y8">2007</option>
    			<option value="Y9">2006</option>
    			<option value="Y10">2005</option>
    			<option value="Y11">2004</option>
    		</select></td>
    </tr>
    
    <tr>
    	<td>What is your username?<br/><a>(example: astudent120589)</a></td>
    	<td><input type="text" name="txtName" /></td>
    </tr>
    
    <tr>
    	<td>What is your password?</td>
    	<td><input type="password" name="txtPassword" /></td>
    </tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td><td><input type="button" value="Configure resources" id=btnConfigure /></td></tr>
    </table>
    </body>
    </html>
    • Marked as answer by Steve Audus Wednesday, January 13, 2010 8:33 AM
    Tuesday, January 12, 2010 7:41 PM

All replies

  • Steve Audus said:

    I am sure this will be very easy for you clever scripting guys out there, here's a couple of questions.

    I have wrote this little script for some wireless laptops that we are not going to join our domain, but we'd like our students to access to thier home drives, and shared resources.

    ===============================
    echo off
    net use z: /delete
    net use t: /delete
    echo                Your Intake Year                                                                       
    echo    Y7=2008      Y8=2007      Y9=2006      Y10=2005      Y11=2004
    echo  Please type your Intake Year below
    set /p Group=
    echo        Please Type your Username  (example astudent120589)
    echo Please Type your Username
    set /p usern=
    echo "Please Type your Password"
    set /p password=
    echo Your username is %usern%
    echo Your Group is %Group%
    pause
    net use Z: "\\Server\User Storage\Pupils\%Group%\%usern%" /User:ourdomaim\%usern% %password% /PERSISTENT:NO
    net use T: "\\Server\student shared$" /User:ourdomain\%usern% %password% /PERSISTENT:NO

    ================================

    1. It works but i'd prefer to hide the password as they type it? is it possible?
    2. I'd also prefer to ask for thier year group, so they just type 7,8,9,10 or 11 instend of thier intake group, but I don't know how to script this?
    3. Also what is the command to set the path of MY documents to Z: drive, so applications trying to save will pick z: as it's default location.

    Any help or suggestions on how to improve this script would be great. 

    Thank you.

    Steve, Chaucer BEC, Sheffield UK 


    Steve Audus, Chaucer BEC, Sheffield, UK



    ====================================

    I have now done some searching and updated my script, so I have solved question 2.

    echo off
    net use z: /delete
    net use t: /delete

    echo Please type your Year Group below and press enter (7,8,9,10 or 11)
    set /p Group=
    if "%Group%" == "7" set intake=2008
    if "%Group%" == "8" set intake=2007
    if "%Group%" == "9" set intake=2006
    if "%Group%" == "10" set intake=2005
    if "%Group%" == "11" set intake=2004

    echo Please Type your Username  (example astudent120589)      
    set /p usern=

    echo Now please Type your Password
    set /p password=

    net use Z: "\\Server\User Storage\Pupils\%intake%\%usern%" /User:mydomain\%usern% %password% /PERSISTENT:NO
    net use T: "\\Server\student$" /User:mydomain\%usern% %password% /PERSISTENT:NO

    So does any have any suggestions on how to hide the password entry?

    Thank you 
    Steve Audus, Chaucer BEC, Sheffield, UK
    Saturday, February 28, 2009 11:26 PM
  • You can hide or mask the password input through ansi.sys. Here's a script that demonstrates this capability:

    http://home7.inet.tele.dk/batfiles/monthly/jul2000.htm

    Regards,

    Salvador Manaois III
    MCITP | Enterprise & Server Admin
    MCSE MCSA MCTS CIWA C|EH
    Bytes & Badz: http://badzmanaois.blogspot.com
    Monday, March 2, 2009 2:36 AM
    Moderator
  • Thank you for the suggestion,
    but the script doesn't work, due to an error with MEM.EXE, and I really can't see how to use the script for a password,
    that could be any length and contain an character.

    But thanks for the suggestion.

    I am thinking of trying to write the script in vbs, but I don't know where to start.

    Any other suggestions?

    Thanks
    Steve
    Steve Audus, Chaucer BEC, Sheffield, UK
    Monday, March 2, 2009 8:48 AM
  • I am trying to clear up the older open posts on this forum. If this is still an unresolved issue for you please let me know. If you do not post back within one week I will assume it is resolved and will close this thread.

    Thank you

    Ed Wilson
    Microsoft Scripting Guy
    Tuesday, January 12, 2010 3:31 PM
  • It works but i'd prefer to hide the password as they type it? is it possible?

    This is possible with my copyrighted freeware editv32.exe (on 32-bit Windows) and editv64.exe (on 64-bit Windows) programs. For example:

    editv32 -m -p "Enter the password: " PWD

    This causes editv32.exe to display the prompt "Enter the password:" and pauses for input. The "-m" option masks the password with "*" characters. When you type something and press Enter, the input you typed is stored in the PWD environment variable.

    You can download editv32.exe and editv64.exe from my web site:

    http://www.westmesatech.com/editv.html

    HTH,

    Bill
    Tuesday, January 12, 2010 4:49 PM
    Moderator
  • There's an old Scripting Guy post which shows you a VBScript solution for this - but it won't work in Vista and above.
    Here's a quick HTA I wrote though which should do the trick.

    <html>
    <head>
    <title>Drive Mapper</title>
    <HTA:APPLICATION 
         APPLICATIONNAME="Drive Mapper"
         SCROLL="no"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="normal"
    >
    <STYLE>
    body {
    	padding-top:20px;
    	text-align:center;
    }
    td,input	{
    	font-family:Verdana;
    	font-size:12pt;
    }
    a	{
    	font-size:9pt;
    	font-family:Verdana;
    }
    </STYLE>
    <SCRIPT LANGUAGE=VBScript>
    Set objNetwork = CreateObject("Wscript.Network")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Sub Window_OnLoad
    	Dim X, Y, strComputer, objWMIService, colItems, objItem, intHorizontal, strYear
    	X=500
    	Y=300
    	window.resizeTo X,Y
    		' resize the HTA
    	strComputer = "."
    	Set objWMIService = GetObject("Winmgmts:\\" & strComputer & "\root\cimv2")
    	Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
    	For Each objItem in colItems
    		intHorizontal = objItem.ScreenWidth
    		intVertical = objItem.ScreenHeight
    	Next
    	window.moveTo (intHorizontal - X) / 2, (intVertical - Y) / 2
    		' centre it
    	txtName.value=objNetwork.UserName
    	txtName.focus
    End Sub
    
    Sub btnConfigure_OnClick
    	If txtName.value="" Then
    		MsgBox "Please enter your name",16,"ERROR"
    		txtName.focus
    		Exit Sub
    	End If
    	If txtPassword.value="" Then
    		MsgBox "Please enter your password",16,"ERROR"
    		txtPassword.focus
    		Exit Sub
    	End If	
    	MapDrive "Z:","\\Server\User Storage\Pupils\" & lisYear.value & "\" & txtName
    	MapDrive "T:","\\Server\student shared$"
    	MsgBox "Network resources have been mapped",64,"DONE"
    End Sub
    
    Sub MapDrive(DriveLetter,DrivePath)
    	If objFSO.DriveExists(DriveLetter) Then
    		objNetwork.RemoveNetworkDrive DriveLetter,true
    	End If
    	objNetwork.MapNetworkDrive DriveLetter, DrivePath, false, txtName.value,txtPassword.value
    End Sub
    </SCRIPT>
    </head>
    <body>
    <table>
    <tr>
    	<td>What is your intake year?</td>
    	<td><select size="1" name="lisYear" id="lisYear">
    			<option value="Y7">2008</option>
    			<option value="Y8">2007</option>
    			<option value="Y9">2006</option>
    			<option value="Y10">2005</option>
    			<option value="Y11">2004</option>
    		</select></td>
    </tr>
    
    <tr>
    	<td>What is your username?<br/><a>(example: astudent120589)</a></td>
    	<td><input type="text" name="txtName" /></td>
    </tr>
    
    <tr>
    	<td>What is your password?</td>
    	<td><input type="password" name="txtPassword" /></td>
    </tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td><td><input type="button" value="Configure resources" id=btnConfigure /></td></tr>
    </table>
    </body>
    </html>
    • Marked as answer by Steve Audus Wednesday, January 13, 2010 8:33 AM
    Tuesday, January 12, 2010 7:41 PM
  • Thank you for your work that is brilliant.

    Steve


    Steve Audus, Chaucer BEC, Sheffield, UK
    Wednesday, January 13, 2010 8:33 AM
  • I tried using editv32. When I issued the following command:

    Editv32 -p "Password: " -m Passx

    TrendMicro gave me a Program Library Injection warning so I blocked it. I just reproduced the situation. Here's the message:

    Program Library Injection: EditV32.exe is attempting to configure Windows so that a program library (DLL) is automatically loaded by some or all of your applications. If the DLL is malicious, this change can drastically affect your computer's security and stability.

    Perhaps the author could shed some light on what the program is doing that causes this, why the approach is necessary, and why in this case it isn't harmful? I'm a tad reluctant to use any unexamined third-party code to collect a real system password anyway - call me paranoid, no offense is intended but we live in dangerous times - and this warning isn't helping my confidence much...

    Thanks,
    Lupestro

     

    Friday, July 30, 2010 4:44 PM
  • This is possible with my copyrighted freeware editv32.exe (on 32-bit Windows) and editv64.exe (on 64-bit Windows) programs. For example:

    editv32 -m -p "Enter the password: " PWD
    Exactly what I was looking for, thanks a million! I personally am using a script to shutdown my file server via putty, and didn't want to have the password sitting in a text file. It was also totally self defeating via 'normal input', when all one had to do was hit the 'up' arrow to view it. :P
    Monday, August 23, 2010 10:38 AM
  • Program Library Injection: EditV32.exe is attempting to configure Windows so that a program library (DLL) is automatically loaded by some or all of your applications. If the DLL is malicious, this change can drastically affect your computer's security and stability.

    I'm the author of EditV32.exe and EditV64.exe. I don't know why TM would be giving you that message. What version are you running?

    Bill

    Sunday, September 5, 2010 6:21 AM
    Moderator
  • Exactly what I was looking for, thanks a million! I personally am using a script to shutdown my file server via putty, and didn't want to have the password sitting in a text file. It was also totally self defeating via 'normal input', when all one had to do was hit the 'up' arrow to view it. :P

    You're welcome, and thanks for the feedback.

    Bill

    Sunday, September 5, 2010 6:22 AM
    Moderator
  • Hi The_Cat,

    Used your HTA (with very minor tweaks) to solve essentially the same problem -- works a treat, many thanks!

    Allan

     

    Monday, November 29, 2010 9:17 AM
  • @AbqBill:

    Thank you a lot for EditV32/64, they are very useful! However, I use the following too to convert my bat files to exe and even though it seems to work, the script dies right after I've entered the password. Any clues what I can do to fix it? I would highly appreciate any help on this issue! :)

    Screenshot: http://i.imgur.com/Nzp7P.png

    http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html

    Thursday, December 2, 2010 10:45 PM
  • Hi,

    Glad you like the tool. Does your shell script (batch file) work if you don't use this tool to convert it to an EXE?

    Bill

    Friday, December 3, 2010 4:49 PM
    Moderator
  • Hi,

    FYI, I just tried using the "Bat to Exe" converter tool with a script that uses EditV32.exe v2.2 and it worked without problems for me.

    Bill

    Monday, December 6, 2010 4:28 PM
    Moderator
  • I'd just like to throw my 2 cents in on this old thread:

    I was having the same problem when having to mask the password input for mapping a drive. I was able to get around it without using any third party programs or scripts.

    If you use the "net use" command and provide the username, the batch file will automatically ask you to enter the password; it doesn't echo any input.

     

    @REM  Get username
    
    set /P user=Enter your username: 
    
    @REM  Mount drive with provided username, without a variable for a password
    
    net use Z: "\\UNC_PATH" * /user:%user%@domain /PERSISTENT:NO

    The response will be:

    Enter your username: username
    Type the password for \\UNC_PATH:

    I wrote a batch file that included this type of "masking" a few years ago. A situation came up where I needed it, but was unable to find the said batch file. I googled and could not find any information pertaining to this method.

    Just thought I'd bring it up!

     

     

    Wednesday, December 29, 2010 11:15 PM
  • I use temp vbscript to do the trick. It save the masked password in a temp file

    Set USER_=%temp%\user.lck
    Set /P User=your account:
    Set PwdVBS=%~dpn0-tmp.vbs
    echo Set objPassword = CreateObject("ScriptPW.Password") > %PwdVBS%
    echo WScript.StdOut.Write "Your password:" >> %PwdVBS%
    echo strPassword = objPassword.GetPassword() >> %PwdVBS%
    echo Set fso = CreateObject("Scripting.FileSystemObject") >> %PwdVBS%
    echo Set LoginFile = fso.CreateTextFile(WScript.Arguments(0), True) >> %PwdVBS%
    echo LoginFile.WriteLine(WScript.Arguments(1) ^& "~" ^& strPassword) >> %PwdVBS%
    echo LoginFile.Close >> %PwdVBS%
    cscript.exe %PwdVBS% //nologo %USER_% %User%
    del /q %PwdVBS%

    Thursday, January 12, 2012 7:47 PM
  • Hi STF1996,

    Unfortunately, the ScriptPW.Password object only exists on Windows XP. Your script will not work on anything other than XP (unless you copy the dll file and register it first, of course). So I consider the ScriptPW.Password object a non-portable solution. This is one of the reasons I wrote my utility.

    Bill

    Thursday, January 12, 2012 8:10 PM
    Moderator
  • It seems you're right ;)

    thanks for this information because we will migrate to windows 7 this year. As you know, an IT guy cannot avoid to learn about powershell. And after few research, I just test the sample here http://www.via-powershell.fr/index.php/2011/01/credentials/manipulation-des-credentials-via-powershell/ (french)

    most of powershell cmd have a -credential parameter but if you want to use a legacy dos cmd you can get password

    $Credential = Get-Credential
    $NetworkCredential = $Credential.GetNetworkCredential()
    $User = "$($NetworkCredential.Domain)\$($NetworkCredential.UserName)"
    $Password = $NetworkCredential.Password

    Schtasks.exe /QUERY /S $ComputerName /FO CSV /V /U $User /P $Password

    Saturday, January 14, 2012 7:51 PM
  • I found another solution here: http://blog.magerquark.de/scriptpw-dll-on-windows-2008-and-windows-7-scriptpw-password/

    • Proposed as answer by Alexandre Piva Saturday, December 15, 2012 3:09 PM
    Saturday, December 15, 2012 3:09 PM
  • I found another solution here: http://blog.magerquark.de/scriptpw-dll-on-windows-2008-and-windows-7-scriptpw-password/

    That doe nt do what was asked.

    Never download exe programs from unknown sources.  If this cod eis useful then download the source and compile it.

    On Win 7 and Win 6 PowerShell is an easier and safer solution.


    ¯\_(ツ)_/¯

    Saturday, December 15, 2012 5:46 PM
  • To Bill_Stewart:

    Hi Bill, I'v seen many of your other comments regarding this same situation. I looked over your website a bit and tried using your method of masking characters. I'm 14 years old and trying to get well acquainted with Windows programming.

    I couldn't find any instructions on how to work/use your file to better my education with batch scripts. I found the descriptions of the contents in the download to be lacking enough information to give me a well fit understanding of what the files are, and what they do.

    I don't want you to see this as a threatening reply. If you could make these changes, more people could understand, use and enjoy the programs you've made without having to ask any questions on how to operate them. 

    If you could help that would be great! 

    This is my current project below. This script allows the user to hide and lock a folder they don't want anyone to get into. I did not come up with this script myself, I found it online. Right now I'm making edits to make it more suitable for me. 

    Like the main question above I would like to mask the password. If you can walk me through the process that would help a lot. Thanks.

    -Konnor

    cls
    @ECHO OFF
    title Private Folder
    if EXIST "HTG Locker" goto UNLOCK
    if NOT EXIST Private goto MDLOCKER
    :CONFIRM
    cls
    echo Are you sure you want to lock the folder(Y/N)
    
    set/p "cho=>"
    if %cho%==Y goto LOCK
    if %cho%==y goto LOCK
    if %cho%==n goto END
    if %cho%==N goto END
    cls
    echo Invalid choice.
    ping localhost -n 5 >nul
    goto CONFIRM
    
    :LOCK
    ren Private "HTG Locker"
    attrib +h +s "HTG Locker"
    cls
    echo Folder locked
    ping localhost -n 2 >nul
    goto End
    
    :UNLOCK
    cls
    echo Enter password to unlock folder
    set/p "pass=>"
    if NOT %pass%== YOUR-PASS-HERE goto FAIL
    attrib -h -s "HTG Locker"
    ren "HTG Locker" Private
    cls
    echo Folder Unlocked successfully
    ping localhost -n 2 >nul
    goto End
    :FAIL
    cls
    echo Invalid password
    ping localhost -n 3 >nul
    goto UNLOCK
    :MDLOCKER
    md Private
    cls
    echo Private created successfully
    ping localhost -n 1 >nul
    goto End
    :End


    • Edited by Konman5 Wednesday, June 18, 2014 5:05 PM Needed Directory to Specific User
    Wednesday, June 18, 2014 4:44 PM
  • Here is a sample that uses editv32.exe (you must use editv64.exe if you are running 64-bit Windows):


    @echo off
    setlocal enableextensions
    set PWD=
    
    :REPEAT
    editv32 -p "Password: " -m PWD
    rem Exit code 4 - program aborted with Ctrl+C
    if errorlevel 4 goto :END
    rem Exit code 2 - nothing entered
    if errorlevel 2 goto :NOBLANK
    
    echo You entered: %PWD%
    goto :END
    
    :NOBLANK
    echo You cannot enter a blank password.
    goto :REPEAT
    
    
    :END
    endlocal
    

    Study this example carefully. If you don't understand it then I recommend finding some tutorials and resources. Sorry but a forum is just not a good way to learn scripting/programming fundamentals.


    -- Bill Stewart [Bill_Stewart]


    Wednesday, June 18, 2014 5:05 PM
    Moderator
  • Understood, thank you Bill.
    Wednesday, June 18, 2014 5:16 PM
  • This is the UNIX way of reading keyboard input without echo:

    stty -echo; read PASSWORD; stty echo; echo ""

    I have confirmed this syntax to work in Cygwin under Windows.

    Microsoft offers an environment that likely includes this capability in their "Services For UNIX" product.

    Wednesday, April 29, 2015 6:28 PM
  • much simpler:

    set a variable using Powershell and use the variable in your batch - it will not show when entered.

    as follows:

    set "psCommand=powershell -Command "$password = read-host 'Enter Password' -AsSecureString ; ^
        $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password); ^
            [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
    for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p

    Thursday, September 21, 2017 6:56 AM
  • If you are proposing to run PowerShell from a batch file, why? Just use PowerShell and dispense with the batch file altogether. Batch files are essentially obsolete now that we have PowerShell.

    -- Bill Stewart [Bill_Stewart]

    Thursday, September 21, 2017 2:24 PM
    Moderator
  • If you are proposing to run PowerShell from a batch file, why? Just use PowerShell and dispense with the batch file altogether. Batch files are essentially obsolete now that we have PowerShell.

    -- Bill Stewart [Bill_Stewart]

    ...

    Command Prompt is not "obsolete".  There are billions of lines of legacy scripts out there that work just fine.  Most of us can't afford to port all of our code to newest framework every time we have a minor requirements change like "hide the password".

    Saturday, July 21, 2018 3:03 PM
  • @Brian2Hand's solution is the most elegant I've seen so far.  Works perfectly for me, and folds into any existing command prompt script effortlessly.

    Saturday, July 21, 2018 3:08 PM
  • Command Prompt is not "obsolete". There are billions of lines of legacy scripts out there that work just fine. Most of us can't afford to port all of our code to newest framework every time we have a minor requirements change like "hide the password".

    I would argue that for new scripts, cmd.exe shell scripts (batch files) are obsolete now that we have PowerShell. PowerShell is superior to cmd.exe in nearly every conceivable way. If you don't agree with that, that's fine, but we'll just have to agree to disagree.

    Incidentally, I find it ironic that the solution you find the most elegant requires PowerShell. That was my point earlier: Why use a batch file at all? Just use PowerShell for the whole thing and be done with it. You will get the advantage of a better script that is easier to read/manage/upgrade.


    -- Bill Stewart [Bill_Stewart]


    Saturday, July 21, 2018 8:29 PM
    Moderator
  • I am sure this will be very easy for you clever scripting guys out there, here's a couple of questions.

    I have wrote this little script for some wireless laptops that we are not going to join our domain, but we'd like our students to access to thier home drives, and shared resources.

    ===============================
    echo off
    net use z: /delete
    net use t: /delete
    echo                Your Intake Year                                                                       
    echo    Y7=2008      Y8=2007      Y9=2006      Y10=2005      Y11=2004
    echo  Please type your Intake Year below
    set /p Group=
    echo        Please Type your Username  (example astudent120589)
    echo Please Type your Username
    set /p usern=
    echo "Please Type your Password"
    set /p password=
    echo Your username is %usern%
    echo Your Group is %Group%
    pause
    net use Z: "\\Server\User Storage\Pupils\%Group%\%usern%" /User:ourdomaim\%usern% %password% /PERSISTENT:NO
    net use T: "\\Server\student shared$" /User:ourdomain\%usern% %password% /PERSISTENT:NO

    ================================

    1. It works but i'd prefer to hide the password as they type it? is it possible?
    2. I'd also prefer to ask for thier year group, so they just type 7,8,9,10 or 11 instend of thier intake group, but I don't know how to script this?
    3. Also what is the command to set the path of MY documents to Z: drive, so applications trying to save will pick z: as it's default location.

    Any help or suggestions on how to improve this script would be great. 

    Thank you.

    Steve, Chaucer BEC, Sheffield UK 


    Steve Audus, Chaucer BEC, Sheffield, UK

    I know this is a necro, but this should be helpful to at least a few future humans:

    If the shares are on a single server, you can map the server once and all future shares will use those same credentials. net use allows you to prompt for a hidden password with "/user:username *"

    So first do

    set /p name=Username:
    net use \\Server\ /user:%name% *

    then do your shares:

    net use Z: \\server\share1$
    net use T: \\server\share2$

    so it prompts for a hidden password once and will still allow you to do multiple shares

    Regrettably, this particular solution only works when the shares are all on a single server.

    Wednesday, November 28, 2018 5:08 PM