Page 1 of 1

FAQ item: launch arguments

Posted: Fri Nov 20, 2015 1:40 pm
by webfork
EDIT: Thread overview: what follows is a discussion on ways to talk about how to launch programs with "-portable" or similar. While there are a number of different ways to go over this (many discussed below) usually the best way is just to use a launcher program like Asuite or PStart:
PStart Asuite
Right-click on a menu item and choose Edit. Image Right-click on a menu item and choose Property.Image
Enter argument Command Line Parameters field.Image Enter "argument" text in the Property field. Image
----------

So Specular brought this up over in the Treesheets entry:
Specular wrote:Do you think the line in the entry '... and launch with TreeSheets -p' will make sense to users? I mean, anyone technical will get it but wondering if there should be some FAQ link about it.
He's completely right. I've had this on my list of FAQ todo list for too long because I couldn't decide if I should use a batch file or what. Does this work?

Q: How do I launch a program with extras characters like "program.exe -portable"?

A: There are two ways to do this:
  • Use a launcher - The simplest way is to use a launcher program like Pstart, Asuite, or Splat you can enter the extra characters in a separate blank labeled "arguments" or "parameters". Examples:
  • Create a batch file
    1. Before you begin, unless you use a custom File Manager, you may need to disable the Windows feature that hides file extensions (e.g. .DOC, .MP3, etc.)
    2. In the same folder as the program you want to launch, create an empty text file.
    3. In this file, paste the launch code exactly as you see it in the entry. For example, the entry says to launch TreeSheets.exe -p, paste the italicized text and save.
    4. Save the text file and rename it launch.bat and then double-click on the file.

Re: FAQ item: launch arguments

Posted: Fri Nov 20, 2015 3:39 pm
by webfork
Shortcut method
  1. Right-click on the program and choose "Create shortcut"

    Image
    .
  2. Rename the shortcut to "PROGRAM_Portable" (e.g. Treesheets Portable)

    Image
    .
  3. Right-click on the shortcut and edit the "target" field to append the required start parameter. Example:

    C:\PORTABLE\TreeSheets\TreeSheets.exe

    C:\PORTABLE\TreeSheets\TreeSheets.exe" -p

    Example:
    Image

    If there are quotes present, just put the -p at the end of the text, outside the quotes.

This is an alternative method NickR pointed me to. He also had a system to avoid accidentally starting the EXE file by putting the main program in a subdirectory, but I wanted to get this additional method posted quickly.

Re: FAQ item: launch arguments

Posted: Fri Nov 20, 2015 4:11 pm
by smaragdus
This is a useful tutorial, thanks. However it is unclear to me why still so many developers insist of using AppData. Program uninstallers are usually never good enough and after a uninstallation of a program too much trash is left behind all over Windows.

Re: FAQ item: launch arguments

Posted: Fri Nov 20, 2015 4:52 pm
by webfork
smaragdus wrote:... it is unclear to me why still so many developers insist of using AppData. Program uninstallers are usually never good enough and after a uninstallation of a program too much trash is left behind all over Windows.
I think it's just a matter of training. Most developers start out working on installer-based program where AppData makes sense. I really don't have an explanation for the leftovers issue.

Re: FAQ item: launch arguments

Posted: Sat Nov 21, 2015 4:02 am
by SYSTEM
In the batch file method, it's best to insert "start" before the command, e.g.

Code: Select all

start TreeSheets.exe -p
That way the CMD window will close immediately, instead of staying until the program is closed.

----

I think the shortcut method uses an absolute path and is therefore not suitable if the drive letter can change.
smaragdus wrote:This is a useful tutorial, thanks. However it is unclear to me why still so many developers insist of using AppData. Program uninstallers are usually never good enough and after a uninstallation of a program too much trash is left behind all over Windows.
AppData has these advantages:
  • With roaming profiles (that can be used in organizations) settings stored in AppData will follow the user. In other words, if the user logs in to his/her account with a different computer in the company, the program will use the correct settings instead of defaults.
  • AppData is user specific. If multiple people share the same computer (in a family, for example), everyone can have different settings.
