Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Where Do I Put the autoexec.bat File to Get my Batch File Executed at Login?

5,718 views
Skip to first unread message

KevinSimonson

unread,
Mar 17, 2011, 12:20:57 PM3/17/11
to
I have a batch file that executes "echo off" and then does a bunch of
<doskey> commands that abbreviate a number of commands I use. I'll
probably keep adding to that file as time goes by. I did a little bit
of research on the Internet (for example I read "http://
www.computing.net/answers/windows-7/how-to-edit-autoexecbat-in-windows-7/6604.html"),
and from what I've looked at it looks like I need to put a command to
execute my "Aliases.bat" file in an "autoexec.bat" file and put it
somewhere where my operating system will execute it when I bring up a
Command Prompt.

But my question is, where do I put it? The URL I referenced above
seems to indicate I need to put the "autoexec.bat" at either "C:\" or
"C:\Windows\system", so I put it at those two places and just for the
heck of it I also copied it to "C:\Windows\System32". Then I brought
up a new Command Prompt and typed in "l", which is one of my aliases
for "ls -F", but the Command Prompt didn't recognize it. I shut my
computer down completely and powered it up again and logged in, and
typed "l", and still got the same error message, "'l' is not
recognized as an internal or external command, operable program or
batch file." I tried the same stuff with capitalizing the 'a', namely
naming the file "Autoexec.bat", and that didn't do any good.

Does anybody know where I have to put my "autoexec.bat" file so that I
can get my "Aliases.bat" file executed automatically when I log in,
instead of me having to explicitly execute it every time I bring up a
Command Prompt?

My operating system is Windows 7 Enterprise, and, in case you want all
my information, I sometimes accompany that OS with the string
"Intel(R) Core(TM) i7 CPU, Q 820 @ 1.73Ghz 1.73 Ghz".

Kevin Simonson

Char Jackson

unread,
Mar 17, 2011, 5:37:13 PM3/17/11
to

It doesn't matter much where you put your batch file or what you call
it, hence the multiple suggestions you've found already. Put it where
it's convenient for you. Some use the root folder of C:\, some create
a new folder for batch files, such as C:\batch, and some simply drop
their batch files into C:\Windows or one of its subfolders. It doesn't
matter.

Wherever you decide to put it, create a shortcut in the Start->
Programs-> Startup menu so that it gets executed after you login to
Windows. (There are other ways of auto-executing a program upon login,
but that's the easiest.)

The problem you're running into now is that autoexec.bat isn't used by
Windows 7, so your batch file isn't being executed.

KevinSimonson

unread,
Mar 18, 2011, 3:33:09 PM3/18/11
to
On Mar 17, 3:37 pm, Char Jackson <n...@none.invalid> wrote:

> It doesn't matter much where you put your batch file or what you call
> it, hence the multiple suggestions you've found already. Put it where
> it's convenient for you. Some use the root folder of C:\, some create
> a new folder for batch files, such as C:\batch, and some simply drop
> their batch files into C:\Windows or one of its subfolders. It doesn't
> matter.
>
> Wherever you decide to put it, create a shortcut in the Start->
> Programs-> Startup menu so that it gets executed after you login to
> Windows. (There are other ways of auto-executing a program upon login,
> but that's the easiest.)
>
> The problem you're running into now is that autoexec.bat isn't used by
> Windows 7, so your batch file isn't being executed.

The name of my batch file is "Aliases.bat" and it's in the "Bin"
subdirectory of my login directory. How do I go about creating "a


shortcut in the Start->Programs->Startup menu so that it gets executed

after" I login?

I tried clicking <Start->All Programs->Startup> and then right
clicking on <Startup> and selecting <Properties>. Doing that caused a
little window to pop up labeled "Startup Properties", that had six
tabs, <General>, <Sharing>, <Security>, <Location>, <Previous
Versions>, and <Customize>. I took a look at all of them, and none of
them looked like it had anything to do with creating a shortcut for my
".bat" file so that it gets executed after I login.

I also tried right clicking on "Aliases.bat" itself, in my version of
Windows Explorer, right clicking, and selecting <Create shortcut>,
which _did create_ a shortcut file. At that point I copied that
shortcut to "<my login directory>\AppData\Roaming\Microsoft\Windows
\Start Menu\Programs\Startup", and then I shut down my laptop and
brought it up again, and then when I brought up a command prompt I
typed "m autoexec.bat", where "m" is my alias for "more", and got the
message "'m' is not recognized as an internal or external command,


operable program or batch file."

If someone could explain how I can get my shortcut into the <Startup>
menu, I'd really appreciate it!

Kevin Simonson

Char Jackson

unread,
Mar 18, 2011, 4:49:57 PM3/18/11
to

The easiest way is to simply drag the shortcut into the Startup
folder. Start orb, All Programs, Startup.

A totally different alternative is to fire up the Windows Task
Scheduler, click to create a new task, tell it to run at every login,
and tell it where your file resides.

Of course, before proceeding, you should manually test the
functionality of your batch file. Execute it by double clicking the
shortcut you created, then open a new Command prompt window. Do your
aliases show up? If so, either of the methods above should work, but
if not, then you have a different problem and neither of the methods
above will help.

Char Jackson

unread,
Mar 18, 2011, 5:52:57 PM3/18/11
to
On Fri, 18 Mar 2011 12:33:09 -0700 (PDT), KevinSimonson
<kvns...@hotmail.com> wrote:

>The name of my batch file is "Aliases.bat" and it's in the "Bin"
>subdirectory of my login directory. How do I go about creating "a
>shortcut in the Start->Programs->Startup menu so that it gets executed
>after" I login?

If you're still having problems with this, it might be helpful if you
post the contents of your batch file.

KevinSimonson

unread,
Mar 18, 2011, 6:16:47 PM3/18/11
to
On Mar 18, 2:49 pm, Char Jackson <n...@none.invalid> wrote:

> The easiest way is to simply drag the shortcut into the Startup
> folder. Start orb, All Programs, Startup.
>
> A totally different alternative is to fire up the Windows Task
> Scheduler, click to create a new task, tell it to run at every login,
> and tell it where your file resides.
>
> Of course, before proceeding, you should manually test the
> functionality of your batch file. Execute it by double clicking the
> shortcut you created, then open a new Command prompt window. Do your
> aliases show up? If so, either of the methods above should work, but
> if not, then you have a different problem and neither of the methods

> above will help.- Hide quoted text -
>
> - Show quoted text -

I followed Char Jackson's advice and executed my "Aliases.bat" file by
bringing up Windows Explorer and clicking on that file, though first I
added some code in there so I could be sure it was it executing. When
I did, a Command Prompt window popped up, and it was very clearly
executing my "Aliases.bat" file, but as soon as it completed all the
commands in the file it vanished, and when I brought up another
Command Prompt later, it didn't have my aliases set. So does that
mean I "have a different problem" as you stated it?

Kevin Simonson

Char Jackson

unread,
Mar 18, 2011, 7:01:43 PM3/18/11
to

Yes, as I suspected, the alias definitions aren't saved across other
instances of the Command Prompt.

Check this link:
<http://superuser.com/questions/150244/command-aliases-in-dos>

There are a couple of solutions there that I think might work, but I
haven't done any testing of my own.

==============
Solution 1:

It is rather easy setup permanent alias in command prompt for Windows
using the @DOSKEY command and HKCU\Software\Microsoft\Command
Processor Autorun option.

Quick step-by-step guide:

1. Create a new batch file, call it Alias.bat. Copy/paste the text
below. TIP: I recommend creating a C:\Bin folder for all your command
line tools.
2. Open the register HKEY_CURRENT_USER\Software\Microsoft\Command
Processor.
3. Add an String Value named Autorun and set the value to absolute
path of the Alias.bat file.
4. Done.

This batch file will execute every time you open a command prompt.

Contents of Alias.bat

@ECHO OFF
@DOSKEY ls=DIR $*
@DOSKEY cp=COPY $*
@DOSKEY xcp=XCOPY $*
@DOSKEY mv=MOVE $*
@DOSKEY clear=CLS
@DOSKEY h=DOSKEY /HISTORY


===================
Solution 2:

Put your aliases into a file called, perhaps, alias.cmd and add /K
\path\to\alias.cmd to the shortcut that you use to start cmd.exe.


Both of those solutions look like they should work. Please let us know
how it goes.

krist...@gmail.com

unread,
Oct 9, 2012, 4:07:05 PM10/9/12
to

carilda...@gmail.com

unread,
Dec 29, 2012, 4:22:12 PM12/29/12
to
I tried adding the key to the registry and my script worked just fine but control never returned to the command prompt - Win7 Enterprise.

However, the /K <batch-file-path> performed correctly.

Char Jackson

unread,
Dec 29, 2012, 6:31:39 PM12/29/12
to
On Sat, 29 Dec 2012 13:22:12 -0800 (PST), carilda...@gmail.com
wrote:
That was nearly two years ago, but thanks for reporting on your
success.

0 new messages