問題描述
如何從批處理文件本身中找到已編譯的 bat (.exe) 目錄? (How can you find a compiled bat (.exe) directory from within the batch file itself?)
我已經將一個 .bat 應用程序編譯成 .exe,問題是應用程序會在同一目錄中創建一些結果文件夾,但是當 .exe 解壓縮到本地 Temp 目錄時,結果文件夾正在那裡創建。如何將結果保存在與 .exe 相同的文件夾中?
參考解法
方法 1:
I can, and I did it, the rest of the "batch file content" and the compiler itself are meaningless to the issue, just use:
wmic process where "name='here.exe'" get ExecutablePath
Just iterate the results and set them into a variable:
for /f "tokens=2 delims=," %%I in (
'wmic process where "name='here.exe'" get ExecutablePath^,Handle /format:csv ^| find /i "here.exe"') do set "exepath=%%~I"
Good night.
(by Henrique Afonso、Henrique Afonso)