It is intentional that "program uninstallers are usually never good enough". Some people want settings to remain when they uninstall a program, so that they'll still be there if they reinstall the program in the future. Settings take up much less space than the actual program, so it's not important to remove them.

Re: FAQ item: launch arguments

Posted: Sat Nov 21, 2015 7:55 am
by NickR
@System
"I think the shortcut method uses an absolute path and is therefore not suitable if the drive letter can change"

You are absolutely correct System sir :D

I had described the method I use on fixed drives (ie using portable SW to avoid registry clutter and allow ini file access)

I was trying to not add the complication of relative paths
so as not to muddy the waters with a long-winded explanation :|


So here is a fuller description suitable for a USB stick etc

Using TreeSheets as an example

Code: Select all

K:\TreeSheets\Ready2run
       Bin
          docs        (folder)
          examples (folder)
          images    (folder)
          readme.html
          TreeSheets.ini
          UseShortcutTreeSheets.exe
       TreeSheets                               < the shortcut
above shows I have placed all the unpacked TreeSheets files in a folder I called Bin
and I had renamed the main exe to UseShortcutTreeSheets.exe so I don't run it directly by accident
( I chose to use this folder structure so that the shortcut I want to run stands out and
is not lost among many files that may accompany the real exe)


In the folder above Bin:
'Treesheets' is a shortcut to 'UseShortcutTreeSheets.exe' in the Bin folder
as it is the only file in the folder it is hard to miss

But the shortcut has been modified thus:

Target field:

Code: Select all

 %Windir%\system32\cmd.exe /c cd Bin && start UseShortcutTreeSheets.exe -p

'Start In' field is empty

(the 'cd' cmd is only needed so that the 'ini' file is written in 'Bin' and not the calling folder)


This works for me - your mileage may vary
and note that spaces in the filepath may need some crafty quoting - fun :D

Re: FAQ item: launch arguments

Posted: Sat Nov 21, 2015 11:48 am
by Midas
SYSTEM wrote:In the batch file method, it's best to insert "start" before the command, e.g.

Code: Select all

start TreeSheets.exe -p
That way the CMD window will close immediately, instead of staying until the program is closed.
  • In the same vein, I recommend using a pair of double quotes right after the START command -- the reason being should there be a need to use a path for the executable and in the eventuality of this path containing spaces it will need to be enclosed in quotes; in that case and if that pair of empty quotes is absent, the path might be misinterpreted as a console window title command...

    Code: Select all

    start "" "%~dp0TreeSheets.exe" -p
    

Re: FAQ item: launch arguments

Posted: Sat Nov 21, 2015 5:29 pm
by webfork
Great suggestions, thanks Midas and SYSTEM. Here's a possible edit:

[BEGIN EDIT]
  • Create a batch file
    1. For this example, we'll use Mouse Recorder. Before you begin, you may need to disable the Windows feature that hides file extensions (e.g. .DOC, .MP3, etc.), as you'll be renaming this part of the file.
    2. In the program folder (e.g. C:\Portable\MouseRec\), create an empty text file.
    3. Paste the following text:
      • start "" "%~dp0XXXX"
    4. Look at the program entry and replace XXXX with the entry's launch file. For example, Mouse Recorder has to "Launch mouserecorder.exe" so paste mouserecorder.exe as below:
      • start "" "%~dp0mouserecorder.exe"
    5. Add the -portable to the end of the text:
      • start "" "%~dp0mouserecorder.exe" -portable
    6. Save the text file and rename it to launch.bat and then double-click this file.
[/END EDIT]

I'm a little worried this is too complex. Thoughts?

Re: FAQ item: launch arguments

Posted: Sun Nov 22, 2015 2:44 am
by SYSTEM
webfork wrote:Great suggestions, thanks Midas and SYSTEM. Here's a possible edit:

