如何從批處理文件本身中找到已編譯的 bat (.exe) 目錄? (How can you find a compiled bat (.exe) directory from within the batch file itself?)


問題描述

如何從批處理文件本身中找到已編譯的 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 AfonsoHenrique Afonso)

參考文件

  1. How can you find a compiled bat (.exe) directory from within the batch file itself? (CC BY‑SA 2.5/3.0/4.0)

#batch-file






相關問題

如何在 Windows 批處理腳本或 Perl 中將文件移動到回收站? (How can I move files to the Recycle Bin in a Windows batch script or Perl?)

psftp 批處理腳本不起作用 (psftp batch script won't work)

用於確定 Windows 和 Office 版本的快速命令或批處理腳本 (quick command or batch script to determine Windows and Office version)

查找 pdfs/doc/docx/etc 的批處理文件 (Batch file to look for pdfs/doc/docx/etc)

批處理文件“and if”語句 (Batch-file "and if" statement)

打開具有特定顏色和標題的 CMD (Open CMD with specific color and title)

使用 excel 2010 更新批處理文件中的變量 (use excel 2010 to update variables in batch file)

讓這批列出文件名,其路徑為文件 gtr 超過一定大小。如何修改以僅列出沒有路徑和擴展名的文件名? (Got this batch to list filenames with path for files gtr than some size.. How to modify to list only filenames without path and extension?)

從變量中刪除括號(CLI-Windows) (Remove Brackets from Variable (CLI-Windows))

僅在不到一天的文件中搜索字符串 (Search for a string only in files less than a day old)

如何從批處理文件本身中找到已編譯的 bat (.exe) 目錄? (How can you find a compiled bat (.exe) directory from within the batch file itself?)

Windows 批處理腳本:Findstr 輸出:過濾子字符串 (Windows batch script : Findstr output : Filter substring)







留言討論