批處理和inputbox函式互動時實現換行,^&vbcrlf^&
阿新 • • 發佈:2020-12-08
技術標籤:5.其他
::使用:+字串實現標識作用,常見goto使用到標識 set "vbs=%Temp%\GotUserInputedDataProgram.vbs" set "data=%Temp%\UserInputedData.tmp" ::==================================== ::=========開始預置對話方塊============= ::==================================== ::查詢檔案是否存在,存在就刪除 if exist "%vbs%" del /s /q /f "%vbs%">nul ::delete file echo On Error Resume Next>>"%vbs%" echo Dim fso,wri,data,file>>"%vbs%" ::建立一個進行互動的視窗 echo Set fso=Wscript.CreateObject^("Scripting.FileSystemObject"^)>>"%vbs%" echo file="%data%">>"%vbs%" echo if fso.FileExists^(file^) Then fso.DeleteFile^(file^)>>"%vbs%" echo Set wri=fso.CreateTextFile^(file,True^)>>"%vbs%" ::視窗輸入的字串儲存在data中 ::批處理中和InputBox使用時要實現換行需要按如下格式寫:變數+^&vbcrlf^&+變數,^是bat轉義符號,&是vbs中的連線符(此處必須使用^對&進行轉義原樣輸入inputbox函式中) echo data=InputBox^("%message%"^&vbcrlf^&"使用者名稱:!user!"^&vbcrlf^&"密&碼:!password!"^&vbcrlf^&"庫&名:!database!","%title%","%note%"^)>>"%vbs%" echo wri.Write data>>"%vbs%" echo wri.Close>>"%vbs%" echo Set fso=Nothing>>"%vbs%" echo Set op=Nothing>>"%vbs%" echo fso.DeleteFile^(Wscript.ScriptFullName^)>>"%vbs%" echo Wscript.Quit>>"%vbs%" ::=============================================================================== ::呼叫執行一個vb程式,就是上面建立的視窗 call "%vbs%" ::獲取data中的內容,利用迴圈獲取 for /f "delims=" %%i in (%data%) do set "content=%%i" if exist "%vbs%" del /s /q /f "%data%">nul if exist "%vbs%" del /s /q /f "%vbs%">nul ::如果輸入內容為空就停止