Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

registry editing

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need to edit a registry key in my registry using a console application. I tried searching microsoft for "registry", but didn't find scripts.
 
source
Creating or Opening a Registry Key

Before you can read or write to a key, you must first obtain a handle to it. To do this, use either the RegOpenRegKeyEx or RegCreateKeyEx Microsoft Win32® functions. In practice, you will almost always use RegCreateKeyEx, which will open the key if it exists or create it if it does not. Here is a typical scenario:

Declare an HKEY variable in your code.
Call RegCreateKeyEx, passing HKEY_LOCAL_MACHINE as the parent key and Software/YourCompany/YourApplication as the subkey.
For each setting you wish to read, call RegQueryValueEx, and if the setting is not found set a default value.
Close the handle to the key with RegCloseKey.
Sample code:


void CMyFirstMFCApplicationApp::LoadPreferences()
{
HKEY hkey;
DWORD dwDisposition;

DWORD dwType, dwSize;

// Set the default values
m_dwMaxFileSize = 16 * 1024; // 16k
_tcscpy(m_szLastFileName, TEXT("Datafile.TXT"));

if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\My Company\\My
Application"), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==
ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegQueryValueEx(hkey, TEXT("MaxFileSize"), NULL, &dwType,
(PBYTE)&m_dwMaxFileSize, &dwSize);

dwType = REG_SZ;
dwSize = sizeof(m_szLastFileName);
RegQueryValueEx(hkey, TEXT("LastFileName"), NULL, &dwType,
(PBYTE)&m_szLastFileName, &dwSize);

RegCloseKey(hkey);
}
}


void CMyFirstMFCApplicationApp::SavePreferences()
{
HKEY hkey;
DWORD dwDisposition;

DWORD dwType, dwSize;

if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\My Company\\My
Application"), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==
ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegSetValueEx(hkey, TEXT("MaxFileSize"), 0, dwType,
(PBYTE)&m_dwMaxFileSize, dwSize);

dwType = REG_SZ;
dwSize = (_tcslen(m_szLastFileName) + 1) * sizeof(TCHAR);
RegSetValueEx(hkey, TEXT("LastFileName"), 0, dwType,
(PBYTE)&m_szLastFileName, dwSize);

RegCloseKey(hkey);
}
}
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
I don't get it at all. Can you maybe edit that code a little bit (making the areas I need to edit italic)? And, I will need to make that file edit hkey_local_machine/somecrap/file
 
Here is what I did (the bold areas are what I edited):

void CMyFirstMFCApplicationApp::LoadPreferences()
{
HKEY hkey;
DWORD dwDisposition;

DWORD dwType, dwSize;

// Set the default values
m_dwMaxFileSize = 16 * 1024; // 16k
_tcscpy(m_szLastFileName, TEXT("Datafile.TXT"));

if(RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Logitech\\MouseWare\\CurrentVersion\\Control Center\\Schemes\\.Default\\Devices\\Cordless6\\0001\\Assignments\\MiddleMouseShortClick\\AutoScroll\\ScrollCompatibility"), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==
ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegQueryValueEx(hkey, TEXT("MaxFileSize"), NULL, &dwType,
(PBYTE)&m_dwMaxFileSize, &dwSize);

dwType = REG_SZ;
dwSize = sizeof(m_szLastFileName);
RegQueryValueEx(hkey, TEXT("2"), NULL, &dwType,
(PBYTE)&m_szLastFileName, &dwSize);

RegCloseKey(hkey);
}
}


void CMyFirstMFCApplicationApp::LoadPreferences()
{
HKEY hkey;
DWORD dwDisposition;

DWORD dwType, dwSize;

// Set the default values
m_dwMaxFileSize = 16 * 1024; // 16k
_tcscpy(m_szLastFileName, TEXT("Datafile.TXT"));

if(RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Logitech\\MouseWare\\CurrentVersion\\Control Center\\Schemes\\.Default\\Devices\\Cordless6\\0001\\MacSets\\AutoScroll\\ScrollCompatibility"), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==
ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegQueryValueEx(hkey, TEXT("MaxFileSize"), NULL, &dwType,
(PBYTE)&m_dwMaxFileSize, &dwSize);

dwType = REG_SZ;
dwSize = sizeof(m_szLastFileName);
RegQueryValueEx(hkey, TEXT("2"), NULL, &dwType,
(PBYTE)&m_szLastFileName, &dwSize);

RegCloseKey(hkey);
}
}


