how to call another application from qt in run admistrator mode
-
wrote on 19 Aug 2024, 09:59 last edited by
as in the title I want to call another application in run admistrator mode from the main application, will this process be detected as a virus by Windows security?
-
as in the title I want to call another application in run admistrator mode from the main application, will this process be detected as a virus by Windows security?
wrote on 19 Aug 2024, 10:07 last edited by@Blackzero said in how to call another application from qt in run admistrator mode:
will this process be detected as a virus by Windows security?
Not particularly, why should it be? Unless you are saying that is a Windows "feature". And I don't see why it would be affected by whether you spawn it from a Qt program or not.
-
@Blackzero said in how to call another application from qt in run admistrator mode:
will this process be detected as a virus by Windows security?
Not particularly, why should it be? Unless you are saying that is a Windows "feature". And I don't see why it would be affected by whether you spawn it from a Qt program or not.
wrote on 20 Aug 2024, 01:09 last edited by@JonB said in how to call another application from qt in run admistrator mode:
whether you spawn it from a Qt program or not.
yes I bring it up from the Qt program the application I call is my own creation he needs adminstartor rights to change the main application or called Auto Update.exe
-
@Blackzero said in how to call another application from qt in run admistrator mode:
will this process be detected as a virus by Windows security?
Not particularly, why should it be? Unless you are saying that is a Windows "feature". And I don't see why it would be affected by whether you spawn it from a Qt program or not.
wrote on 20 Aug 2024, 01:16 last edited by@JonB I have tried this code on another laptop but nothing seems to happen, the Auto Update application opens but when Auto Update wants to install the downloaded file it fails but if it is run with adminstartor rights manually Auto update can install the file in the C:/Program Files/ folder.
QStringList arguments; arguments << QString(“/c”) << QString(“start”) << QString(“AutoUpdate.exe”); bool success = QProcess::startDetached(“cmd.exe”, arguments);
-
wrote on 20 Aug 2024, 02:23 last edited by Bonnie
Normally, the called process won't have adminstartor privilege unless the caller process already have it.
You need to make AutoUpdate.exe request adminstartor privilege itself.
In that case duringQProcess::startDetached
Qt will first tryCreateProcess
API and receive anERROR_ELEVATION_REQUIRED
error. Then it will tryShellExecuteEx
API which will trigger an UAC prompt.
Edit: I mean start AutoUpdate.exe directly not by cmd.exe. -
Normally, the called process won't have adminstartor privilege unless the caller process already have it.
You need to make AutoUpdate.exe request adminstartor privilege itself.
In that case duringQProcess::startDetached
Qt will first tryCreateProcess
API and receive anERROR_ELEVATION_REQUIRED
error. Then it will tryShellExecuteEx
API which will trigger an UAC prompt.
Edit: I mean start AutoUpdate.exe directly not by cmd.exe.wrote on 20 Aug 2024, 02:36 last edited by@Bonnie said in how to call another application from qt in run admistrator mode:
unless the caller process already have it.
You need to make AutoUpdate.exe request adminstartor privilege itself.so in order for AutoUpdate.exe to have administartor rights I have to change it like a manifest?
-
Normally, the called process won't have adminstartor privilege unless the caller process already have it.
You need to make AutoUpdate.exe request adminstartor privilege itself.
In that case duringQProcess::startDetached
Qt will first tryCreateProcess
API and receive anERROR_ELEVATION_REQUIRED
error. Then it will tryShellExecuteEx
API which will trigger an UAC prompt.
Edit: I mean start AutoUpdate.exe directly not by cmd.exe.wrote on 20 Aug 2024, 02:43 last edited by@Bonnie I used 2 ways here, I don't know if this way is stupid, I changed the AutoUpdate manifest and called AutoUpdate in this way
<?xml version='1.0' encoding='UTF-8' standalone='yes'?> <assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level='requireAdministrator' uiAccess='false' /> </requestedPrivileges> </security> </trustInfo> <dependency> <dependentAssembly> <assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*' /> </dependentAssembly> </dependency> </assembly>
QString pathToAutoUpdate = "AutoUpdate.exe"; runAsAdmin(pathToAutoUpdate); void runAsAdmin(const QString &exePath) { LPCWSTR applicationPath = (LPCWSTR)exePath.utf16(); HINSTANCE hInstance = ShellExecute(nullptr, L"runas", applicationPath, nullptr, nullptr, SW_SHOWNORMAL); if (reinterpret_cast<intptr_t>(hInstance) <= 32) { } else { qApp->quit(); } }
-
wrote on 20 Aug 2024, 06:56 last edited by
Looks fine by me. In my original reply I mean after setting the manifest thing of AutoUpdate (which makes it only runs in admin mode),
QProcess::startDetached
would handle ERROR_ELEVATION_REQUIRED by callingShellExecuteEx
. But it is OK to useShellExecute
directly if cross-platform is not required. -
Looks fine by me. In my original reply I mean after setting the manifest thing of AutoUpdate (which makes it only runs in admin mode),
QProcess::startDetached
would handle ERROR_ELEVATION_REQUIRED by callingShellExecuteEx
. But it is OK to useShellExecute
directly if cross-platform is not required. -
-
as in the title I want to call another application in run admistrator mode from the main application, will this process be detected as a virus by Windows security?
wrote on 21 Aug 2024, 13:29 last edited by@Blackzero said in how to call another application from qt in run admistrator mode:
will this process be detected as a virus by Windows security?
There is antivirus software which will detect this as potential thread. This has, however, nothing to do with administrator mode. Programs that execute other programs show suspicious behavior in general. The best you can do to improve the situation is to sign your software (which is what we did). It's not bullet proof, but helps a lot with certain AV products.
-
@Blackzero said in how to call another application from qt in run admistrator mode:
will this process be detected as a virus by Windows security?
There is antivirus software which will detect this as potential thread. This has, however, nothing to do with administrator mode. Programs that execute other programs show suspicious behavior in general. The best you can do to improve the situation is to sign your software (which is what we did). It's not bullet proof, but helps a lot with certain AV products.
wrote on 21 Aug 2024, 15:51 last edited by@SimonSchroeder said in how to call another application from qt in run admistrator mode:
Programs that execute other programs show suspicious behavior in general.
You mean like Command Prompt? Or make? Or C++ compiler? Or IDE? Or bat files? Are these really all "signed for AV", e.g. MInGW toolchain?
-
@SimonSchroeder said in how to call another application from qt in run admistrator mode:
Programs that execute other programs show suspicious behavior in general.
You mean like Command Prompt? Or make? Or C++ compiler? Or IDE? Or bat files? Are these really all "signed for AV", e.g. MInGW toolchain?
wrote on 22 Aug 2024, 06:42 last edited by@JonB That's just my observation with our company's software. There are two different levels of code signing (we are using the simpler one: The signature includes our name and the identity was checked by the issuing company, but the trust chain does not go up to Microsoft itself.). But I bet that all Microsoft products are signed properly (even the command prompt) to avoid being detected by AV software. I've seen at least some open source software being signed (not sure about MinGW, though).
bat files are different as they are not executables. However, every bat file you download from the internet or which is saved on a network drive (everything not your own computer is the "internet" for Windows) will warn you that it might be unsafe to execute and if you are really sure if you want to do this. Every. Single. Time. This is not AV, but just Windows being careful about "untrusted sources" (even opening an Excel or Word file from a network drive by default is only opened in read-only mode).
-
@JonB That's just my observation with our company's software. There are two different levels of code signing (we are using the simpler one: The signature includes our name and the identity was checked by the issuing company, but the trust chain does not go up to Microsoft itself.). But I bet that all Microsoft products are signed properly (even the command prompt) to avoid being detected by AV software. I've seen at least some open source software being signed (not sure about MinGW, though).
bat files are different as they are not executables. However, every bat file you download from the internet or which is saved on a network drive (everything not your own computer is the "internet" for Windows) will warn you that it might be unsafe to execute and if you are really sure if you want to do this. Every. Single. Time. This is not AV, but just Windows being careful about "untrusted sources" (even opening an Excel or Word file from a network drive by default is only opened in read-only mode).
wrote on 22 Aug 2024, 08:52 last edited by@SimonSchroeder said in how to call another application from qt in run admistrator mode:
will warn you that it might be unsafe to execute and if you are really sure if you want to do this. Every. Single. Time. This is not AV, but just Windows being careful about "untrusted sources"
Is this the one where the file properties shows "This was downloaded from a remote source" and I clear that if I'm happy with it and then it's fine? I certainly execute things from other LAN machines. I rarely download a
.bat
file!
1/13