Link to home
Create AccountLog in
Linux

Linux

--

Questions

--

Followers

Top Experts

Avatar of rortiz77
rortiz77

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?

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of ChrisChris🇬🇧

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 farzanjfarzanj🇨🇦

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of GovvyGovvy🇺🇸

Use setx /m command line

Avatar of rortiz77rortiz77

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?

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of GovvyGovvy🇺🇸

SETX LS DIR /M

This is the error I get:

C:\>setx LS DIR /M
ERROR: Access to the registry path is denied.

Avatar of Steve KnightSteve Knight🇬🇧

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

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of GovvyGovvy🇺🇸

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.

Avatar of Steve KnightSteve Knight🇬🇧

setx sets environment variables.... not aliases of commands, unless I am missing another use?

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


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.  

Avatar of Steve KnightSteve Knight🇬🇧

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?

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Steve KnightSteve Knight🇬🇧

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!

Avatar of Steve KnightSteve Knight🇬🇧

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

Avatar of Steve KnightSteve Knight🇬🇧

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

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


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

Avatar of Steve KnightSteve Knight🇬🇧

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
Avatar of Steve KnightSteve Knight🇬🇧

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

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?

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Very good job with explaining :-)

Avatar of Steve KnightSteve Knight🇬🇧

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

Avatar of Steve KnightSteve Knight🇬🇧

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

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Linux

Linux

--

Questions

--

Followers

Top Experts

Linux is a UNIX-like open source operating system with hundreds of distinct distributions, including: Fedora, openSUSE, Ubuntu, Debian, Slackware, Gentoo, CentOS, and Arch Linux. Linux is generally associated with web and database servers, but has become popular in many niche industries and applications.