Windows: script / program for a USB key that opens the console and sets the path and working directory

The purpose of this question is to create a portable Windows script / program that will help users run (console) programs directly from a USB key (not necessarily through autorun, though). Thus, the script / program does the following when double clicked:

  • Launch the console ( cmd will) and give the DOS command prompt,
  • Set the current directory to a specific WorkingDir directory on a USB key (which contains various [Python] programs),
  • Set the path so that the user can run the command (python.exe) found in another USB key directory (so that the user can run the various Python programs found in WorkingDir ).

All of this is based on Portable Python , which is located on a USB keyboard. I would also like to just put the contents of the key on the hard drive and use it from there.

I tried to write a file containing commands like:

 PATH=..\"Portable Python 2.7.2.1\App":%PATH% cd WorkingDir cmd 

but I'm not sure what to call it so that Windows starts it (and therefore I could not verify whether this command would work).

I don't know much about DOS and Windows, so any help would be greatly appreciated!

+4
source share
2 answers

In fact, in the windows you use; to separate paths :) And you shouldn't use .. like that. You can use% CD% to get the current directory, and then move from it. And do not use quotation marks. In addition, you can put @ in front of any command that you do not want to send to the console.

You can put this in run.bat (this should work: P):

 @PATH=%PATH%;%CD%\..\Portable Python 2.7.2.1\App @cd WorkingDir @cmd 

And then just double click on it and it will open the commmand command just the way you want it. Or maybe you can add the autorun.inf file to open it automatically.

+3
source

You need to create two files:

autorun.inf

 [autorun] open=cmd.exe "Python Console" /k autorun.cmd action=Open Python Console... 

autorun.cmd

 @Echo Off CD %~d0\WorkingDir Path %Path%;%~d0\Portable Python 2.7.2.1\App 

The phrase %~d0 is the drive in which the command file is located, namely the letter of the flash drive (E :).

Now I came across two small icons. There was already a hidden, system readonly autorun.inf file on my USB drive. I had to unprotect with the following command before I could edit it.

 Attrib autorun.inf -r -s -h 

My second hiccup is that Windows 7 will not start from a USB drive. You must right-click the drive in Explorer and select "Run Python Console ..."

+3
source

All Articles