void CMyFirstMFCApplicationApp::LoadPreferences()
{
HKEY hkey;
DWORD dwDisposition;

DWORD dwType, dwSize;

// Set the default values
m_dwMaxFileSize = 16 * 1024; // 16k
_tcscpy(m_szLastFileName, TEXT("Datafile.TXT"));

if(RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Logitech\\MouseWare\\CurrentVersion\\Control Center\\Schemes\\.Default\\MacSets\\DoubleM\\AutoScroll\\ScrollCompatibility"), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==
ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegQueryValueEx(hkey, TEXT("MaxFileSize"), NULL, &dwType,
(PBYTE)&m_dwMaxFileSize, &dwSize);

dwType = REG_SZ;
dwSize = sizeof(m_szLastFileName);
RegQueryValueEx(hkey, TEXT("2"), NULL, &dwType,
(PBYTE)&m_szLastFileName, &dwSize);

RegCloseKey(hkey);
}
}


 
best way to know test it ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Okay, there are fifty errors. Can you fix it (I can't fix a script I have never worked with)?

#include <iostream.h>
#include <io.h>
#include <windows.h>
#include <Winbase.h>
int main ()
{
int selection;


cout << &quot;This file will update your registry in order to fix the Quake 3 mouse3 problem. Press 1 to continue or 2 to exit. \n&quot;;
cin >> selection;
if (selection == 1);

{
cout << &quot;editing Registry... \n&quot;;


void CMyFirstMFCApplicationApp::LoadPreferences()
{
HKEY hkey;
DWORD dwDisposition;

DWORD dwType, dwSize;

// Set the default values
m_dwMaxFileSize = 16 * 1024; // 16k
_tcscpy(m_szLastFileName, TEXT(&quot;Datafile.TXT&quot;));

if(RegCreateKeyEx(HKEY_CURRENT_USER, TEXT(&quot;Software\\Logitech\\MouseWare\\CurrentVersion\\Control Center\\Schemes\\.Default\\Devices\\Cordless6\\0001\\Assignments\\MiddleMouseShortClick\\AutoScroll\\ScrollCompatibility&quot;), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==
ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegQueryValueEx(hkey, TEXT(&quot;MaxFileSize&quot;), NULL, &dwType,
(PBYTE)&m_dwMaxFileSize, &dwSize);

dwType = REG_SZ;
dwSize = sizeof(m_szLastFileName);
RegQueryValueEx(hkey, TEXT(&quot;2&quot;), NULL, &dwType,
(PBYTE)&m_szLastFileName, &dwSize);

RegCloseKey(hkey);
}
}


void CMyFirstMFCApplicationApp::LoadPreferences()
{
HKEY hkey;
DWORD dwDisposition;

DWORD dwType, dwSize;

// Set the default values
m_dwMaxFileSize = 16 * 1024; // 16k
_tcscpy(m_szLastFileName, TEXT(&quot;Datafile.TXT&quot;));

if(RegCreateKeyEx(HKEY_CURRENT_USER, TEXT(&quot;Software\\Logitech\\MouseWare\\CurrentVersion\\Control Center\\Schemes\\.Default\\Devices\\Cordless6\\0001\\MacSets\\AutoScroll\\ScrollCompatibility&quot;), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==
ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegQueryValueEx(hkey, TEXT(&quot;MaxFileSize&quot;), NULL, &dwType,
(PBYTE)&m_dwMaxFileSize, &dwSize);

dwType = REG_SZ;
dwSize = sizeof(m_szLastFileName);
RegQueryValueEx(hkey, TEXT(&quot;2&quot;), NULL, &dwType,
(PBYTE)&m_szLastFileName, &dwSize);

RegCloseKey(hkey);
}
}


void CMyFirstMFCApplicationApp::LoadPreferences()
{
HKEY hkey;
DWORD dwDisposition;

DWORD dwType, dwSize;

// Set the default values
m_dwMaxFileSize = 16 * 1024; // 16k
_tcscpy(m_szLastFileName, TEXT(&quot;Datafile.TXT&quot;));

if(RegCreateKeyEx(HKEY_CURRENT_USER, TEXT(&quot;Software\\Logitech\\MouseWare\\CurrentVersion\\Control Center\\Schemes\\.Default\\MacSets\\DoubleM\\AutoScroll\\ScrollCompatibility&quot;), 0, NULL, 0, 0, NULL, &hkey, &dwDisposition)==
ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegQueryValueEx(hkey, TEXT(&quot;MaxFileSize&quot;), NULL, &dwType,
(PBYTE)&m_dwMaxFileSize, &dwSize);

dwType = REG_SZ;
dwSize = sizeof(m_szLastFileName);
RegQueryValueEx(hkey, TEXT(&quot;2&quot;), NULL, &dwType,
(PBYTE)&m_szLastFileName, &dwSize);

RegCloseKey(hkey);
}
}
cout << &quot;Program Executed&quot;;
}

else {
cout << &quot;Program Aborted&quot;;
}

return 0;
}

 
what was the errors ?
can u use another language ? so much code so 'simple' task
what other language do u use ?
what do u what exactly ? create one , delete one , read one?
&quot;I can't fix a script I have never worked with&quot;
i didn't work with it either ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
It is supposed to edit three registry valus.

Here are the errors (compile log):

Building Makefile: &quot;C:\Dev-C++\reg\Makefile.win&quot;
Executing make...
make.exe all -f &quot;C:\Dev-C++\reg\Makefile.win&quot;
Execution terminated
g++.exe -c reg.cpp -o reg.o -I&quot;C:\Dev-C++\include&quot; -I&quot;C:\Dev-C++\include\g++-3&quot; -I&quot;C:\Dev-C++\include&quot; -s
reg.cpp: In function `int main()':
reg.cpp:18: variable or field `CMyFirstMFCApplicationApp' declared void
reg.cpp:18: parse error before `::'
reg.cpp:26: `m_dwMaxFileSize' undeclared (first use this function)
reg.cpp:26: (Each undeclared identifier is reported only once
reg.cpp:26: for each function it appears in.)
reg.cpp:27: `m_szLastFileName' undeclared (first use this function)
reg.cpp:27: implicit declaration of function `int _tcscpy(...)'
reg.cpp:29: `hkey' undeclared (first use this function)
reg.cpp:47: variable or field `CMyFirstMFCApplicationApp' declared void
reg.cpp:47: parse error before `::'
reg.cpp: At top level:
reg.cpp:76: syntax error before `::'
reg.cpp:84: ANSI C++ forbids declaration `m_dwMaxFileSize' with no type
reg.cpp:84: `int m_dwMaxFileSize' used prior to declaration
reg.cpp:85: ANSI C++ forbids declaration `_tcscpy' with no type
reg.cpp:85: warning: `_tcscpy' was previously implicitly declared to return `int'
reg.cpp:85: initializer list being treated as compound expression
reg.cpp:87: parse error before `if'
reg.cpp:91: ANSI C++ forbids declaration `dwSize' with no type
reg.cpp:91: conflicting types for `int dwSize'
reg.cpp:81: previous declaration as `DWORD dwSize'
reg.cpp:93: ANSI C++ forbids declaration `RegQueryValueExA' with no type
reg.cpp:93: `int RegQueryValueExA' redeclared as different kind of symbol
C:/Dev-C++/include/winreg.h:83: previous declaration of `LONG RegQueryValueExA(HKEY__ *, const CHAR *, DWORD *, DWORD *, BYTE *, DWORD *)'
reg.cpp:93: initializer list being treated as compound expression
reg.cpp:95: ANSI C++ forbids declaration `dwType' with no type
reg.cpp:95: conflicting types for `int dwType'
reg.cpp:81: previous declaration as `DWORD dwType'
reg.cpp:96: ANSI C++ forbids declaration `dwSize' with no type
reg.cpp:96: redefinition of `int dwSize'
reg.cpp:91: `int dwSize' previously defined here
reg.cpp:98: ANSI C++ forbids declaration `RegQueryValueExA' with no type
reg.cpp:98: redefinition of `int RegQueryValueExA'
reg.cpp:93: `int RegQueryValueExA' previously defined here
reg.cpp:98: initializer list being treated as compound expression
reg.cpp:100: ANSI C++ forbids declaration `RegCloseKey' with no type
reg.cpp:100: `int RegCloseKey' redeclared as different kind of symbol
C:/Dev-C++/include/winreg.h:52: previous declaration of `LONG RegCloseKey(HKEY__ *)'
reg.cpp:101: parse error before `}'
reg.cpp:103: syntax error before `<'
make.exe: *** [reg.o] Error 1
0

 
can you include the whole code, including all required libraries please.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top