You are here

A Simple batch file to Portablize (most) applications

15 posts / 0 new
Last post
crazy2be
Offline
Last seen: 12 years 3 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
%checkforerror%
)
echo Adding Registry enteries...
for /L %%b in (1,1,%regkeynumber%) DO (
reg import %applicationname%RegEnteries%%b.reg > temp.txt
%checkforerror%
)
echo Changing path...
for /F "" %%c IN ('Reg query %driveregkey%') DO (
reg add %driveregkey% /d %currentdrive%%%~pa /f > temp.txt
%checkforerror%
)
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/
%application%
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
%checkforerror%
)
echo Replacing Original Enteries...
for /L %%e IN (1,1,%regkeynumber%) DO (
reg import %applicationname%OldRegEnteries%%e.reg > temp.txt
%checkforerror%
)
echo Done! (window will close automaticly)
ping 0.0.0.0 >nul
::pause
:end
exit

Zach Thibeau
Zach Thibeau's picture
Offline
Last seen: 8 years 10 months ago
Developer
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 PortableApps.com use NSIS as our base to portablelize our apps here and does the job more efficiently too.

your friendly neighbourhood moderator Zach Thibeau

crazy2be
Offline
Last seen: 12 years 3 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.

Devo
Offline
Last seen: 6 days 1 hour 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.

SilentWalker
Offline
Last seen: 12 years 3 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
EspaÑaks's picture
Offline
Last seen: 2 weeks 2 days ago
Joined: 2008-08-21 05:17
At least, not as easy as VB6

At least, not as easy as VB6

Eiñ??? A siñature????

OliverK
OliverK's picture
Offline
Last seen: 1 year 3 months ago
Developer
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

dudekracked
Offline
Last seen: 6 years 6 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, http://www.xiberpix.net/SqirlzReflect.html, a program for making water reflection effect. it has 2 reg keys that are prominent,

1.
[HKEY_CURRENT_USER\Software\xiberpix]
[HKEY_CURRENT_USER\Software\xiberpix\Sqirlz Water Reflections]
[HKEY_CURRENT_USER\Software\xiberpix\Sqirlz Water Reflections\Preferences]
"Noprompt"=dword:00000001
[HKEY_CURRENT_USER\Software\xiberpix\Sqirlz Water Reflections\Settings]

2.
[HKEY_LOCAL_MACHINE\SOFTWARE\xiberpix]
[HKEY_LOCAL_MACHINE\SOFTWARE\xiberpix\Sqirlz Water Reflections]
"Directory"="C:\\Program Files\\Sqirlz Water Reflections"
"Version"="2.5"
"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
Ph4n70m's picture
Offline
Last seen: 3 months 3 weeks 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.>>"%TEMP%\CleanRegistry.reg"
echo [-%fullregkey%]>>"%TEMP%\CleanRegistry.reg"
reg import "%TEMP%\CleanRegistry.reg"
del "%TEMP%\CleanRegistry.reg"

crazy2be
Offline
Last seen: 12 years 3 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
powerjuce's picture
Offline
Last seen: 11 years 7 months ago
Developer
Joined: 2007-09-20 21:34
o really...

So you figured it out...
We have been working here at Portableapps.com 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
Firefox
Thunderbird
Frets On Fire
Sumtrapdf
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
ZachHudock's picture
Offline
Last seen: 4 years 8 months ago
Developer
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
powerjuce's picture
Offline
Last seen: 11 years 7 months ago
Developer
Joined: 2007-09-20 21:34
lol tats annoying...

i was just about to edit it and u replied

Regards
~powerjuce

Please search before posting. ~Thanks

crazy2be
Offline
Last seen: 12 years 3 months ago
Joined: 2008-08-22 20:56
AS I STATED BEFORE...

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.

Ed_P
Offline
Last seen: 3 years 11 months 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>

Ed

Log in or register to post comments