我有一個批處理文件,它接受用戶輸入的密碼。由於某種原因,它不需要最後一個字符,我無法弄清楚。批處理文件中未設置最後一個字符的密碼
powershell -Command $pword = read-host "Enter password " -AsSecureString ; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) > .tmp.txt & set /p password=<.tmp.txt & del .tmp.txt
echo psexec \\%computerName% -u %domainName%\%userName% -p %password% cmd
我知道這是不是PowerShell命令,因爲我與set /p password="Enter password: "
測試它仍然無法呼應的最後一個字符。
按我的意見,如果我使用的語句這裏是:
set /P domainName=
set params = %*:"=""?!
if "%domainName%" == "1" (
set "domainName=domain1"
goto nextstep
)
if "%domainName%" == "2" (
set "domainName=domain2"
goto nextstep
)
if "%domainName%" == "3" (
set "domainName=domain3"
goto nextstep
) else (
goto resetfile
)
:nextstep
我的問題是2的3個領域,PSEXEC運行的那個。對於domain1,它不會運行。我回應了這個命令,並且它完美地打印出來。當我從命令中刪除echo
時,它跳過所有這些並重新啓動文件。
nextstep
是:
:nextstep
set /p userName="Enter your Admin username: "
powershell -Command $pword = read-host "Enter password " -AsSecureString ; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) > .tmp.txt & set /p password=<.tmp.txt & del .tmp.txt
psexec \\%computerName% -u %domainName%\%userName% -p %password% cmd
:resetfile
set resetfile=
set /p resetfile="Do you want to restart this file? Press 'y' for Yes or 'n' for No then Press ENTER: "
if not '%resetfile%'=='' set resetfile=%resetfile:~0,1%
if '%resetfile%'=='y' goto start
腳本甚至沒有問我是否要重新啓動腳本。它只是回到:start
,這是在腳本的開始。
請幫忙,謝謝!
使用它,我想密碼的最後一個字符是像'&^%'或'!'特殊字符和延遲擴充被啓用。嘗試'echo psexec.exe「\\%computerName%」-u「%domainName%\%userName%」-p「%password%」cmd「。任何情況下,執行'psexec.exe'都應該使用雙引號。但是,如果密碼包含啓用延遲擴展的'%'或'!',則最好使用'echo psexec.exe「\\%computerName%」-u「%domainName%\%userName%」-p「!password!」 cmd「,當然還有'setlocal EnableDelayedExpansion'。 – Mofi
老實說,難道你不能只是從PowerShell運行psexec,而不是做一個讓SecureString再次變得不安全的糟糕舞蹈嗎? – Joey
@joey我想我可以。 –