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).
Related
I have a batch program that I would like to add to one of my c++ programs. The batch program tests if a file exists and exits the script if it doesn't. I do not want to add any more libraries to my code. The problem that I have is that I am not sure how I am able to use batch in c++. I am able to figure everything else out on my own I just need to know this one thing.
You can use the system(" ") command to use batch.
Assuming you are on Windows,
you have two options available to run batch files on Windows from C/C++.
You can use system (or _wsystem for wide characters).
"The system function passes command to the command interpreter,
which executes the string as an operating-system command. system
refers to the COMSPEC and PATH environment variables that locate the
command-interpreter file (the file named CMD.EXE in Windows 2000 and
later)."
Or
You can use CreateProcess directly.
Note that for batch files:
"To run a batch file, you must start the command interpreter; set
lpApplicationName to cmd.exe and set lpCommandLine to the following
arguments: /c plus the name of the batch file."
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.
In visual studio you can specify in
"Project Properties > Debugging > Command Arguments"
the arguments you want to pass in. But I want to be able to change this manually so I can run different arguments and test my code. Is there a way to open the console and pass in arguments like you normally would in a unix shell?
./myProg arg1 arg2
Having to go into the properties and change every time is annoying.
Thanks!
I'm not sure specifically with how you'd like to open the console, like what the intended result here is. I could interpret this a few ways.
You can run your application from an external command prompt set to the binary directory with any args you want, but the issue is that you would have to attach your debugger if you needed to do debugging. You could switch to console-based debugging or you could introduce a console read in order to attach the debugger.
In later versions of Windows, holding shift and right clicking in Explorer yields an Open command window here option. This makes it quick and easy to open up a command prompt. You can right click a C++ project and Open Folder in File Explorer. This'll get you most of the way there.
If you want, you could specify a special sentinel arg that allows you to interactively populate commandline args within the program. Either that or if there are expected to be args and there are none, you could assume that means interactive mode.
Using cmd /c, you might be able to come up with some really tricky things. Using batch files or all sorts of craziness to populate args. You could combine this with build steps etc. to produce output that batch files read. The sky is the limit.
I don't know specifically what sort of thing you were after, but hopefully this enumerates some things that might be of help.
The IDE I'm using is VS2010 for writing C++
I want to execute the command cmd C:\utilities\unix\tail.exe -f -n15 $(ProjectDir)Log.txt every time the program I'm coding is run from within the IDE. (This command should open a console to track changes made to the file Log.txt)
There are ways to make a command run every time the program is built, but I can't find a way to make a command run whenever the program itself is run, even if it's already built. Where or how might I be able to set that kind of thing up?
I've tried putting $(TargetPath) & C:\utilities\unix\tail.exe -f -n15 $(ProjectDir)Log.txt into the project's Properties->Debugging->Command (TargetPath is the full name of the debug executable) but VS reads the entire thing as a filename and gets confused.
You can create a file run.cmd for example next to the vcxproj file, which would contain:
%1
C:\utilities\unix\tail.exe -f -n15 %2Log.txt
And then in Properties->Debugging->Command you write:
$(ProjectDir)\run.cmd
and in Command Arguments you write:
"$(TargetPath)" "$(ProjectDir)"
I may have misspelled the macros, but you get the idea: it executes first your program and then whatever you want.
Edit: Unfortunately it works only if you start without debugging (Ctrl+F5), because otherwise the debugger tries to attach to run.cmd and complains that the format is unsupported.
I wanna create a exe which has the Shell Script and Simple CPP file which calls the Shell Script using system() function. Lets say exe name 'myInstaller' which has files myintsaller.cpp and myShell.sh. When i run the exe myInstaller , it must execute shell script. I want to do like this so i can protect my Shell Script code ,which has over 3000 lines of Code.
How do i do this ... I m in real need of this.
As far as i've searched, there is no way to bundle the script inside the exe. Either it would be Shell Compiler as shelter suggested or plain shell scripts. No work around for this.
I guess it's Windows platform since you speak about exe. In this case you can add your script as a resource to your exe, extract it in run-time and execute.
You could keep the script as a string in your C++ code and call system("sh -c '" + code + "'"). Quoting may be an issue though. Otherwise, write it to a temp location, execute it and then unlink it.