views:

469

answers:

2

Hello,

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 also the command to DELETE the registry entry.

This should work under all versions from ME to 7 please.

Otherwise just XP/Vista/7.

Thanks.

+2  A: 

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

Traveling Tech Guy
Thanks for the help!
YourComputerHelpZ
+1  A: 

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.

Jay