Page 1 of 1

Question about the "run" command

Posted: 31 Mar 2018 16:54
by kuiwu_cn
There is a BAT file in the directory "F:\Test\".
I created a shortcut on this BAT file.
snap_screen_20180331224659.png
The content of the BAT file is:


@ECHO OFF
CLS
PAUSE
snap_screen_20180331224747.png
I run this shortcut with a script:

run quote ("F:\Test\Test.lnk"),,2,1;

But there is no BAT window, why?
snap_screen_20180331224850.png

Re: Question about the "run" command

Posted: 31 Mar 2018 17:07
by highend
XY does not internally resolve that .lnk, so either use

Code: Select all

run property("#ShortcutTarget", "F:\Test\Test.lnk"),,2,1;
or e.g.:

Code: Select all

open "F:\Test\Test.lnk";

Re: Question about the "run" command

Posted: 31 Mar 2018 17:23
by kuiwu_cn
My real need is:
Let the BAT file get administrator privileges. I set "run with administrator" on the properties of shortcuts, so that BAT can get administrator privileges.
Thanks very much。
Your method is very good, but it can't help me.

Re: Question about the "run" command

Posted: 31 Mar 2018 17:32
by highend
Then let the .bat file elevate itself and if this doesn't cut it, use an external tool, e.g.:
https://jpassing.com/2007/12/08/launch- ... mand-line/

Code: Select all

REM ### Admin Check ########################################
REG QUERY "HKU\S-1-5-19" >NUL 2>NUL && GOTO :ENDUAC
SET "vbsFile=%TEMP%\~getAdmin.vbs"
IF "%1" NEQ "" (FOR /F "tokens=*" %%I in ('ECHO %*') DO SET "param=%%~I")

ECHO Set UAC = CreateObject^("Shell.Application"^)> "%vbsFile%"
ECHO UAC.ShellExecute "cmd", "/c """"%~s0"" ""%param%""""", "", "runas", ^1>> "%vbsFile%"
CSCRIPT "%vbsFile%" //Nologo
IF EXIST "%vbsFile%" DEL /Q "%vbsFile%" >NUL 2>NUL
EXIT /B
:ENDUAC

Re: Question about the "run" command

Posted: 31 Mar 2018 17:34
by kuiwu_cn
It's very interesting that the script below can execute normally. Why? Is it a BUG?

run quote ("F:\Test\Test.lnk"),,0,1;

snap_screen_20180331233134.png

Re: Question about the "run" command

Posted: 31 Mar 2018 17:39
by highend
Maybe shell lnk resolving isn't used / executed if XY needs to wait for it's termination

Re: Question about the "run" command

Posted: 01 Apr 2018 12:03
by kuiwu_cn
I'm very sorry, but my English is not very good. I didn't understand your meaning. Can you explain it?

Re: Question about the "run" command

Posted: 02 Apr 2018 12:15
by kuiwu_cn
highend wrote:Maybe shell lnk resolving isn't used / executed if XY needs to wait for it's termination

May I trouble you to explain it, thank you.

Re: Question about the "run" command

Posted: 02 Apr 2018 12:26
by highend
If this doesn't work:

Code: Select all

run quote("F:\Test\Test.lnk"),,2,1;
and this does:

Code: Select all

run quote("F:\Test\Test.lnk"),,0,1;
then XYplorer's script command "run" does not do the necessary resolving of the .lnk shortcut
to its real file when 2 is used for the wait parameter. Probably a bug then (Don needs to answer this)

Re: Question about the "run" command

Posted: 02 Apr 2018 13:29
by kuiwu_cn
If I have a BAT file, I want to get administrator privileges when I double-click it. I only need to add "(Need ADMIN)" in the file name. I have implemented this function already.

Code: Select all

    @ECHO OFF
    TITLE 另一个BAT执行完毕后,该BAT会自动退出

    "%~dp0Let_the_BAT_File_Have_ADMIN.lnk" %~1 %~2

XYplorer is a great software. I like it very much. I use it every day.

snap_screen_20180402192447.png

Re: Question about the "run" command

Posted: 30 Apr 2018 11:48
by admin
highend wrote:If this doesn't work:

Code: Select all

run quote("F:\Test\Test.lnk"),,2,1;
and this does:

Code: Select all

run quote("F:\Test\Test.lnk"),,0,1;
then XYplorer's script command "run" does not do the necessary resolving of the .lnk shortcut
to its real file when 2 is used for the wait parameter. Probably a bug then (Don needs to answer this)
I can only confirm these findings. With the "wait" flag set to 1 or 2, the CreateProcess function (Windows API) is needed but this function does not support LNK files.

In the bext beta you will at least get an error message.