C++ Write Registry [duplicate] - c++

This question already has answers here:
Using C++ to edit the registry
(5 answers)
Closed 9 years ago.
I will write this registry key in the registry.
It should be written in C++ for windows 7 and 8.
This is the .reg file:
REGEDIT4
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\.bin\]
[-HKEY_CLASSES_ROOT\binimage\]
[-HKEY_CLASSES_ROOT\Bootvis Trace File\]
[-HKEY_CLASSES_ROOT\Crestron SIMPL Windows Compiled Program\]
[-HKEY_CLASSES_ROOT\elby.VCDMount.1\]
[-HKEY_CLASSES_ROOT\gBurner\]
[-HKEY_CLASSES_ROOT\ImgBurn.AssocFile.bin\]
[-HKEY_CLASSES_ROOT\IsoBuster.bin\]
[-HKEY_CLASSES_ROOT\IZArcBIN\]
[-HKEY_CLASSES_ROOT\MPlayerFileVideo\]
[-HKEY_CLASSES_ROOT\PAISO\]
[-HKEY_CLASSES_ROOT\StuffIt.Archive.Open.Generic\]
[-HKEY_CLASSES_ROOT\StuffIt11.Archive.Open.Generic\]
[-HKEY_CLASSES_ROOT\TzBIN\]
[-HKEY_CLASSES_ROOT\UltraEdit.bin\]
[-HKEY_CLASSES_ROOT\VLC.bin\]
[HKEY_CLASSES_ROOT\.bin\]
#="exefile"
"Content Type"="application/x-msdownload"
[HKEY_CLASSES_ROOT\.bin\PersistentHandler\]
#="{098f2470-bae0-11cd-b579-08002b30bfeb}"
[HKEY_CLASSES_ROOT\.bin\shell\open\command\]
#="\"%1\" %*"
IDK how to do it but maybe anyone here can help me :)
Thanks :)

You should use the WinAPI functions for registry handling. You can find the list here.
I would be checking these functions:
RegCreateKeyEx
RegOpenKeyEx
RegGetValue
RegSetValueEx
RegCloseKey

Related

Pass %PROGRAMFILES% environment variable to _access_s [duplicate]

This question already has answers here:
Using Windows Environment Variable in Native Code
(2 answers)
Closed 10 months ago.
I am trying to check for the existence of a file using _access_s
errno_t ret = _access_s("%PROGRAMFILES(x86)%\\Microsoft\\Edge\\Application\\msedge.exe", 0); ---> //error, returns 2
errno_t ret = _access_s("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe", 0); ----> //works fine
How to use environment variables in the path for _acces_s method?
Edit: I am looking for a winrt api as this is UWP app I am working on.
Before passing the path to _access_s you need to expand the environment variables.
You can use ExpandEnvironmentStringsA function for that. This function gets a path with environment variables and outputs a path with the variables expanded.

How to open protected Windows share using Python? [duplicate]

This question already has answers here:
Python - How to open Windows share using user name and password
(4 answers)
Closed 5 years ago.
How do I open Windows share with credentials using Python on a Windows machine?
I'm currently doing this:
share = open(r'share#username:password','r')
i used
subprocess.call(r'net use z: \windows_server\share /user:#username password', shell=True)
to mount the share and
subprocess.call(r'net use z: /delete')
to delete it.This is the most hassle free and efficient way. Thanks everyone for the help!!

Text from URL to String - C++ [duplicate]

This question already has answers here:
Downloading HTTP URLs asynchronously in C++
(4 answers)
Closed 8 years ago.
What I want my program to do is to download data from URL(this will be some text, code, whatever) and save it to string in C++. How do I do this? I googled a lot and found absolutely nothing, except using some classes that exist only on Linux. I'm working on Windows so I don't accept answers such as: use curl.h . Thanks
There are some POCO libraries that make it very easy. Here is some code that reads a single line of text from a website:
#include "Poco/URIStreamOpener.h"
#include "Poco/Net/HTTPStreamFactory.h"
Poco::Net::HTTPStreamFactory::registerFactory();
Poco::URIStreamOpener& opener = Poco::URIStreamOpener::defaultOpener();
try
{
std::auto_ptr<std::istream> reader(opener.open(myURL));
reader->getline(line,sizeof(line));
}
catch(...)
{
}
And that's all there is to it. The try...catch is there in case of a bad Internet connection.

How to get the current default set language of the current Windows OS for version 7 and later versions using C++? [duplicate]

This question already has answers here:
How to get OS language using C++ API?
(3 answers)
Closed 8 years ago.
How to get the current default set language of the current Windows OS for version 7 and later versions using C++?
To deal this, I've tried to look for in the net but without any result.
Any brilliant suggestion, please?
Thanks a lot!
You can call GetUserDefaultLocaleName to get the locale
string const s = setlocale( LC_ALL, "" );
cout << s << endl;
… is one way.
Update: The above does not retrieve the “preferred” language set in the Control Panel. E.g. on my laptop it says Norwegian in spite of a preference for US English. Following the documentation I tried GetSystemPreferredUILanguages, but it still reported Norwegian. However, GetThreadUILanguage reports US English, so presumably that's it.

Execute file in another directory [duplicate]

This question already has answers here:
system("c:\\sample\\startAll.bat") cannot run because of working directory?
(4 answers)
Closed 9 years ago.
Consider the following:
I have a c++ program in C:\Documents\myProgram.exe
With this code in it:
system("start C:\\somefolder\\start.bat");
That will start the target file (start.bat) in C:\Documents\ instead of `C:\somefolder\'.
My question is, how do I execute the file in it's own directory instead of myProgram's directory?
In theory this is what I want to accomplish using c++:
cd C:\somefolder\,
start start.bat
If you're on windows anyway, use ShellExecute, you can set more things and launch even documents, links etc.
To do this you can do one of two things (that I found).
A) You can use chdir() in unistd.h; see http://pubs.opengroup.org/onlinepubs/7908799/xsh/unistd.h.html
or
B) You can use something called the File System Interface, from the GNU library, for more advanced stuff; see http://www.gnu.org/software/libc/manual/html_node/File-System-Interface.html#File-System-Interface.
Anyway, best of luck, I hope you find something that will work!