You are here

A Simple batch file to Portablize (most) applications

15 posts / 0 new
Last post
Last seen: 13 years 5 months ago
Joined: 2008-08-22 20:56
A Simple batch file to Portablize (most) applications

You can generally use this batch file to portabalize alot of things. Just change the variables to your needs (the set blah=blah lines)

[edit] Fixed to be automatically minimized [/edit]

@echo off
if NOT "%1" == "/Added" (
start /MIN "ShellWM Loader" %0 /Added
goto end
) else (
echo Loading...
:: Change these to your app's
:: applicationname is the name of the app
:: (no spaces please)
:: application is the file to run, "" if it has spaces
:: regkey1 is the branch created by the application
:: (Usually HKCU\Software\%applicationname%).
:: ::You can set regkeynumber to any number, just be sure temp.txt
rem echo reg export %regkey1% %applicationname%OldRegEnteries%%a.reg
echo Adding Registry enteries...
for /L %%b in (1,1,%regkeynumber%) DO (
reg import %applicationname%RegEnteries%%b.reg > temp.txt
echo Changing path...
for /F "" %%c IN ('Reg query %driveregkey%') DO (
reg add %driveregkey% /d %currentdrive%%%~pa /f > temp.txt
echo Starting %applicationname%.
echo ********************************
echo ****Do not close this window****
echo ********************************
echo If you do, your settings will not be saved,
echo or the registry enteries removed.
echo Exporting current settings...
for /L %%d IN (1,1,%regkeynumber%) DO (
rem set nothing=%%d
reg export %regkey1% %applicationname%RegEnteries%%d.reg > temp.txt
echo Replacing Original Enteries...
for /L %%e IN (1,1,%regkeynumber%) DO (
reg import %applicationname%OldRegEnteries%%e.reg > temp.txt
echo Done! (window will close automaticly)
ping >nul

Zach Thibeau
Zach Thibeau's picture
Last seen: 1 year 1 month ago
Joined: 2006-05-26 12:08
While yes your batch file is

While yes your batch file is ok not all people like looking at a command prompt when launching the app. We here at use NSIS as our base to portablelize our apps here and does the job more efficiently too.

your friendly neighbourhood moderator Zach Thibeau

Last seen: 13 years 5 months ago
Joined: 2008-08-22 20:56
nsis is better, but batch is easier

NSIS is great, it doesn't show a command window, but there are a few reasons i used a batch file in this case:
1. It is easy for anyone to use and modify; they can simply right click -> edit
2. You don't need an entire programing language for something this simple
3. there is no way to (portability) create and edit NSIS launcher files

and as for it being for efficient, i don't really know how that is possible. the batch file process (cmd.exe) uses half of the resources of the NSIS process.

i realize why NSIS is used, but for apps that have no NSIS launcher, people can use this batch file in the meantime.

Last seen: 1 month 3 days ago
Joined: 2007-09-04 14:55
Launchers can be created portably

All you need is Notepad++ to be able to edit nsi files portably. Really any text editor could be used, but Notepad++ is much easier to use. If you look in the beta forums you will find NSIS Portable. I use it to compile launchers while I'm at work where I can't install any programs. It works like a charm.

It may not be as simple to initially learn, but the end result is much cleaner and it can be done portably.

Last seen: 13 years 5 months ago
Joined: 2008-11-06 12:23
so can u use..

notepad++ portable can b used in place of nsis portable....or do i actually need 2 use the programming lang. and where can i learn nsis? i use vb6 in school but is nsis hard?

EspaÑaks (not verified)
At least, not as easy as VB6

At least, not as easy as VB6

OliverK's picture
Last seen: 2 years 5 months ago
Joined: 2007-03-27 15:21
search for HM NIS Edit

search for HM NIS Edit Portable

Too many lonely hearts in the real world
Too many bridges you can burn
Too many tables you can't turn
Don't wanna live my life in the real world

Last seen: 7 years 8 months ago
Joined: 2008-08-05 11:28
Automatic Removal of Registry Entry

hello crazy2be, thank you for this batch file, i have some problems though, hope you can help me,

1.) is it possible to add a way to automatically remove registry entry after using program, i dont want to leave any trace of registry on the host computer. i was able to do this manually by add (-)minus sign to the exported registry key, i want to add it on your batch file but i dont know how to do include it.

2.) im trying to make sqirlz water reflection portable,, a program for making water reflection effect. it has 2 reg keys that are prominent,

[HKEY_CURRENT_USER\Software\xiberpix\Sqirlz Water Reflections]
[HKEY_CURRENT_USER\Software\xiberpix\Sqirlz Water Reflections\Preferences]
[HKEY_CURRENT_USER\Software\xiberpix\Sqirlz Water Reflections\Settings]

[HKEY_LOCAL_MACHINE\SOFTWARE\xiberpix\Sqirlz Water Reflections]
"Directory"="C:\\Program Files\\Sqirlz Water Reflections"
"Uninstaller"="C:\\WINDOWS\\Sqirlz Water Reflections Uninstaller.exe"

my problem is that the program has two registry keys, in HKLM and HKCU, how do you tackle this? can i set a regkey 2?

and last 3.) could you elaborate more with the driveregkey? i dont know how to use it. are you talking about like the example above? though sqirlz water reflection doesnt really rely on the directory in HKLM, i was able to use it on other directory.

thank you!

Ph4n70m's picture
Last seen: 1 year 6 months ago
Joined: 2007-01-12 19:22
1) You can remove using

1) You can remove using this:

