Run as administrator
-
Depending on context, I will need to launch single exe file from Qt application with and without administrator rights on Windows. Is this possible?
-
This thread has a siimilar topic and provides already hints.
-
Hi
The easy way is just to use a tool.
Like
http://nircmd.nirsoft.net/elevate.html
nircmd elevate notepad.exe C:\Windows\System32\Drivers\etc\HOSTSand you can just use QProcess to start nircmd.
This assumes i read it right.
From a Qt program, you want to start OTHER app, with and without admin rights -
Hi
The easy way is just to use a tool.
Like
http://nircmd.nirsoft.net/elevate.html
nircmd elevate notepad.exe C:\Windows\System32\Drivers\etc\HOSTSand you can just use QProcess to start nircmd.
This assumes i read it right.
From a Qt program, you want to start OTHER app, with and without admin rights -
@mrjj
Hmm, again, I (kind of) thought the OP was referring to running a single Qt app elevated & not. But you're interpretation is probably correct :) -
Sorry for confusions. I used this code in my app to elevate privilege when launching an app:
SHELLEXECUTEINFO Shex; ZeroMemory( &Shex, sizeof( SHELLEXECUTEINFO ) ); Shex.cbSize = sizeof( SHELLEXECUTEINFO ); Shex.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS; Shex.lpVerb = L"runas"; Shex.lpFile = f.c_str(); Shex.lpParameters = args.c_str(); Shex.nShow = SW_SHOWNORMAL; if (!ShellExecuteEx(&Shex)) { return; }
-
Sorry for confusions. I used this code in my app to elevate privilege when launching an app:
SHELLEXECUTEINFO Shex; ZeroMemory( &Shex, sizeof( SHELLEXECUTEINFO ) ); Shex.cbSize = sizeof( SHELLEXECUTEINFO ); Shex.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS; Shex.lpVerb = L"runas"; Shex.lpFile = f.c_str(); Shex.lpParameters = args.c_str(); Shex.nShow = SW_SHOWNORMAL; if (!ShellExecuteEx(&Shex)) { return; }
@MartinD
Hi
Ah, using run as. ( you should have mentioned this from start :)Im not sure what question is about then.
Are you asking how to use ShellExecuteEx
both as elevated and as not?As far as i recall, you should replace lpVerb with "open"
to have it NOT ask.