2

How can I get the path of the start up folder from a batch file? The only way I found was to look in the registry but I don't think thats possible with CMD.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Oztaco
  • 3,399
  • 11
  • 45
  • 84

2 Answers2

2

This will set STARTUP to the location of the startup folder:

for /F "skip=4 tokens=3*" %%j in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Common Startup"') do set STARTUP=%%k

(skip=4 is for XP, use skip=2 for Windows 7. I don't have Vista to try the command there)

Also available (change the value after /v):

Common AppData
Common Programs
Common Documents
Common Desktop
Common Start Menu
CommonPictures
CommonMusic
CommonVideo
Common Templates
Common Favorites
Common Startup
Common Administrative Tools
phuclv
  • 37,963
  • 15
  • 156
  • 475
SeanC
  • 15,695
  • 5
  • 45
  • 66
  • Hmm... doesnt seem to work, I wrote echo %STARTUP% and it wrote "ECHO is OFF..." and I tried cd %STARTUP% and it showed the current directory. – Oztaco Jun 25 '12 at 21:47
  • try just `reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Common Startup"` from the command line - the 4th line is what we are after. the 3* is a kludge to get around the fact delimiters are horrible to work with on this command - the 3rd item on that line should be `REG_SZ`, and the 4th will be everything after that – SeanC Jun 25 '12 at 21:52
  • Yeah, just putting in that line worked, how would you put this into a variable, because then you could just do %var:~75,% to get to the important part (75 isnt the exact number, I didn't count yet :P) – Oztaco Jun 25 '12 at 22:52
  • ok. seems in XP it's `skip=4` and in win7, it's `skip=2`. count the lines from the output from the `reg query` command, and skip that number of lines less one – SeanC Jun 26 '12 at 03:24
  • Yes, skip=2 worked but the reg query command had 4 lines when I did it by it's self – Oztaco Jun 26 '12 at 09:41
  • on an 80 column display, 2 of the lines wrap to the next line, but the system still sees them as one line – SeanC Jun 26 '12 at 13:03
1

In Windows XP you can access like this

CD %HOMEDRIVE%%HOMEPATH%\Start Menu\Programs\Startup
phuclv
  • 37,963
  • 15
  • 156
  • 475
Sudhakar B
  • 1,465
  • 9
  • 16
  • 1
    You need quotes around it, because of the space in "Start Menu", and it will only work in an english version of Windows –  Jun 23 '12 at 09:01
  • Hmm well it will be good if you place in single quotes. but now days it allowed in all new systems. Its worked in my system. – Sudhakar B Jun 23 '12 at 09:04