之前我问这个问题的时候有点困惑,但我需要这个批处理文件在用户不知情的情况下将其自身添加到启动中。我知道这听起来有点粗略,但它适用于我正在制作的新软件
答案1
最简单的方法是将其复制到启动文件夹或创建文件的快捷方式:
%USERPROFILE%\AppData\Roaming\Microsoft\Windows\开始菜单\程序\启动
每次特定用户登录时,这将运行脚本。
您可以在批处理中进行检查,查看副本/快捷方式是否已经存在于启动文件夹中,如果不存在,则该文件将在启动文件夹中复制自身/创建自身的快捷方式。
答案2
这里有一些建议的命令,可用于在注册表子键值中添加要在 bat 中执行的条目,并使这些命令自行调用以适应/遵循您的需求/场景:
rem :: For all boot in local machine (apply to all users) use this key::
rem :: HKLM\Software\Microsoft\Windows\CurrentVersion\Run
rem :: This is an command for run in your bat and for execute it self in all next boot and for all users:
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" /v _Some_Uniq_Value_ /d "%~f0" /f >nul
rem :: For check if reg add command works, you can use this command ::
reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" | find "_Some_Uniq_Value_"
rem :: ——————————————————————-
rem :: For only in next boot in local machine (apply to machine) use this key ::
rem :: HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
rem :: This is an command for run in your bat for execute one time it self in next boot ::
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v _Some_Uniq_Value_ /d "%~f0" /f >nul
rem :: For check if reg add command works, you can use this command ::
reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce" | find "_Some_Uniq_Value_"
rem :: ——————————————————————-
rem :: For all boot in local machine (apply only to current user) use this key::
rem :: HKCU\Software\Microsoft\Windows\CurrentVersion\Run
rem :: This is an command for run in your bat for execute it self in all next boot and for the current user:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v _Some_Uniq_Value_ /d "%~f0" /f >nul
rem :: For check if reg add command works, you can use this command::
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" | find "_Some_Uniq_Value_"
rem :: ——————————————————————
rem :: For only in next boot in local machine (apply only to current user) ::
rem :: HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce
rem :: This is an command for run in your bat for execute one time it self in next boot and for the current user ::
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v _Some_Uniq_Value_ /d "%~f0" /f >nul
rem :: For check if reg add command works, you can use ::
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" | find "_Some_Uniq_Value_"
rem :: ——————————————————————-
观察:你的命令将运行不带重复条目的命令,仅重写相同的值...
这%~fi
请参阅 bat 文件的完整路径,因此,在你将要调用的位置运行你的 bat...
很抱歉我的英语水平有限!