list 批处理/CMD:将文件添加到启动列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1154701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Batch/CMD: Adding files to Startup list
提问by Deniz Zoeteman
How can a batch file lists itself in the startup list of Windows???
批处理文件如何在 Windows 的启动列表中列出自己???
It doesn't matter if it goes from the registry or not.
它是否来自注册表并不重要。
IF with the registry, please give also the command to DELETE the registry entry.
如果有注册表,请同时给出删除注册表项的命令。
This should work under all versions from ME to 7 please.
这应该适用于从 ME 到 7 的所有版本。
Otherwise just XP/Vista/7.
否则只是 XP/Vista/7。
Thanks.
谢谢。
回答by Traveling Tech Guy
Not sure i understand you, but if what you want is an easy way to execute a command/batch on startup, why not just put it in the All Users\Startup
folder?
To do so programatically would just mean copying a file to that directory.
For example, in Windows Vista, the full path of that directory is:
不确定我理解你,但如果你想要的是一种在启动时执行命令/批处理的简单方法,为什么不把它放在All Users\Startup
文件夹中?
以编程方式执行此操作仅意味着将文件复制到该目录。
例如,在 Windows Vista 中,该目录的完整路径为:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
(you can use replace the beginning of the line with %ProgramData%
or %AllUsers%\ProgramData
to make it more global - such as when Windows is installed on D:).
(您可以用其替换该行的开头%ProgramData%
或%AllUsers%\ProgramData
使之更具全球性的-当安装在d的Windows :)如。
回答by Jay
I do not use windows7 (might get a check at the beta shortly), but I think the correct place will always be better taken from the registry, because of the Windows versions being localized. My own version of C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startuphere looks more like "C:\Documents and Settings\All Users\Menu Démarrer\Programmes\Démarrage"(from XP, of course)
-10 for programmers using hard-coded directory names (yes, some installers will create english/different language directories at installation).
-1 for Microsoft localising directory names...
Anyhow here is a snipet for this, valid for XP at least:
我不使用 windows7(可能很快会在测试版中得到检查),但我认为正确的位置总是会更好地从注册表中获取,因为 Windows 版本是本地化的。我自己的C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup 版本看起来更像是“C:\Documents and Settings\All Users\Menu Démarrer\Programmes\Démarrage”(当然来自 XP)
-10对于使用硬编码目录名称的程序员(是的,一些安装程序会在安装时创建英语/不同语言的目录)。
-1 用于 Microsoft 本地化目录名称...
无论如何,这里有一个 snipet,至少对 XP 有效:
commonstartup.cmd
通用启动程序
@echo off
for /F "tokens=3 delims= " %%k in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Common Startup"^| findstr /i /c:"Common Startup"') do set StartUp=%%k
echo StartUp="%StartUp%"
___Notes_____
1:Because reg.exefrom Windows2000 and XP have different command arguments, maybe the W7 one has changed too so test it before set and forget.
2:To get a list of all the system directories, issue the command: reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"and read the lines. You might want to change the "Common Startup"for something else, if things are so different with W7.
3:There is also a personal/user list within HKEY_CURRENT_USERif you want this to be usable by some users only.
___注意事项_____
1:因为Windows2000和XP下的reg.exe命令参数不同,可能W7的也变了,所以先测试一下再设置忘记。
2:要获取所有系统目录的列表,请发出命令:reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"并阅读行。如果 W7 的情况如此不同,您可能希望将“通用启动”更改为其他内容。
3:如果您希望它仅供某些用户使用,则HKEY_CURRENT_USER 中还有一个个人/用户列表。
回答by PCMC
xcopy C:\Users\NAME\Desktop\Batch.bat C:\ProgramData\Microsoft\Windows\"Start Menu"\Programs\StartUp /O /X /E /H /K is the correct command for windows 10. simply change the the second path to your version, and remember whenever there is a space, place a " before the word before the space, and after the word after it. however, it MUST be opened in administrator, so after some research, i found that a batch file could be used to start a different batch file and run it in administrative mode: runas /user:administrator C:\data\mybatchfile.bat that should work!
xcopy C:\Users\NAME\Desktop\Batch.bat C:\ProgramData\Microsoft\Windows\"Start Menu"\Programs\StartUp /O /X /E /H /K 是 Windows 10 的正确命令。只需更改版本的第二条路径,记住每当有空格时,在空格之前的单词之前和之后的单词之后放置一个“。但是,它必须在管理员中打开,所以经过一些研究,我发现批处理文件可用于启动不同的批处理文件并在管理模式下运行它: runas /user:administrator C:\data\mybatchfile.bat 应该可以工作!