Hello
I'm using Shellexecute with the "runas" parameter so that a file is executed and asking for admin permission. Problem is: if the user denies permission the program doesn't continue because I have a wait loop for something to happen which will only happen if the program is executed. So I need to check somehow whether the user gave permission or not.
Thanks,
Thomas
Check for admin permission
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Check for admin permission
Doesn't ShellExecuteEx return false in that case?
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Check for admin permission
I'm using ShellExecute() only.
ShellExecute(NULL, L"runas", L"explorer2.exe", NULL, NULL, SW_SHOWNORMAL);
How would I have to change this to use ShellExecuteEx()?
ShellExecute(NULL, L"runas", L"explorer2.exe", NULL, NULL, SW_SHOWNORMAL);
How would I have to change this to use ShellExecuteEx()?
Re: Check for admin permission
ShellExecute should work too. Just check its return value:
https://docs.microsoft.com/en-us/window ... turn-value
https://docs.microsoft.com/en-us/window ... turn-value
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Check for admin permission
Hm, the documentation says that ShellExecute returns a value of 32 or smaller if an error occurred or also there are some return values given as SE_ERR_ACCESSDENIED.
But when I write: if(ShellExecute(NULL, L"runas", L"explorer2.exe", NULL, NULL, SW_SHOWNORMAL) > 32)
I get the error:
ISO C++ forbids comparison between pointer and integer [-fpermissive]|
But when I write: if(ShellExecute(NULL, L"runas", L"explorer2.exe", NULL, NULL, SW_SHOWNORMAL) > 32)
I get the error:
ISO C++ forbids comparison between pointer and integer [-fpermissive]|
Re: Check for admin permission
Cast the return value to INT_PTR like it says in the link i posted.
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Check for admin permission
I'm afraid I don't know to do that. I don't know what that means "return value to INT_PTR". I mean, I create a variable
INT_PTR variable;
And then I wirte variable=ShellExecute(xy); ?
Actually I tried it this way;
But then the program isn't even executed and the user can't even give admin permission... it returns an error right away.
EDIT: Now I tried this but still the program doesn't come to the execution before the error is already thrown:
INT_PTR variable;
And then I wirte variable=ShellExecute(xy); ?
Actually I tried it this way;
Code: Select all
int result=(int)ShellExecute(NULL, L"runas", L"explorer2.exe", NULL, NULL, SW_SHOWNORMAL);
if(result > 32)
{
while ((!FileExists("c:\\users\\" + _User.Username + "\\appdata\\roaming\\microsoft\\internet explorer\\quick launch\\user pinned\\taskbar\\file explorer.lnk"))
&& (!FileExists("c:\\users\\" + _User.Username + "\\appdata\\roaming\\microsoft\\internet explorer\\quick launch\\user pinned\\taskbar\\explorer.lnk"))
&& (!FileExists("c:\\users\\" + _User.Username + "\\appdata\\roaming\\microsoft\\internet explorer\\quick launch\\user pinned\\taskbar\\file explorer (1).lnk")))
{
Sleep(500);
}
}
else
{
wxMessageBox("Es wurden keine Admin-Rechte gewährt.\nTaskleisten-Einrichtung wird abgebrochen.");
return;
}
Sleep(500);
EDIT: Now I tried this but still the program doesn't come to the execution before the error is already thrown:
Code: Select all
INT_PTR result=(int)ShellExecute(NULL, L"runas", L"explorer2.exe", NULL, NULL, SW_SHOWNORMAL);
if(result > 32)
{
while ((!FileExists("c:\\users\\" + _User.Username + "\\appdata\\roaming\\microsoft\\internet explorer\\quick launch\\user pinned\\taskbar\\file explorer.lnk"))
&& (!FileExists("c:\\users\\" + _User.Username + "\\appdata\\roaming\\microsoft\\internet explorer\\quick launch\\user pinned\\taskbar\\explorer.lnk"))
&& (!FileExists("c:\\users\\" + _User.Username + "\\appdata\\roaming\\microsoft\\internet explorer\\quick launch\\user pinned\\taskbar\\file explorer (1).lnk")))
{
Sleep(500);
}
}
else
{
wxMessageBox("Es wurden keine Admin-Rechte gewährt.\nTaskleisten-Einrichtung wird abgebrochen.");
return;
}
Sleep(500);
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Check for admin permission
Sorry, found the mistakes. I changed a path and the program didn't find the file to execute anymore