Batch/CMD: Adding files to Startup list

前端 未结 3 576
北恋
北恋 2021-01-03 00:18

How can a batch file lists itself in the startup list of Windows???

It doesn\'t matter if it goes from the registry or not.

IF with the registry, please give

相关标签:
3条回答
  • 2021-01-03 00:57

    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:

    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:).

    0 讨论(0)
  • 2021-01-03 00:59

    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\Startup here 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:

    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.exe from 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_USER if you want this to be usable by some users only.

    0 讨论(0)
  • 2021-01-03 01:01

    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!

    0 讨论(0)
提交回复
热议问题