是否可以在cmd Net Use中捕获密码?

时间:2015-05-07 15:18:06

标签: batch-file cmd

bat脚本获取用户名和密码以连接到共享网络驱动器,关键要素是:

net use u: \\server\users\%UserName% * /user:%UserName% /persistent:no

这很有效,因为" *"这是隐藏的视图,我已经捕获了用户的登录名。映射到同一服务器上的其他位置无需任何进一步的用户输入,但只要我映射到另一个服务器,将提示用户再次输入其密码。

无论如何,我可以捕获输入" *"应用于其他服务器的字符串?

感谢。

3 个答案:

答案 0 :(得分:1)

感谢您的回复,不幸的是我的电子邮件,必须阻止回复,因为我没有收到任何通知。

我从未使用过PowerShell,这将是另一个学习曲线,JosefZ的帖子肯定会被审查。

我在工作时间之外做了一些更深入的搜索并找到了一个基于命令的实用程序:

EditVar / EditV32 / EditV64和Choose / Choose32 / Choose64 (C)Bill Stewart的2006-2014(bstewart@iname.com)

它位于与orinal脚本相同的位置,只需要一行来调用它并分配一个字符串,在下面的示例中,%PASSWORD%将是我可以用来代替“*”的字符串,正常工作一种享受。

editv64 -p "Enter your password: " PASSWORD -m

很高兴得到反馈,我将整理我的电子邮件过滤器 - 干杯。

答案 1 :(得分:0)

A clone from my answer to another question

Set /P "=Type the password for \\server\users\%UserName%:" < Nul
Call :PasswordInput serverpass
net use u: \\server\users\%UserName% %serverpass% /user:%UserName% /persistent:no

rem skip over the procedure 
goto :eof
:PasswordInput
::Author: Carlos Montiers Aguilera
::Last updated: 20150401. Created: 20150401. 
::Set in variable Line a input password
::
::Update 20150503: https://stackoverflow.com/users/3439404/josefz?tab=profile
::Changes made in next lines:
::    SetLocal EnableDelayedExpansion
::    If !CHR!==!CR! Echo(&EndLocal&set "%1=%Line%"&Goto :Eof
::Usage:
::    Call :PasswordInput variableName
::where variableName is a name of output variable (by reference call)
:: 
SetLocal EnableDelayedExpansion
For /F skip^=1^ delims^=^ eol^= %%# in (
'"Echo(|Replace.exe "%~f0" . /U /W"') Do Set "CR=%%#"
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do Set "BS=%%#"
Set "Line="
:_PasswordInput_Kbd
Set "CHR=" & For /F skip^=1^ delims^=^ eol^= %%# in (
    'Replace.exe "%~f0" . /U /W') Do Set "CHR=%%#"
If !CHR!==!CR! Echo(&EndLocal&set "%1=%Line%"&Goto :Eof
    If !CHR!==!BS! (If Defined Line (Set /P "=!BS! !BS!" <Nul
        Set "Line=!Line:~0,-1!"
    )
) Else (Set /P "=*" <Nul
If !CHR!==! (Set "Line=!Line!^!"
    ) Else Set "Line=!Line!!CHR!"
)
Goto :_PasswordInput_Kbd

资源(必读):

答案 2 :(得分:0)

PowerShell示例脚本,用于读取隐藏的输入字符串并传递给多个net use命令:

Function Read-Password {
  param(
    [String] $promptString
  )
  $secureString = Read-Host $promptString -AsSecureString
  try {
    $intPtr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secureString)
    $password = [Runtime.InteropServices.Marshal]::PtrToStringAuto($intPtr)
  }
  finally {
    if ( $intPtr ) {
      [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($intPtr)
    }
  }
  $password
}

$password = Read-Password "Enter password"
if ( -not $password ) { return }

net use \\server1\share /user:foo $password
net use \\server2\share /user:foo $password
# ... etc.