Batch/CMD: Adding files to Startup list

前端 未结 3 607
北恋
北恋 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: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.

提交回复
热议问题