1.

Solve : Run wzzip from anywhere?

Answer» <html><body><p>Quote from: Geek-9pm on March 25, 2015, 02:41:26 PM</p><blockquote>Some common utilities are 'portable' in the sense taht they do not require installation in a specific directory and do not have DLL or other things needed. <br/></blockquote> <br/>I think this can be expanded somewhat.<br/><br/>A program being "installed" effectively ensures the software environment will allow the software to run. This could mean installing required runtimes, registering COM components or .NET assemblies into the GAC, or initializing settings files or registry keys, associating files, installing say a Windows explorer extension, etc.<br/><br/>A "portable" program can be either a wrapped program- a wrapped program being launched via a wrapper program which effectively hooks all that programs attempts to read/write registry or other local system information and redirects it to perhaps a local INI file, or it can be a program that has the capability to operate in a portable fashion.<br/><br/>What makes this topic interesting is that by, say, modifying the path, you are creating your own special "install environment". That is, you can now run, say, wzzip, directly from the command prompt. But any <a href="https://interviewquestions.tuteehub.com/tag/batch-893737" style="font-weight:bold;" target="_blank" title="Click to know more about BATCH">BATCH</a> file you create will now require "installation" in the sense that you will have to make configuration changes to change the system path so the batch can access the program it requires. For example in this case if you want to in any way distribute- either amongst your own systems or even at large- a batch that uses winzip, realistically a user should only require that winzip be installed. They should not be required to <a href="https://interviewquestions.tuteehub.com/tag/manuallybrbr-2814100" style="font-weight:bold;" target="_blank" title="Click to know more about MANUALLY">MANUALLY</a> "install" your batch file by <a href="https://interviewquestions.tuteehub.com/tag/manipulating-1086096" style="font-weight:bold;" target="_blank" title="Click to know more about MANIPULATING">MANIPULATING</a> their system path variable so that winzip is accessible.<br/><br/>It is actually quite straightforward to implement this behaviour. There are a few pieces of information that come into play:<br/><br/>-using SET PATH or PATH commands in a batch script or command prompt will only change the PATH variable for the current session. This can be directly observed. If you create the following batch script:<br/><br/> Code: <a>[<a href="https://interviewquestions.tuteehub.com/tag/select-630282" style="font-weight:bold;" target="_blank" title="Click to know more about SELECT">SELECT</a>]</a>Set PATH=C:\somefolder;%PATH%<br/>echo %PATH%<br/>You can double-click and run it repeatedly all you want, but each run will not add an additional "C:\somefolder" to the front of the path; it will always be the existing PATH environment variable as set in system properties, with C:\somefolder on the front.<br/><br/>If you run it within the same session- repeatedly in a batch script or within a command prompt, then you will see that behaviour, and your path will get a duplicated folder path tacked onto the front with each run in that session.<br/><br/>Rather than have the batch script require that the system path be changed, you can simply verify the program you want to run is available on the path- if not, you look for it and add the folder to the path, otherwise you just use it as you want. you can use WHERE to see if a program is available. if it returns a non-zero errorlevel than you can go look for it in well-known install folders, and then try again; if you cannot find it in any known install folders, you can then show an error message. For example (Paths may need to be changed, I seem to remember Winzip using a "Niko Mak computing" folder or something, but that may be ages back):<br/><br/> Code: <a>[Select]</a>:retry<br/>where wzzip<br/>if errorlevel neq 0 goto setuppaths<br/>wzzip -params<br/>goto finished<br/>:setuppaths<br/>if exist C:\Program Files\WinZip\wzzip.exe set Path=C:\Program Files\WinZip;%Path%&amp;goto retry<br/>if exist C:\Program Files (x86)\WinZip\wzzip.exe set Path=C:\Program Files (x86)\WinZip;%Path%&amp;goto retry<br/>echo Winzip could not be found in it's default install location.<br/>:finished<br/><br/>Doing it this way means:<br/><br/>-Any user of the batch will only require the program you use to be installed in it's default install folder- they won't need to manipulate their path variable themselves or make other permanent changes to their system<br/>-If a program is available in multiple variants- perhaps a 64-bit and 32-bit version, you can prefer the 64-bit version on systems that have it without it being a requirement and without, again, any explicit action by the user before running your software.<br/><br/>This implementation is itself, imperfect, of course- squashman's method- using start- is far more reliable and will allow the program to be launched regardless of where it is installed. The alternative- without start- of getting the same result would require using reg query to query the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\wzzip.exe (or winzip.exe, perhaps?) key, retrieving the the path value, parse that output to get the path itself and then add that path to the Path variable in the same manner as above. Quote from: strollin on March 26, 2015, 09:15:34 AM<blockquote>The problem with running a batch file to add it to the PATH is that each time you run the batch file it will add it again.<br/></blockquote> <br/>Yes, this will <a href="https://interviewquestions.tuteehub.com/tag/happen-1015459" style="font-weight:bold;" target="_blank" title="Click to know more about HAPPEN">HAPPEN</a> if you run the batch file in the same cmd window again and again,<br/>but adding a setlocal as shown below will fix that.  <br/><br/>I think we agree that adding the folder permanently to the path is the better way to go. <br/><br/> Code: <a>[Select]</a>echo off<br/>setlocal<br/>call "d:\bin.bat"<br/>wz -params<br/></body></html>


Discussion

No Comment Found