1

I'm trying to run some programs from a flash drive. Therefore, I want them to keep their data on the drive as well. I know how to do this using the following batch script;

APPDATA=%CD%
Program.exe

However, using multiple batch scripts is quite inconvenient. I've seen certain commands in the target section of a shortcut. For example when using a web browser;

"C:\Program Files\chrome\chrome.exe" http://"www.google.com"

Now, I'm trying to add the APPDATA=%CD% command into a shortcut, so that the data is kept on my flash drive instead of the host computer. Does anyone know how I can do this?

I'm using Windows 10, but the command should work on all modern Windows versions.

An example of what I'm trying to do.

  • Please provide a screenshot of the shortcut configuration you're trying... – Ƭᴇcʜιᴇ007 Dec 16 '15 at 20:37
  • Which version of Windows? Also, consider editing your question to include your comment. – Steven Dec 16 '15 at 20:37
  • Cool. Makes more sense now. ;) So, what makes you think adding that command as a argument to Launcher.exe will have any affect? I ask because that's what you're doing there, and it doesn't really line up with your mentioning of "batch"... – Ƭᴇcʜιᴇ007 Dec 16 '15 at 20:53
  • Why not just use portable chrome, portable firefox, ... – DavidPostill Dec 16 '15 at 21:05
  • @DavidPostill I think OP's Chrome example was unrelated to the actual task (which appears to be about Minecraft). – Ƭᴇcʜιᴇ007 Dec 16 '15 at 21:07
  • @techie then portable minecraft ;) – DavidPostill Dec 16 '15 at 21:10
  • 1
  • @DavidPostill I was going to say that, but I didn't want to go look if there actually was one. ;) hehe – Ƭᴇcʜιᴇ007 Dec 16 '15 at 21:11
  • I'm trying to do that, making a portable version of chrome, but I'm also trying to do this for a lot of programs. I want them to store their appdata on the USB drive, but I don't want to make a batch file for every one of them, so I'm trying to use the shortcuts. – Jaïr Paalman Dec 16 '15 at 21:14
  • You should use portable progams where you can. Then just create links as approriate to run the software from your main drive. – DavidPostill Dec 16 '15 at 21:24
  • What do you mean? – Jaïr Paalman Dec 16 '15 at 21:31
  • Portable programs by their very nature are completely self-contained and can be run from a USB drive. You can then create shorcuts on the main OS drive to run the USB program (but then you have the drive letter problem) or (better) create shortcuts on the root of the USB drive. Then you can open your USB drive in explorer (on any machine) and run the program(s). Other programs (like minecraft as detailed in my answer) can be made portable and run completely from the USB drive (even if they weren't designed to be portable in the first place). – DavidPostill Dec 17 '15 at 20:17

2 Answers2

2

It appears you are just appending APPDATA=%CD% to the Target field of a shortcut, as an argument for the "launcher.exe" program.

I don't think this is want you want/need, since appdata is a known Windows environment variable, and especially since %cd% only works from a command prompt.

To me it appears want you want to do is set the appdata environment variable, and then run the Launcher.

To set an environment variable from the command line, you need to use the keyword set.

So...:

  • Create a new text file (with Notepad.exe or whatever).
  • Add set APPDATA=%CD% to the file.
  • On the next line, add the full path to Launcher.exe (eg. c:\program files\minecraft\launcher.exe).
  • Save the file someplace, with a batch file extension (ie: whateverYouLike.bat)
  • Change the Target of your shortcut to point to the batch file you just made (instead of Launcher.exe). Ensure you keep the "Start in" ("Beginnen in") field the same, so that the target file is run in that folder's context

So now when you click the shortcut it'll run your batch file, and your batch file will first set the AppData environment variable, and then run the Launcher.exe.

  • Yes, I have already done that. Now, I'm trying to do this with a shortcut, as I'm trying to do this for multiple programs and I don't want to create a batch file for every one of them. – Jaïr Paalman Dec 16 '15 at 21:16
  • 1
    You should put that information into your question, so we don't suggest things that are only specific to the info offered and/or that you've tried already. – Ƭᴇcʜιᴇ007 Dec 16 '15 at 21:19
  • So you asked for "batch" help, yet you don't want to make batch files? How is making batch files (once) any more difficult than changing shortcuts for multiple files? Confusing.. :/ Anyhow, as I said, you can't do it the way you are trying. Perhaps try changing the "target" to set appdata=%cd% & c:\pathtofile\launcher.exe and see if that works (I don't think it will though). – Ƭᴇcʜιᴇ007 Dec 16 '15 at 21:24
  • I've tried. It didn't work. I guess it really is impossible then. The problem is that, I can't see the icons when I use batch scripts. I just thought there should be an easier way, but I guess there's not. Anyways, thanks for your help. – Jaïr Paalman Dec 16 '15 at 21:36
  • "I can't see the icons when I use batch scripts." See: Is it possible to change the icon of a MS-DOS bat file? -- Short version: make a shortcut to the batch file, then change the icon of the shortcut. :) – Ƭᴇcʜιᴇ007 Dec 16 '15 at 21:42
  • I've done that, but the icons disappear after the drive letter changes in a different host computer, and I use a lot of different computers. – Jaïr Paalman Dec 16 '15 at 21:47
  • 1
    @JaïrPaalman The portable mincraft link that I included in my answer also addresses how to deal with the icon issues: "Going the extra mile: Getting a Minecraft icon for the USB".You can use the same technique for any batch files you store on the USB drive. – DavidPostill Dec 17 '15 at 20:11
2

How do I make a portable version of Minecraft?

If we already had Minecraft installed, it's very easy to convert it to portable Minecraft. We still create the directories on the USB and download Minecraft.exe, but we copy the existing .minecraft folder from the disk to the USB.

To find the non-portable Minecraft folder, we can press the Windows key + R and type %appdata% at the "Run" window.

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 07a

Then, we just copy .minecraft to the data folder on the thumb drive.

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 07b

Create the batch to start portable Minecraft

Finally, we need to create a batch file to start Minecraft. This batch file will tell the Minecraft executable to use the folders on the USB, and not the HDD.

We just need to open a plain text editor, such as Notepad...

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 08

...and type:

set APPDATA=%CD%\data 
"%CD%\bin\Minecraft.exe"

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 09

Afterward, we save the file within the Minecraft Portable folder, along with the bin and data folders.

We can give it a name of our choice, such as "portable Minecraft", or "Minecraft portable", or "launcher". It is important that it has the ".bat" extension, and we have selected "All Files" in the "Save as type".

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 10

If we did it correctly, the system will recognize it as a Windows Batch File.

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 11

This is the file we will run to start the portable Minecraft.

Portable Minecraft: The first launch

The first time we start portable Minecraft, the PC needs to have internet access. It will download the runtime...

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 12

...set up the runtime, which can take a while on a slow USB stick...

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 13

...and then prompt for our Minecraft account credentials.

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 14

Once inside, it's a good idea to check that the proper folders on the USB are being used, instead of the system folders. We click on Edit Profile...

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 15

...and make sure the Game Directory and Executable are both on the flash drive.

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 16

We don't need to make any changes, just check that the paths are on the USB.

After that, we can click on Play. We wait as the system downloads the proper files...

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 17

...and a couple of minutes later, we are on the main menu.

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 18

With a good enough USB flash drive, there will be no difference as if we played off the HDD.

How to Create Portable Minecraft - Make a USB stick to Play Anywhere 19

Since we run the program once, we can now play offline on any PC with the same version of Windows. It won't even ask for the account credentials anymore, the one time was enough.

Source Portable Minecraft - Make a USB stick to Play Anywhere

DavidPostill
  • 156,873