
我希望有人可以幫助解決這個問題。所以Win10 x64。
我需要將一個 XPI 檔案(Firefox 擴充功能)複製到 Program Files(不是 x86)子資料夾。如果我做一個簡單的bat文件,並以管理員身份右鍵單擊運行它,mkdir工作正常,但複製操作不起作用。相反,如果我以管理員身份打開 cmd 並從那裡運行複製操作,則 mkdir 和複製操作都會按預期工作。
我需要從具有提升權限的第三方軟體呼叫 BAT,所以如果我能解決第一個場景,我應該能夠解決我的問題。非常感謝任何幫助或解釋。程式碼非常簡單:
mkdir "C:\Program Files\Mozilla Firefox\distribution\extensions"
copy file.xpi "C:\Program Files\Mozilla Firefox\distribution\extensions"
提前致謝。
答案1
嘗試使用 xcopy 而不是 copy。
或是您考慮過使用 powershell 嗎?
它功能更強大,您可以指定憑證過程。您也可以使用 Powershell 繞過執行策略。
Set-Executionpolicy Bypass -Scope Process -Force
然後你可以使用以下命令在powershell中複製該程序
xcopy /q <source> <destination>
如果這不起作用,請嘗試將 xcopy 命令放入 Start-Process powershell 命令中。就像是...
Start-Process -FilePath "c:\Windows\System32\xcopy.exe" -ArgumentList "file.xpi C:\Program Files\Mozilla Firefox\distribution\extensions\" -Credential domain\user
或者,網域\用戶將是電腦名稱\用戶
請注意,Start-Process 還具有 -Wait 開關,用於等待進程完成。