set fullregkey=HKEY_CURRENT_USER\Software\YourApplication
echo Windows Registry Editor Version 5.00>"%TEMP%\CleanRegistry.reg"
echo [-%fullregkey%]>>"%TEMP%\CleanRegistry.reg"
reg import "%TEMP%\CleanRegistry.reg"
del "%TEMP%\CleanRegistry.reg"

Last seen: 13 years 5 months ago
Joined: 2008-08-22 20:56
I need to work on that...

I'll make a new version that can deal with multiple entries, and will be hidden (minimized) when you run it.

powerjuce's picture
Last seen: 12 years 9 months ago
Joined: 2007-09-20 21:34
o really...

So you figured it out...
We have been working here at for a good three(?) years now.
There are reasons that your script does not work well.
It looks bad starting with a cmd screen. Using NSIS we have a clean startup.
Also NSIS makes it an executable which people cannot edit and thereby CANNOT MESS UP!!.
Batch files are often blocked in places of work, or in schools as is cmd so basing the ENTIRE launcher on a batch file does not work now does it?
Continuing on...
There are apps like... oh I don't know
Frets On Fire
that move files around!!!
How does your script deal with them?
O wait it does not.
We also have to change environmental variables so that we can store data more effiently.

All of this can be done with batch, I kno, but then it won't be simple, and at that point why not just use NSIS?

Please search before posting. ~Thanks

ZachHudock's picture
Last seen: 11 months 1 week ago
Joined: 2006-12-06 18:07
chill out powerjuce.....that

chill out powerjuce.....that comment seems quite harsh.

The developer formerly known as ZGitRDun8705

powerjuce's picture
Last seen: 12 years 9 months ago
Joined: 2007-09-20 21:34
lol tats annoying...

i was just about to edit it and u replied


Please search before posting. ~Thanks

Last seen: 13 years 5 months ago
Joined: 2008-08-22 20:56

This is not meant as *any* sort of permanent solution. It is designed on as a temporary measure, and i know it will only work for some applications. I know that the CMD screen is ugly, and is blocked in some places, but you can use a bat2exe if you really want (or make a C++ program and just use System())

i know that this is really a bad solution, but it allows people to portabalize many applications that do not yet have NSIS scripts written for them. it was never intended as any sort of permanent solution.

Please read my replys to questions that have already been raised before posting. thank you.

Last seen: 5 years 1 month ago
Joined: 2007-02-19 09:09
I like your CMD script.

The command line brings us closer to the machine we're working on. GUI's are fine for those who don't like getting their hands dirty.

Kinda like getting under the hood to fix your car or using a cell phone to call your boy friend to come fix it. <bg>


Log in or register to post comments