How to get .exe program into startup by c++ - c++

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.

Related

How can I get the path of a file I am trying to open using file explorer's "open with" dialog box

So I have a very specific question that I realize is a bit stupid, however regardless of how I search for it, nothing really shows up.
I am aware that I can use system() to execute commands in cmd, and I am so done with writing
g++ <filename.cpp> & a.exe & del a.exe
every time I want to compile, build and then delete the exe of a c++ app. Therefore I plan on making a simple handling software using c++ to open other c++ apps. It will just take the name of the app I am trying to run and do all of the things said in the above code. My problem is, when using cmd I can write the name of the file I am running, however how can I get the name of the file if I double click?
Example would be to always open cpp files with the program I am making. Upon double click, it will open a cmd console, type the code for me and execute the program. Then when I close the program, the cmd will close. I am aware how to do all of that, except how to get the file name of the file I am opening using the program.
I have tried using different libraries and have not found anything similar or at least nothing that states of this use. I am not expecting the whole program nor do I want it, I realize it is a simple project, however I am struggling with this one part and am unable to find a solution.
I simply want to make my own starting script. Then in file explorer I right click on any .cpp file, click open with and the dialog box shows up. I click the program I have created and there I compile the .cpp file with the script of my choice, however I do not understand how to get the path from right click, open with, and using my own program. This is all withing file explorer, not within the software I am making.

Qt. All functions work in release folder, but not in Program Files

in my program I have functions to restart program and load / save settings from .ini file. Everything is working in release folder, but when I install it (program is in C://Program Files (x86)):
*When I call restart function
QProcess::startDetached(QApplication::applicationFilePath());
exit(0);
Application is terminating itself, but new instance is not started...
*or When I call save settings to .ini file
QSettings setting(qApp->applicationDirPath() + "//config//settings.ini", QSettings::IniFormat);
setting.sync();
setting.beginGroup("/Example");
setting.setValue("/Example1",
setting.endGroup();
When I run App first time, usually It saves once, but next times Settings is not saved, settings.ini, or any other .ini file which I'm trying to save looks like 'locked' and I can't save it even through notepad... But If I run App with Administrator permissions everything is working (Restart still don't)
//Edit: I'have checked this on desktop, It works. On another partition (D://) it doesn't work.
In this moment other functions work normally. Could anybody help me with this issue?
i think you need admin rights to create a file to Program Files in latest windows. Try install it somewhere else and check if it still fails
By default you need administrator rights to write inside Program Files.
Your application should use instead the path C:\ProgramData (assuming C: system drive), to save files intended to be shared with all users (eventually creating a directory inside with the company / application's name). The location should be accessed by using the environment variables ProgramData or AllUsersProfile.
Or, to save settings / data separately for each user, you could use these environment variables to access the intended directory:
AppData (expanding to e.g. C:\Users\<Username>\AppData\Roaming) - user profile specific data
LocalAppData (expanding to e.g. C:\Users\<Username>\AppData\Local) - machine specific data
getenv function can be used for reading an environment variable.

Compiled exe won't run through my custom schemed cmd?

I have a custom color/font/size/etc. scheme for my cmd.
When I run my program through VS (with or without debugging) it runs my program in cmd using my scheme. (good)
But, when I run the exe file directly, it runs in the default cmd (without my scheme). (bad)
If I make a .bat file which executes my exe, then it runs in the schemed cmd. (good)
But if I make a shortcut of that .bat file, it runs in the default cmd! (bad)
How can I make it so that the exe itself runs through the schemed cmd?
If not possible, how can I make it so the shortcut to the exe/bat runs it through the schemed cmd?
If you want the software to run in schemed cmd, you should execute the program over command line, other way you can edit your program's font etc. in your program.
Compilers run programs by cmd.
And if you want it so much, you can check your program on task manager at beginning your code and if there isn't, you can run with system function and hide first one.
I don't know how you changed your cmd scheme, so, it is possible that this will not help you. Anyway...
The standard way of cmd customization is to include in HKCU\Console\ a subkey with the title of the console that will be customized, and inside this key, the values that define the console properties (more here)
So, let's say you have now a console scheme in the registry. When you start a console program via a shortcut, the window title of the started console is the text indicated as the shortcut name. Match shortcut name to console name defined in registry (or the reverse).

Open file to display content in C++

I have 2 questions to ask regarding opening files (any kind of files) using C++. I am currently working on a GUI program and I want to add a changelog in txt form. Also I want a menu in my program to open that changelog.txt with the default text editor every user has installed or to simply put it to open that text file. Please keep in mind that I want to open the file for display NOT in the program for input/output.I know I can do that using
system("notepad.exe filepath.txt");
or to open them with the preset program:
system("filepath.txt");
The problem is that both of those open a command line behind the notepad. I know there is another command to open files using Win32 API called CreateProccess() but my compiler doesn't recognise that command (OpenWatcom W32).
So here are my questions:
1) Is there any other command to open files or is there a way to stop the command line from opening when using system command?
2) How do you define in Windows that the text file is in the current program folder? I mean instead of giving the entire filepath which will change from user to user is there any way to "tell" the program that the file is always on the current folder that the program is in?
I am sorry for any errors, if you want any clarification please let me know.
CreateProcess would be the wrong function to use here. That would require you to decide which process to run. The user may prefer to use a text editor other than Notepad, I know I do! The right way to do this on Windows is to ask the shell to open the file with whatever program the user has associated with the file. The ShellExecute function does this.
Call it like this:
ShellExecute(
MainWindowHandle,
"open",
FullyQualifiedTextFileName,
NULL,
NULL,
SW_SHOWNORMAL
);
You will need to include the Shellapi.h header file and link to the Shell32.lib library. If your compiler does not include these files, and I would be surprised if that was the case, then you can get them from the Platform SDK. That said, if you are serious about programming on Windows you should get hold of a tool that gives you access to the Windows API.
I do recommend that you use a fully qualified path for a task like this. Since your text file is located in the same directory as the executable you should simply join that directory to your text file's name. Get hold of the full path to the executable by calling GetModuleFileName passing NULL for the hModule parameter.

Access denied when updating config file in ProgramData directory. How do I fix this?

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.