I have a file in the root directory which I want to open for editing in my QT application.
Generally we use sudo filepath to open the file with all permissions.
But i want to achieve this in my c++ QT application.
Any kind of help is appreciable.
Thank you.
Do the following.
Get userid, if it is not 0 (uid of root is 0), the do the following
Execute argv[0] with gksu/kdesu.
Perform tasks.
Your program needs to be executed with root privileges, or, more specifically, it needs to be executed as a user who has access permissions for those files.
If it is not, then it is impossible to access those files, because the OS will not allow your program to do so. There are no changes in the C++ code that will fix this. You need to execute your program using sudo.
Related
At first I must say: IT IS NOT KEYLOGER OR ANOTHER VIRUS, I just writing a program to automize some actions on my computer. I know that I must change registry with IsMyProgramRegisteredForStartup(PCWSTR pszAppName) or RegOpenKey with RegSetValueEx, or something like this, but I actually don't know how to use it,
so please can someone help me with this problem or someone know another way to get it into startup.
All information that I can say that I on Windows 10, and for example I need to get someprogram.exe get into StartUp by c++ program
First, why do you have to set exe file as startup using C++ code? You can just create shortcut of your exe file. Copy that shortcut to this directory
Easiest way : press win+R and type shell:startup. It will open the startup directory right away
Or input the path manually:
For all users: C:\ProgramData\Microsoft\Windows\Start
Menu\Programs\StartUp
For current users:
C:\Users[Username]\AppData\Roaming\Microsoft\Windows\Start
Menu\Programs\Startup
After restart the windows and login, your exe file will automatically run. Plus you can check whether your exe file is already registered as startup program using task manager -> startup.
I have create a project in which I am trying to generate a .txt file and then calling OS specific commands (I'm using unix so using system() function to trigger application) to open it in default application.
My code works perfect.
But the problem starts when I try to run my application after setting it in environment path. I am doing that for global visibility. File gets generated correctly by while opening the .txt using system() seems like it is trying to look at it at different directory.
I want to some how convey to the system() function to look at the specific location.
How can I solve this problem?
It sounds like you are actually just in a different working directory. Try showing the result of getcwd.
I wonder whether it is possible in C++ to programatically copy a concrete file to the root directory. For example, say I have a file exm.txt in the location C:\example\ and I'd like to copy it to C:\ so that I'll obtain a file C:\exm.txt. Is it possible in C++ WinAPI? When using
CopyFile("C:\\example\\exm.txt","C:\\exm.txt",true);
nothing happens and this functions returns error code 5: Access denied [I'm almost sure I'm working as the administrator - this is my personal computer].
The aforementioned function - as far as I know - works correctly for all other directories (different from the root directory in some partition). So, my question is whether we can do programatically copy also to the root directory.
Thanks in advance for any help!
That is because the security settings, by default, do not allow standard user to create files at the root level of the system drive.
The obvious solutions are:
Save the file somewhere else if you can. It's good practise not to litter the root directory of the system volume.
Run the process with elevated rights by adding the requireAdministrator option to your manifest. Or by right clicking the executable or shortcut and selecting Run as administrator.
I am using Ubuntu and I am trying to create a new file in the /var/tmp directory in c++ but for some reason it is not creating the file. Also, how long do files last in this folder usually?
Here is what I have:
string defaultPath = "/var/tmp/a.txt";
ofstream ouputFile(defaultPath);
I think it is something with "/var/tmp/" I am not sure because I am not that familiar with linux operating systems. Any help is much appreciated.
Most likely this question is unrelated to C++, you should check if user, which runs the program has permissions to create a file in /var/tmp:
touch /var/tmp/a.txt
Then check if file is created there. If not check permissions on /var/tmp and fix them by chmod or choose directory where the user has write permissions.
I can't seem to update my configuration file in c:\ProgramData\appname\config.ini. I keep getting an access denied error. Seems the ini code fails to be able to delete the existing .ini file when trying to update it with the new file. Funny thing is that I have other programs I've written that share the same code but don't have this problem. This is troubling.
Comparing my working program with this non working program, I noticed that when I click on the security tab for the ini file, I see that my user name [Scott] is not listed under "Group or Usernames" like in the working program's ini file. Also, the non working one has a shield next to Delete and Rename (when right click on filename) while the working one does not have this. How can I set the permissions? The setup file for both projects is identical and when I create the folder and copy the program file in Isso Setup, no permissions are set (read only flag is not set, hidden is not set, and System is not set).
Why am I getting this and how come my other program install and works fine? Installer runs as administrator and does the access permission prompting. What do I need to do?
This is because your program was not run as an administrator. You have to either run your program as an administrator or move your .ini file and any other files you wish to update during the duration of the program to a location like C:\Users\\AppData\Local\. Note that for the latter option you will have to update your program likewise.
To run your program as an administrator right-click on ur program (or shortcut) and click Run as Administrator.