FAQ item: launch arguments

All suggestions about TPFC should be posted here. Discussions about changes to TPFC will also be carried out here.
Post Reply
Message
Author
User avatar
webfork
Posts: 7756
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

FAQ item: launch arguments

#1 Post by webfork » Fri Nov 20, 2015 1:40 pm

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.
Supporting Net Neutrality - BattleForTheNet | Why this matters | More from EFF.org

User avatar
webfork
Posts: 7756
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

Re: FAQ item: launch arguments

#2 Post by webfork » Fri Nov 20, 2015 3:39 pm

One alternative method NickR pointed me to:

Shortcut method
  1. Right-click on the program and choose "Create shortcut"
  2. Rename the shortcut to "PROGRAM_Portable" (e.g. Treesheets Portable)
  3. Right-click on the shortcut and edit the "target" field to append the required start parameter. So for example:
    • Change "C:\PORTABLE\TreeSheets\TreeSheets.exe"

      To: "C:\PORTABLE\TreeSheets\TreeSheets.exe" -p
    If there are no quotes, just put the -p at the end of the text.

NickR 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.
Supporting Net Neutrality - BattleForTheNet | Why this matters | More from EFF.org

User avatar
smaragdus
Posts: 1965
Joined: Sat Jun 22, 2013 3:24 am
Location: Aeaea

Re: FAQ item: launch arguments

#3 Post by smaragdus » Fri Nov 20, 2015 4:11 pm

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.

User avatar
webfork
Posts: 7756
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

Re: FAQ item: launch arguments

#4 Post by webfork » Fri Nov 20, 2015 4:52 pm

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.
Supporting Net Neutrality - BattleForTheNet | Why this matters | More from EFF.org

User avatar
SYSTEM
Posts: 1764
Joined: Sat Jul 31, 2010 1:19 am
Location: Helsinki, Finland

Re: FAQ item: launch arguments

#5 Post by SYSTEM » Sat Nov 21, 2015 4:02 am

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.
My YouTube channel | Release date of my 11th playlist: January 26, 2018

NickR
Posts: 105
Joined: Thu Aug 26, 2010 6:37 am

Re: FAQ item: launch arguments

#6 Post by NickR » Sat Nov 21, 2015 7:55 am

@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

User avatar
Midas
Posts: 4195
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

Re: FAQ item: launch arguments

#7 Post by Midas » Sat Nov 21, 2015 11:48 am

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
    

User avatar
webfork
Posts: 7756
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

Re: FAQ item: launch arguments

#8 Post by webfork » Sat Nov 21, 2015 5:29 pm

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?
Supporting Net Neutrality - BattleForTheNet | Why this matters | More from EFF.org

User avatar
SYSTEM
Posts: 1764
Joined: Sat Jul 31, 2010 1:19 am
Location: Helsinki, Finland

Re: FAQ item: launch arguments

#9 Post by SYSTEM » Sun Nov 22, 2015 2:44 am

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.
My YouTube channel | Release date of my 11th playlist: January 26, 2018

Specular
Posts: 280
Joined: Sun Feb 16, 2014 10:54 pm

Re: FAQ item: launch arguments

#10 Post by Specular » Sun Nov 22, 2015 8:59 am

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.

NickR
Posts: 105
Joined: Thu Aug 26, 2010 6:37 am

Re: FAQ item: launch arguments

#11 Post by NickR » Sun Nov 22, 2015 10:40 am

@ 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

Specular
Posts: 280
Joined: Sun Feb 16, 2014 10:54 pm

Re: FAQ item: launch arguments

#12 Post by Specular » Sun Nov 22, 2015 7:16 pm

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.

User avatar
Midas
Posts: 4195
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

Re: FAQ item: launch arguments

#13 Post by Midas » Mon Nov 23, 2015 10:56 am

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"

User avatar
Andrew Lee
Posts: 2209
Joined: Sat Feb 04, 2006 9:19 am
Contact:

Re: FAQ item: launch arguments

#14 Post by Andrew Lee » Mon Nov 23, 2015 6:06 pm

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.

Specular
Posts: 280
Joined: Sun Feb 16, 2014 10:54 pm

Re: FAQ item: launch arguments

#15 Post by Specular » Mon Nov 23, 2015 11:38 pm

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.

Post Reply