Question about the "run" command

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
kuiwu_cn

Question about the "run" command

Post 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
To see the attached files, you need to log into the forum.

highend
Posts: 15004
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Question about the "run" command

Post 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";
One of my scripts helped you out? Please donate via Paypal

kuiwu_cn

Re: Question about the "run" command

Post 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.
To see the attached files, you need to log into the forum.

highend
Posts: 15004
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Question about the "run" command

Post 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
One of my scripts helped you out? Please donate via Paypal

kuiwu_cn

Re: Question about the "run" command

Post 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
To see the attached files, you need to log into the forum.

highend
Posts: 15004
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Question about the "run" command

Post by highend »

Maybe shell lnk resolving isn't used / executed if XY needs to wait for it's termination
One of my scripts helped you out? Please donate via Paypal

kuiwu_cn

Re: Question about the "run" command

Post by kuiwu_cn »

I'm very sorry, but my English is not very good. I didn't understand your meaning. Can you explain it?

kuiwu_cn

Re: Question about the "run" command

Post 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.

highend
Posts: 15004
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Question about the "run" command

Post 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)
One of my scripts helped you out? Please donate via Paypal

kuiwu_cn

Re: Question about the "run" command

Post 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
To see the attached files, you need to log into the forum.

admin
Site Admin
Posts: 66719
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Question about the "run" command

Post 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.

Post Reply