[BEGIN EDIT]
  • Create a batch file
    1. For this example, we'll use Mouse Recorder. Before you begin, you may need to disable the Windows feature that hides file extensions (e.g. .DOC, .MP3, etc.), as you'll be renaming this part of the file.
    2. In the program folder (e.g. C:\Portable\MouseRec\), create an empty text file.
    3. Paste the following text:
      • start "" "%~dp0XXXX"
    4. Look at the program entry and replace XXXX with the entry's launch file. For example, Mouse Recorder has to "Launch mouserecorder.exe" so paste mouserecorder.exe as below:
      • start "" "%~dp0mouserecorder.exe"
    5. Add the -portable to the end of the text:
      • start "" "%~dp0mouserecorder.exe" -portable
    6. Save the text file and rename it to launch.bat and then double-click this file.
[/END EDIT]

I'm a little worried this is too complex. Thoughts?
I think it's indeed too complex.

In most cases, it's unnecessary to use an absolute path to launch the program (that's what the cryptic %~dp0 is for). It mainly matters if the batch file is somehow run with the "current directory" set to something else than the program directory (in particular, if it's launched with "Run as administrator").

I'd suggest visitors to use

Code: Select all

start "" mouserecorder.exe -portable
if the file name doesn't contain spaces, and

Code: Select all

start "" "mouse recorder.exe" -portable
if it does.

Re: FAQ item: launch arguments

Posted: Sun Nov 22, 2015 8:59 am
by Specular
A launcher is definitely the simplest method if the user is using one already. Pstart is great for handling launch parameters, among other things.

Would have suggested the shortcut method, too but forgot it uses absolute paths. Pity as it would have otherwise been a no-brainer to recommend.

Re: FAQ item: launch arguments

Posted: Sun Nov 22, 2015 10:40 am
by NickR
@ Specular 'Would have suggested the shortcut method, too but forgot it uses absolute paths'

Shortcuts can use relative paths as in my over-complicated post above :?

EG Simplest relative path shortcut example
. to run TimeSheets with '-p' parameter in same folder as TreeSheets.exe
. change Target field to:

Code: Select all

%Windir%\system32\cmd.exe /c start TreeSheets.exe -p
& change 'Start In' field to null

Re: FAQ item: launch arguments

Posted: Sun Nov 22, 2015 7:16 pm
by Specular
NickR wrote:Shortcuts can use relative paths as in my over-complicated post above :?

EG Simplest relative path shortcut example
Ah, must have missed that. Nice, seems simple enough for a user to copy paste and edit in a different executable name. Would be easy to take some screenshots of the window for an FAQ seeing as it's one window, too.

Re: FAQ item: launch arguments

Posted: Mon Nov 23, 2015 10:56 am
by Midas
SYSTEM wrote:if the file name doesn't contain spaces, and

Code: Select all

start "" "mouse recorder.exe" -portable
if it does.
  • I agree with SYSTEM on this -- my inclusion of the path catching parameter was only there to make the example self-evident...
NickR wrote:

Code: Select all

%Windir%\system32\cmd.exe /c start TreeSheets.exe -p
  • On any well behaved computer, NickR example could be further simplified thusly:

    Code: Select all

    %COMSPEC% /c "START TreeSheets.exe -p"

Re: FAQ item: launch arguments

Posted: Mon Nov 23, 2015 6:06 pm
by Andrew Lee
In the FAQ, could we suggest the simplest way to do it would be to use a portable launcher, and leave all the discussion about batch files to the forum topic?

I feel the batch file method is too complicated, and frankly anyone who understands it should have no problems with understanding the command-line paramater in the first place.

Re: FAQ item: launch arguments

Posted: Mon Nov 23, 2015 11:38 pm
by Specular
Andrew Lee wrote:In the FAQ, could we suggest the simplest way to do it would be to use a portable launcher, and leave all the discussion about batch files to the forum topic?

I feel the batch file method is too complicated, and frankly anyone who understands it should have no problems with understanding the command-line paramater in the first place.
The last three posts above yours don't require a batch file though, just a simple shortcut file that can be created by right-clicking in a folder and selecting New>Shortcut. Everyone knows how to do this, and changing the Target field shouldn't be too hard for those using portable programs.