When I try to rename files located in the C:\User directory, e.g. in a subfolder on the desktop (C:\User\...\Desktop\sub\file.ext), wxWidgets output Error 5 (Access denied). I know that this is due to missing access rights because it works just fine on a non-system volume in a normal directory (e.g. D:\sub\file.ext).
Does wxWidgets come with any functions that can provide me the necessary elevated access?
wxRenameFile - Access denied (error 5)
-
- In need of some credit
- Posts: 2
- Joined: Thu Oct 21, 2021 4:22 pm
Re: wxRenameFile - Access denied (error 5)
No.beschbesch wrote: ↑Thu Oct 21, 2021 4:29 pm Does wxWidgets come with any functions that can provide me the necessary elevated access?
Here's Win32 code to do it:
https://github.com/microsoftarchive/msd ... vation.cpp
Beware that this code does not elevate an app "in-place", it re-starts itself with elevated level. I don't know if this is a general limitation or only a limitation of the presented demo code.
Use the source, Luke!
-
- In need of some credit
- Posts: 2
- Joined: Thu Oct 21, 2021 4:22 pm
Re: wxRenameFile - Access denied (error 5)
Thank you, I will take a look at it.
Yes, the windows security system is built like that. It is meant to provide a line of defense line against malware that requires human interaction - in theory at least. Malware should not be able to launch itself as admin on startup - the user always needs to initiate the elevation. I am unsure, if an elevation dialog will pop up when I use this code, or if Microsoft provides a ready-made dialog with some other API.
Lastly, I remember that MP-HC uses elevation for some of its settings.
If anyone is interested, it is the follwoing settings page ('Format'):
. Image Text:
Example of user right elevation from the MP-HC Media Player: The application is launched with SECURITY_MANDATORY_MEDIUM_RID (probably) and so cannot change the file type association. Due to that, MP-HC (probably) disables the 'Formats' settings page after checking the process security token.
Elevation - probably to SECURITY_MANDATORY_HIGH_RID - is only possible once the human user presses the 'Run as administrator' button. Given the symbol, I do not know if Microsoft acutally offers a ready made Common Control, or if the devs have modified a push button to look like "the real thing".
Yes, the windows security system is built like that. It is meant to provide a line of defense line against malware that requires human interaction - in theory at least. Malware should not be able to launch itself as admin on startup - the user always needs to initiate the elevation. I am unsure, if an elevation dialog will pop up when I use this code, or if Microsoft provides a ready-made dialog with some other API.
Lastly, I remember that MP-HC uses elevation for some of its settings.
If anyone is interested, it is the follwoing settings page ('Format'):
. Image Text:
Example of user right elevation from the MP-HC Media Player: The application is launched with SECURITY_MANDATORY_MEDIUM_RID (probably) and so cannot change the file type association. Due to that, MP-HC (probably) disables the 'Formats' settings page after checking the process security token.
Elevation - probably to SECURITY_MANDATORY_HIGH_RID - is only possible once the human user presses the 'Run as administrator' button. Given the symbol, I do not know if Microsoft acutally offers a ready made Common Control, or if the devs have modified a push button to look like "the real thing".
Re: wxRenameFile - Access denied (error 5)
wxButton::SetAuthNeeded()
https://docs.wxwidgets.org/trunk/classw ... 023e08c037
https://docs.wxwidgets.org/trunk/classw ... 023e08c037
Use the source, Luke!