Adding a new DosKey command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Quisquose
Posts: 41
Joined: 13 Jul 2016 19:25

Adding a new DosKey command

#1 Post by Quisquose » 23 Oct 2023 13:53

I have an 'autorun' script that gets called whenever I start a cmd session. In this file I have (among other things) various doskey commands such as:

Code: Select all

doskey dh=echo(^&dir /a:h /o:g
doskey sid=echo(^&wmic useraccount get name,sid
doskey dkh=echo(^&doskey /history ^| more
doskey fon-=echo(^& echo Fonts folder is 'disabled' ^& attrib -s -r c:\windows\fonts
doskey fon+=echo(^& echo Fonts folder is 'enabled' ^& attrib +s +r c:\windows\fonts

....

etc,
I set them up ages ago, and they have all been working great ever since, so I thought that it would be trivial to add a new command by just copying the format of the existing doskey entries (I should have known that things can never be that simple).

All I wanted to do was to have lv run this command:

Code: Select all

echo list volume | diskpart
I tried:

Code: Select all

doskey lv=echo(^& echo list volume ^| diskpart
but all I get is: 'lv' is not recognized as an internal or external command

I tried numerous variations, but to no avail.

mataha
Posts: 32
Joined: 27 Apr 2023 12:34

Re: Adding a new DosKey command

#2 Post by mataha » 23 Oct 2023 14:29

Try:

Code: Select all

doskey lv=echo(^& echo list volume $B diskpart

Quisquose
Posts: 41
Joined: 13 Jul 2016 19:25

Re: Adding a new DosKey command

#3 Post by Quisquose » 23 Oct 2023 16:07

Thanks, but that didn't work either (it gave the same 'not recognized' message).

However, I have managed to find the problem ..... (me!).

I had recently connected a backup drive that has the same layout as my main drive, and somehow the shortcut that contains my startup config and autorun script decided to update its path. So it was still pointing to the correctly named file, but on another drive. That's why everything still worked, but when I updated the cmd file on my main drive, those changes did not take effect (because an older version of the file was being used on another drive). :roll:

Anyway, I edited the shortcut to fix the path back to my main drive and the new 'lv' doskey command now works,

While I am here, I have another question about doskey that perhaps someone can shed light on for me.

I know that you can string things together in order to have a sequence of commands run from a doskey, but is it possible to recreate something like the code below without actually having to save into a separate file and then call that from the doskey. I prefer, whenever possible, to not have things scattered around in different files unless absolutely necessary (because things are more prone to breaking when they are reliant on other files that could get moved, renamed or deleted etc.)

Code: Select all

for /f %%A in ('"prompt $H &echo on &for %%B in (1) do rem"') do set BS=%%A
echo list volume > %temp%\listvol.txt
echo.
echo   Disk Volume Information
echo.  -----------------------
diskpart /s %temp%\listvol.txt | findstr "Volume ###" > %temp%\lvoutput.txt
echo.
type %temp%\lvoutput.txt | findstr /V /C:"Microsoft DiskPart"
echo.
Doskey is kind of fussy about things, so I doubt I could just daisy chain the command together and still have them work. I'm not particularly wedded to the method above, it's just that it's the only method I have for cleaning up command output (I prefer to see only the actual information and not all of the junk branding and copyright text which just clutters things up).

I have not been able to find any (intelligible) guides that show how to format or amend the outputted text of a command, so I'm stuck with the methods I have.

Joe Caverly
Posts: 18
Joined: 11 Jul 2018 05:05

Re: Adding a new DosKey command

#4 Post by Joe Caverly » 25 Oct 2023 07:56

Maybe use this as a starting point;

Code: Select all

U:\>echo  Disk Volume & echo. ----------- & ((echo list volume | diskpart) | findstr "Volume ###")
 Disk Volume
 -----------
  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  Volume 0     D                       DVD-ROM         0 B  No Media
  Volume 1     C                NTFS   Partition    465 GB  Healthy    Boot
  Volume 2                      NTFS   Partition    499 MB  Healthy    Hidden
  Volume 3                      FAT32  Partition     99 MB  Healthy    System
  Volume 4     E   New Volume   NTFS   Partition   1863 GB  Healthy
  Volume 5     F   My Book      NTFS   Partition   2794 GB  Healthy
Ref: https://ss64.com/nt/syntax-conditional.html

Joe

mataha
Posts: 32
Joined: 27 Apr 2023 12:34

Re: Adding a new DosKey command

#5 Post by mataha » 25 Oct 2023 11:47

Does this answer your question? Obviously you have to run it from an elevated command prompt.

Code: Select all

> doskey lv = ((echo   Disk Volume) ^& (echo   -----------) ^& (echo list volume) ^| diskpart ^| findstr "Volume ###" ^| findstr /v /c:"Volume ###")
> lv
  Disk Volume
  -----------
  Volume 0     D                       DVD-ROM         0 B  No Media
  Volume 1     C                NTFS   Partition    465 GB  Healthy    Boot
  Volume 2                      NTFS   Partition    499 MB  Healthy    Hidden
  Volume 3                      FAT32  Partition     99 MB  Healthy    System
  Volume 4     E   New Volume   NTFS   Partition   1863 GB  Healthy
  Volume 5     F   My Book      NTFS   Partition   2794 GB  Healthy

Post Reply