Run external software from Matlab using system() with admin rights

Hi,
I am trying to run a software from my Matlab script with admin rights. Once lunched, it doesn't have admin rights, and I can't communicate with it using .NET commands. I set the external software to run automatically in admin mode, which is done when I double click on it (works with the .NET commands), but not when started from Matlab.
LTPath = 'C:\...\lt.exe';
proc=System.Diagnostics.Process.Start(LTPath);
I have windows 10 64 bit, I am administrator. I use Matlab 2017b.
Thanks !

1 件のコメント

Janos Keresztes
Janos Keresztes 2018 年 5 月 22 日
dear Jan, thank you for your answer. Unfortunately, I got the following error. I also tried using proc=System.Diagnostics.Process.Start(LTPath, uname, password, domain); but got the error: No method 'Start' with matching signature found for class 'System.Diagnostics.Process'.
Error in WS3 (line 12) proc=System.Diagnostics.Process.Start(LTPath, uname, password, domain);
Do you have any suggestions?
Thanks.

サインインしてコメントする。

回答 (2 件)

Guillaume
Guillaume 2018 年 5 月 22 日

1 投票

but got the error: No method 'Start' with matching signature found for class 'System.Diagnostics.Process'.
That's because the 3rd argument to Start is a System.Security.SecureString, not a plain string. You could construct that SecureString with:
password = 'secret';
securestring = System.Security.SecureString;
for c = password
securestring.AppendChar(c);
end
System.Diagnostics.Process.Start(LTPath, user, securestring, domain)
Whether or not that'll help you launching the process with admin privileges, I have no idea.
Jan
Jan 2018 年 5 月 2 日

0 投票

You can try this: Create a file "LT_AsAdmin.vbs":
Set UAC = CreateObject^("Shell.Application"^)
UAC.ShellExecute "C:\...\lt.exe", "ELEV", "", "runas", 1
Then start this VBS script by system.
UNTESTED! I can not run it by myself currently.

6 件のコメント

Guillaume
Guillaume 2018 年 5 月 22 日
Note that you can create the Shell.Application object directly in matlab. No Need to create a vbs script:
uac = actxserver('Shell.Application');
uac.ShellExecute(LTPath, 'ELEV', '', 'runas', 1);
Note: as is typical of microsoft scripting documentation, the doc for ShellExecute is seriously lacking, so I've no idea if the arguments above are valid. I've just copied them from Jan's answer.
Frederik Desaulniers
Frederik Desaulniers 2020 年 12 月 1 日
The code provided by Guillaume almost works, but you need to use double quotes in the arguments for uac.ShellExecute(). Corrected code:
uac = actxserver('Shell.Application');
uac.ShellExecute(LTPath, "ELEV", "", "runas", 1);
Pavel Kliuiev
Pavel Kliuiev 2023 年 1 月 20 日
Any ideas how to modify the code to have two input arguments that are strings?
Jan
Jan 2023 年 1 月 20 日
@Pavel Kliuiev: The input arguments are part of the command to be called. Did you try to include it in the string LTPath?
Pavel Kliuiev
Pavel Kliuiev 2023 年 1 月 20 日
Thanks Jan! Would you mind providing a code snippet? I tried LTPath = "path/to/file.exe arg1 arg2"; uac.ShellExecute(LTPath, "ELEV", "", "runas", 1); for example, and it did not work. arg1 and arg2 are strings.
Jan
Jan 2023 年 1 月 22 日
I have no chance to guess, what "did not work" means. Please explain the details.
Do you really want to provide the strings "arg1" and "arg2" as inputs? They are not variables, but literally "arg1". Maybe you mean:
arg1 = "all";
arg2 = "Match";
LTPath = "path/to/file.exe " + arg1 + " " + arg2
LTPath = "path/to/file.exe all Match"

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品

タグ

質問済み:

2018 年 5 月 2 日

コメント済み:

Jan
2023 年 1 月 22 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by