Kreatronik
Kreatronik

Reputation: 199

How to open a shortcut with windows command line and parameters

I made a shortcut of a python script on my desktop.

Now I want to open this with the command line and parameters.

If I open the properties of the shortcut, I can add the parameters, but I can't force to be opened with the command line.

The default program for these files is notepad++, but if I change it to "command line" and double click it, then just the command line opens with the respective path given in the shortcut, but not executing the file.

What do I need to do?

Upvotes: 1

Views: 5721

Answers (2)

Claudio
Claudio

Reputation: 11

I want to know how to do just what title says "How to open a shortcut with windows command line and parameters".

I mean:

  • From a command line, run a shortcut and pass parameters to it

That shortcut points to a batch file and has set on the tick for run with admins rights. And yes, shortcuts passes the parameters to the application / batch they point to, so no need to add parameters on the LNK it self... worst that parameters are variable and if you put any parameter on the LNK it is treated as a literal... if the LNK has some parameter, the parameters on START are added after the LNK ones (tested).

That batch file (for testing) can be as simple as this:

@ECHO OFF
ECHO Parameter 1 is: %1
PAUSE

If i run the .lnk (shortcut) with start it happens two things:

  1. It runs the Batch file if parameter does not contains "
  2. It does not even run the Batch file if parameter contains "

So how can i pass a parameter that has spaces? like a path, a filename, etc.

I do not want to use the option to set a golbal variable, neither to save that parameter on a file, etc.

Actually i am trying with full qualified START command inside another batch:

@ECHO OFF
ECHO DeBug - start-
start "Some Title Is Requiered, can be empty" /D "Starting Path" /WAIT "Full Path to the LNK file.lnk" %1
ECHO DeBug - stop-
PAUSE

Such .lnk points to the sample Batch (that has a PAUSE on it).

If i call the Batch with a parameter without spaces and without quotation it works perfectly, but as soon as parameter has spaces or quotation the batch pointed by the shortcut is not run (but the admin rights ask appears on all cases, and of course i press Yes on all cases).

Upvotes: 1

tmccar
tmccar

Reputation: 85

Change the shortcut target to "cmd filename" (i.e. add "cmd" before the target)

Upvotes: 0

Related Questions