Adding doskey for an application in windows8 - windows

Please guide me as to how to add persistent doskey for an application in windows 8.
Also tell me how those doskey can be made to work in git bash?
All I know is how to make temporary doskey as
#doskey ls=dir
And in git I know of aliases as
alias dir=ls

You can edit your registry key HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun to run a batch file everytime cmd.exe runs. If you add your doskey commands into that batchfile then every cmd.exe instance will have your doskeys setup.
See my post for more info: http://www.declancook.com/aliases-in-windows-command-prompt/

doskey will load and work in a cmd.exe window.
It is not designed to work within other applications.

Related

Windows command prompt custom commands

I am looking for a way to customise some of the Windows command prompt (cmd.exe) commands. I would like the new command to be called instead of the one defined by Windows to do almost the same thing except some minor customisations. An example could be with the pushd command print a message saying which directory is changing to. This could be useful, for example, to have the output a .bat script parsed by another tool.
As an example, pushd.bat would look like:
#echo off
pushd %1
echo Entering directory `%cd%'
...but where should I put this so that it gets called instead of the internal command pushd?
You should not customize internal commands because some of these commands go all the way back to DOS and have hidden bugs and features that some tools might rely on and it is unlikely that you will implement them correctly.
You can add custom aliases with doskey. These are better than batch files. They allow you to add certain mini scripts that help you in your daily command line usage. These can actually override the names of internal commands.
doskey pushd=echo Entering $*^&pushd $*
pushd c:\Windows
You can add your doskey commands to HKCU\Software\Microsoft\Command Processor\AutoRun in the registry but you really need to be careful if you use it to change existing commands. I recommend that you invent new names for your commands.

how to create a batch file to execute command in Cmder?

I wanna create a batch file that launch Cmder and then execute some commands inside the Cmder. I know how to launch Cmder using a batch file but don't know, how to write/execute a command in Cmder using batch file.
I tries this...
#echo off
cd "C:\Program Files\cmder"
start Cmder.exe
cd "D:\Path"
Above code launches the Cmder.exe but doen't execute cd "D:\Path" inside Cmder.
You asked how to improve / fix
#echo off
cd "C:\Program Files\cmder"
start Cmder.exe
cd "D:\Path"
There are a few issues that could be better addressed in different ways. but as they appear not to be your real Issue I will simply suggest an alternative way to invoke cmder could be:-
#echo off
start "Cmder" "C:\Program Files\cmder.exe" /START "D:\Path"
I dont have a D drive so accept here my Path is e:\Path and the above command would result in the desired action, like so:-
In comments you explained that was not the intent but to run a cmd within cmder that would start first by changing the start directory.
What users need to acknowledge is that cmder is a very lightweight configuration wrapper around ConEmu and it is there that commands are processed as defaults or "Tasks"
So the request is to start up default Cmder and automatically change to e:\path where I can run further commands. One way to achieve this:-
Is to add my own MyAutoRun Task so I can invoke as
start "Cmder" "C:\Program Files\cmder.exe" /TASK MyAutoRun
Which is stored as a ConEmu Task like this:-
The full but limited range of Cmder arguments can be found at https://github.com/cmderdev/cmder#cmderexe-command-line-arguments
For configuring ConEmu tasks you need to see https://conemu.github.io/en/Tasks.html

Windows CMD interpret code following alias

Is it possible to get windows process some code after an alias in the cmd? Basically I want to do sth. like this:
doskey mysvn = D:\portableSVN\bin\svn.exe --config-dir D:\portableSVN\config
mysvn up
mysvn ci -m "message"
This does not work, after interpreting mysvn it just stops and I get:
Subcommand argument required
Type 'svn help' for usage.
Currently, I modify the PATHfor the session and use the standard config folder, but I would rather not have my credentials and proxy settings on every pc I use my portable svn on. Of course I can delete them afterwards, but still they are recoverable.
If necessary, it is also possible to execute batch files as long as they don't need admin rights.
Try with
doskey mysvn=D:\portableSVN\bin\svn.exe --config-dir D:\portableSVN\config $*
See doskey /? for more information

Porting shell functions to cmd.exe: Is it possible to automatically source scripts on startup?

I'm porting a Linux tool-set that makes frequent use of shell functions to provide certain functionality. These functions are automatically sourced when you start a new shell and include things like changing the working directory, which is nigh impossible with stand-alone programs because child processes can't change their parent's environment.
For example, there is a function cdbm which changes the working directory to one that was previously bookmarked. Now I want to do the same on Windows, but I'm stuck with cmd.exe. As far as I understand the scripts could be ported to jscript, vbscript or plain batch, which shouldn't be a problem. But how do I make sure they automatically get sourced on startup and live in the shell's environment?
According to help cmd:
If /D was NOT specified on the command line, then when CMD.EXE starts, it
looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if
either or both are present, they are executed first.
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
and/or
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
As a test, in regedit I created a new key in the HLM branch shown above called "AutoRun" with the string value "echo Hi". When I started a new instance of cmd I got:
Microsoft Windows [Version 6.0.6000]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
Hi
C:\Users\Username>
You could put in the name of a script to run instead (I would put in a fully specified path to the script or one with a environment variable in it like "%HOMEPATH%\scripts\scriptname" (including the quotes in case there are spaces in the name).
Edit:
The registry key has some side effects. One example is help. If I have the echo command above, for example, in the AutoRun when I type help vol I get a "Hi" right above the help text. Doing vol /?, though doesn't do that.
You can set either of the following registry keys to a batch file or other executable to run that program when CMD is started:
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
A batch file should be able to change the current directory of the executing CMD process with the CD command, as it doesn't run as a subprocess. You can disable the autorun behaviour by supplying /D as a switch to CMD.
See CMD /? for more details.
Since cmd doesn't allow you to define functions in global scope, I'm a little at a loss to understand what exactly you're trying to achieve by auto-sourcing a script at startup. I tend to include a batch file directory in my path where you can put batch files I regularly need.
Look at cygwin.

How Symfony did its command alias?

Apologies my french english ...
I would like to create an alias in Windows XP cmd, like Symfony.
This code works perfectly, but resets every system boot :
doskey kCLI= php C:\wamp\www\KinkamaCLI\KinkamaCLI.php
I tryed to put a .bat in "start" folder, but I think it's not beautifull, and I feel it doesn't work, because I can't see the generate batch file :
echo doskey kCLI= php C:\wamp\www\KinkamaCLI\KinkamaCLI.php >> C:\Documents and Settings\sartois\Menu Démarrer\Programmes\Démarrage\kCLI.bat
I would to create a permanent alias. Enter :
kCLI my-command-here
And not :
php C:\wamp\www\KinkamaCLI\KinkamaCLI.php my-command-here
I don't know how symfony proceed, but may be you should check your %PATH% environment variable and add this new path. Check http://support.microsoft.com/kb/310519 on how to modify this variable.
cmd.exe has support for running a list of commands at startup, add your doskey command to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\AutoRun (Note that it is possible to start cmd.exe with /D to skip the autorun entry. I have also seen problems with doskey.exe crashing in 3rd party apps when autorun entry is parsed)

Resources