Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

A little utility to shell to the command prompt

  • Filter
  • Time
  • Show
Clear All
new posts

  • Vidar Hanto
    Originally posted by Michael Mattias View Post
    From a newsgroup Sept 2001:
    > ... " /k cd" ...
    A comment on the " /k cd" variant:

    You will probably want to use "cmd.exe /k cd" instead, since that will invoke the win32 console which is more powerful in today's environment. is the MS-DOS interpreter and is much less flexible - although for basic use the differences aren't too obvious. MS-DOS simulation was more important before, which probably explains why the sept 2001 newsgroup mention In addition, the "/k" switch isn't documented (checked against XP), but it works and behaves as prescribed.

    Also, in this scenario - under XP - the "cd" part is superfluous, and a simple "cmd.exe /k" will do.

    For good measure, you probably would want to have a as-fast-as-possible startup of cmd.exe and not spend time waiting for your system to search the path looking for cmd.exe, in which case you would want to duplicate the lead-in from your standard command prompt shortcut, which is something like "%SystemRoot%\system32\cmd.exe".

    However, this approach will not resolve environment variables for you, so you will need to resolve it manually. In the end you should end up with something like: "C:\Windows\system32\cmd.exe /k" depending on the value of your %SystemRoot% variable (check it using the "SET <enter>" command from within a console window).

    The method under XP is also different from described above. Proceed as follows:
    - Start Explorer.
    - Select Tools>Folder Options>File Types>File Folder
    - Click "Advanced"
    - Click "New"
    - In "Action" enter the text to be displayed in Explorer, e.g. "Console window"
    - In "Application" enter your command "C:\Windows\system32\cmd.exe /k"
    - Click "OK" and close all dialogs to return to the explorer main window.
    - Right-click on a folder, select "Console window" and - voil√°! There it is!

    BEWARE: Under XP this is a one-way thing only - you will not be able to edit nor remove it afterwards! One error here, and it's in there forever... unless you edit the registry directly, in which case you may enter, edit and remove this command as you wish. Four entries are necessary:

    Create the following two keys:
    In key
    modify the default name to whatever is the text you want to be displayed in Explorer, e.g. "Console Window". Don't enter the double quotes.

    In key
    edit the default name to the command to be executed, e.g. "C:\Windows\system32\cmd.exe /k". Don't enter the double quotes.

    As can be seen default registry values are all REG_SZ values, and REG_SZ values don't expand environment variables so you need to expand the command manually.

    Final comment (something for PB staff?):
    In my preview of this post, the key "HKEY_CLASSES_ROOT\Directory\shell\Console_window\command" was displayed with a space between "\c" and "om" yielding "\c ommand" both places until I enclosed the lines with CODE tags. I have not edited the lines themselves after inserting the CODE tags. In this final comment, the same string is displayed as "\ command" with a space between the last back-slash and "command". Time will show if this behaviour transfer into the live forum.


    Leave a comment:

  • Travis Siegel
    One thing I do in addition to this is to assign a hot key to the prompt setup in one of the previous methods.
    Then, when I need a dos prompt, I can hit alt-ctrl-\ and poof, instant dos prompt.
    You can set this in the properties of the shortcut setup in one of the previous methods.
    (though I wasn't aware of the /kcd parms, will have to try that one.

    Leave a comment:

  • Jim Padgett
    Power Toy?

    My Bad!! wrong forum. Please delete me.

    Leave a comment:

  • George Bleck
    Just to round off methods, an alternate way which I use is to create a shortcut to CMD but delete the "Start in" path of %WINDIR% in the properties.

    I use this often when workin on CC programs or PBWIN programs that require command line options.
    Last edited by George Bleck; 26 Oct 2008, 10:28 PM.

    Leave a comment:

  • Michael Mattias
    From a newsgroup Sept 2001:
    > Most people use TWEAKUI, but you can add this feature via Explorer's,
    > View>Options>File_Types, then move down the list to "Folder", press "Edit"
    > then "New". Now in the action field type "Command Prompt Here" and in the
    > field below it type " /k cd" and press "OK".

    Leave a comment:

  • Mark Strickland
    Another Approach

    I have a similar utility that will open up a command window in the specified folder without the need to put a program in that folder.

    You put the utility in the SENT TO folder and when you right click you can select the utility from the right click popup menu. You can right click on a file or folder in Windows Explorer and open the command window. You can also right click on a short cut and it will take the working folder from the short cut and open the command window there.

    If anybody has any interest search the source code forum for "Jump2DOS".

    Leave a comment:

  • Gary Peek
    started a topic A little utility to shell to the command prompt

    A little utility to shell to the command prompt

    I wish I had thought of this a long time ago. I have the need to quickly go to the command prompt in a particular folder to do some DOS tasks.

    The following is a little program that can be placed in a particular folder and run from an icon on the desktop. Maybe this has been done before or is too elementary, but here you go...

    If you want all of the files you can go to, otherwise you can remove the reference to the resource file if you just want to use the source.

                      BYVAL PrvInst AS LONG, _
                      BYVAL CmdLine AS ASCIIZ PTR, _
                      BYVAL CmdShow AS LONG) EXPORT AS LONG
    LOCAL hShell AS LONG
    hShell = SHELL(ENVIRON$("COMSPEC"), 1)