简体   繁体   English

如何使用Windows命令行和参数打开快捷方式

[英]How to open a shortcut with windows command line and parameters

I made a shortcut of a python script on my desktop. 我在桌面上做了​​一个python脚本的快捷方式。

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. 这些文件的默认程序是notepad ++,但是如果我将其更改为“命令行”并双击它,则仅命令行会打开,并带有快捷方式中给出的相应路径,但不会执行该文件。

What do I need to do? 我需要做什么?

将快捷方式目标更改为“ cmd文件名”(即在目标之前添加“ cmd”)

I want to know how to do just what title says "How to open a shortcut with windows command line and parameters". 我想知道该怎么做,标题是“如何使用Windows命令行和参数打开快捷方式”。

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). 是的,快捷方式将参数传递给它们指向的应用程序/批处理,因此无需自行在LNK上添加参数...更糟的是参数是可变的,如果将任何参数放在LNK上,它将被视为文字...如果LNK具有某些参数,则将START上的参数添加到LNK参数之后(经过测试)。

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: 如果我以启动方式运行.lnk(快捷方式),则会发生两件事:

  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. 我不想使用该选项来设置golbal变量,也不想将该参数保存在文件中,等等。

Actually i am trying with full qualified START command inside another batch: 实际上,我正在另一批中尝试使用完全合格的START命令:

@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). 这样的.lnk指向示例批处理(上面有一个PAUSE)。

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). 如果我使用不带空格且不带引号的参数调用批处理,则效果很好,但是只要参数带空格或带引号,批处理快捷方式所指向的批处理就不会运行(但在所有情况下都会出现管理员权限询问,当然我在所有情况下均按“是”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM