Link to home
Start Free TrialLog in
Avatar of rortiz77
rortiz77

asked on

Is there a way to create alias in Windows 2008 just like in Linux Bash?

Is there a way to create aliases in DOS command prompt just like in Linux Bash?  I know of Doskey but how does it keep your information?  If I exit it gets lost.  Is there a profile that can be created to allow it to save it?
Avatar of Chris
Chris
Flag of United Kingdom of Great Britain and Northern Ireland image

you can use the set command but that won't keep it out of that session

i.e.

set backupshare=\\mycompany-dc01\backup
SOLUTION
Avatar of farzanj
farzanj
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Use setx /m command line
Avatar of rortiz77
rortiz77

ASKER

Farzanj's looks a bit easier to work with.  

Govvy, can you give an example of how it would work with SETX? For example, how would I alias ls=dir?
SETX LS DIR /M
This is the error I get:

C:\>setx LS DIR /M
ERROR: Access to the registry path is denied.
Easier way probably is just add a batch file called ls to your path, i.e. enter this in notepad and call it c:\windows\ls.cmd

@dir %*

The %* will pass any command line options to the apps.

If this is Win7 etc. you would need to do it as an admin, e.g.  start cmd.exe prompt as admin then:

cd /d c:\windows\system32
echo @DIR %* > ls.cmd

ls
Your command prompt needs to be run as Administrator
Govvy,

Didn't work as expected.


C:\>SETX LS DIR /M

SUCCESS: Specified value was saved.

C:\>LS
'LS' is not recognized as an internal or external command,
operable program or batch file.
setx sets environment variables.... not aliases of commands, unless I am missing another use?
dragon-it,

Yeah, that's what it seems to me.  And what I'm trying to do is just use aliases that can be stored for future use.  
Have you tried little one line (or whatever needed) batch files like suggested then?

Steve
Yeah, I tried this but it seems like I'd need a file per alias.  Is that correct?
yes... unless you want a generic name, e.g.

u ls

so you have u.cmd whcih takes first param as shortcut etc...

but easier then to type dir!
I did originally think I might be able to use the AppPaths area of the registry but have never been able to get it to work other than subsituting one exe for another, i.e. you can add in here:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths

or here

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ls.exe]
 @="c:\\window\\system32\\cmd.exe"

and ls.exe will launch cmd.exe, like in the same way that if you run "write.exe" it runs wordpad for you.... BUT I haven;t been able to add any command line arguments, and you'd have to do:

cmd /c dir

Steve
As to doskey.... you could stick a number of doskey entries in a batch file, or you can call it with a macro:

@echo off
doskey /macrofile=c:\somepath\doskey-macro.txt
cmd /k

doskey-macro.txt contains

ls=dir
etc.

You can amend registry entries so that a batch autoruns when launching a cmd.exe session or just use a shortcut to this batch to start yourself a cmd windows with them in place.

Alternatively if you haven't looked at it in the link given by fanranj above it shows similar where doskey is added to the autorun key I mention above and an alias defined of "alias".  Therefore you can add aliases in the same way as you are used to with unix shells... clever stuff!

Haven't had a chance to try it like this but looks like it could be useful.

Steve
Well, the world of registries has always been a bit of a mystery.  What all would I have to add in there?
This is following the path:
"HKEY_CURRENT_USER\Software\Microsoft\Command Processor"
Registry-Editor-2011-11-04-09-34.png
Right click the command processor and choose New --> String Value
Value name is "AutoRun"
Value of it is "C:\somedir\yourscript.cmd"

And then in yourscript.cmd either

@doskey /macrofile=c:\somepath\doskey-macro.txt

and then list all your macros in doskey-macro.txt

or list them all one by one:

@echo off
doskey ls=dir
doskey cat=type

etc.

cat / ls / grep is about the limit of my unix shell usage so make the rest up yourself :-)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Steve,

This looks exactly like what I want!  So, I understand the "Save" part...but it doesn't look like I need to type "LOAD" to use the aliases.  When would I use that?
Very good job with explaining :-)
sorry was away at fireworks display with the kids.... I think the idea is ... Any aliases you add is like using doskey command, i.e only for that session.  so alias save makes them permanent.  alias load i guess would only be needed if you messed up the aliases and/or wanted to put them back as they are.

Have enabled this in my own cmd prompt now too - had seen technique befoe but not as neat as with making an alias alias!

Steve
thanks.  cant't believe all that was only 900 points mind :-(