你可以在Windows啟動時使用bat檔案啟動一個程式並傳送檔案路徑嗎

你可以在Windows啟動時使用bat檔案啟動一個程式並傳送檔案路徑嗎

bat 檔案或 vbs 檔案可以接受參數(exe 檔案的路徑),然後建立該檔案的捷徑並將其放置在啟動資料夾中,或新增登錄項目以在 Windows 啟動時執行該 exe

但我希望相同的腳本也能夠刪除啟動條目(在所有作業系統版本上)。

所以我假設腳本需要發送兩個參數/參數: 1 - 啟動時運行的檔案/exe 2 - 是否在啟動時新增或刪除條目

這可能嗎?

答案1

首先,我想建議您仔細檢查註冊表中任何早於 Vista 的作業系統的運行鍵位置,因為我已經很長時間沒有使用它們了,所以可能存在我不記得的差異。

如果我正確理解你的問題,這個批次腳本應該要做你想要的。文件。

:begin
cls
@echo off
echo   Program startup Utility
echo.
echo    1. Add Program to Startup
echo    2. Remove Program From Startup
echo    x. Exit

set /p choice=  Choose A Service:
if not '%choice%'== set %choice%=choice:~0,1%

if '%choice%'=='1' goto :addstartup
if '%choice%'=='2' goto :delstartup
if '%choice%'=='x' goto :exit

:addstartup
cls
echo/
echo/
echo    Add Program to Startup
echo    or type back to go to main menu
echo/
set /p keyname= Please State Program Name:

if '%keyname%'=='back' goto :begin

set /p expath= Please Enter Path to Executible:

if '%expath%'=='back' goto :begin

reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Run\ /v %keyname% /t REG_SZ /d "%expath%"

timeout /t 3 >nul

goto begin


:delstartup
cls
echo/
echo  Remove Program From Startup
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run\ /s
echo/
set /p keyname= Please Enter Program Name:
reg delete HKLM\Software\Microsoft\Windows\CurrentVersion\Run\ /v "%keyname%" /f

timeout /t 3 >nul

goto begin

或者,如果您只需要能夠新增或刪除相同的程序,而不需要輸入多個程式名稱或 exe 路徑,那麼您可以像這樣修改腳本,並將 %keyname% 替換為您的程式名稱,然後%expath%為可執行檔的路徑(不帶%),然後儲存。確保新增和刪除時的鍵名相同。

如果您只想在選定操作後退出腳本,也可以將「goto begin」行與「exit」交換。

:begin
cls
@echo off
echo   Program startup Utility
echo.
echo    1. Add Program to Startup
echo    2. Remove Program From Startup
echo    x. Exit

set /p choice=  Choose A Service:
if not '%choice%'== set %choice%=choice:~0,1%

if '%choice%'=='1' goto :addstartup
if '%choice%'=='2' goto :delstartup
if '%choice%'=='x' goto :exit

:addstartup
cls
reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Run\ /v %keyname% /t REG_SZ /d "%expath%"

timeout /t 2 >nul

goto begin

:delstartup
cls
reg delete HKLM\Software\Microsoft\Windows\CurrentVersion\Run\ /v "%keyname%" /f

timeout /t 2 >nul

goto begin

相關內容