Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with Registry
Message
 
À
Tous
Information générale
Forum:
Visual C++
Catégorie:
Autre
Titre:
Help with Registry
Divers
Thread ID:
00639234
Message ID:
00639234
Vues:
52
Hi people!
well i have a bit of problem that i might think that someone will
come up with a solution.
i Spend 1 day and half checking and searching information in www.codeguru.com found value information about the registry. i found many classes for work with registry. i found good one in :http://www.codeguru.com/system/CRegKey.shtml

Now, i say that is very good because is done by Microsoft, but the reality is... i dont know how put to works!, i try with trial and error and searching information but i'm lost.

i need do in VC++ for performance reasons, because the program is loading in the user login.

this is my not working code:
(Wizard generate a MFC EXE Dialog Based)
BOOL CROLLUPApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CRegKey oRegKey;
CROLLUPDlg dlg;
HKEY hKeyRoot;
DWORD xx;
unsigned long nJol;
//hKeyRoot = 0;
hKeyRoot = HKEY_LOCAL_MACHINE;
unsigned long dd;
m_pMainWnd = &dlg;
CString cRegistro;
char cCode[20];
cRegistro="SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\1\\";
nJol=oRegKey.Open(hKeyRoot,cRegistro,KEY_QUERY_VALUE);
if (nJol==0)
{
oRegKey.QueryValue(cCode,_T("ProductName"),sizeof(cCode)); // no funciona!!!
}
-> here could be existe the working code (i explain later)-------------------------------------<<<<<<<
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResp.....

Basically i need do :
extract the value of the user's network card
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\1\ and obtain the value in serviceName, that is the user's Network Card (CB1021 in my case) ,later with this check in:
HKEY_LOCAL_MACHINE\SYSTEM\CONTROLSET001\SERVICES\CB1021\PARAMETERS\TCPIP\ y
HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\SERVICES\CB1021\PARAMETERS\TCPIP\

the value is DHCPEnabled, and i need check the status is 0 or 1, in case is 0 i need "write" to 1, but i dont have any idea, this work is for change all machines from defined IP to DHCP Enabled. my deadline is Monday, any help is appreciated.

sorry for my english

REgards

please, any question in my private email, thanks

Power without Skills is nothing



cRegKey.H --> definición
#include "stdafx.h"
class CRegKey
{
public:
CRegKey();
~CRegKey();
// Attributes
public:
operator HKEY() const;
HKEY m_hKey;
// Operations
public:
LONG SetValue(DWORD dwValue, LPCTSTR lpszValueName);
LONG QueryValue(DWORD& dwValue, LPCTSTR lpszValueName);
LONG QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount);
LONG SetValue(LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
LONG SetKeyValue(LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
static LONG WINAPI SetValue(HKEY hKeyParent, LPCTSTR lpszKeyName,
LPCTSTR lpszValue, LPCTSTR lpszValueName = NULL);
LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName,
LPTSTR lpszClass = REG_NONE, DWORD dwOptions = REG_OPTION_NON_VOLATILE,
REGSAM samDesired = KEY_ALL_ACCESS,
LPSECURITY_ATTRIBUTES lpSecAttr = NULL,
LPDWORD lpdwDisposition = NULL);
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName,
REGSAM samDesired = KEY_ALL_ACCESS);
LONG Close();
HKEY Detach();
void Attach(HKEY hKey);
LONG DeleteSubKey(LPCTSTR lpszSubKey);
LONG RecurseDeleteKey(LPCTSTR lpszKey);
LONG DeleteValue(LPCTSTR lpszValue);
};
inline CRegKey::CRegKey()
{m_hKey = NULL;}
inline CRegKey::~CRegKey()
{Close();}
inline CRegKey::operator HKEY() const
{return m_hKey;}
inline HKEY CRegKey::Detach()
{
HKEY hKey = m_hKey;
m_hKey = NULL;
return hKey;
}
inline void CRegKey::Attach(HKEY hKey)
{
_ASSERTE(m_hKey == NULL);
m_hKey = hKey;
}
inline LONG CRegKey::DeleteSubKey(LPCTSTR lpszSubKey)
{
_ASSERTE(m_hKey != NULL);
return RegDeleteKey(m_hKey, lpszSubKey);
}
inline LONG CRegKey::DeleteValue(LPCTSTR lpszValue)
{
_ASSERTE(m_hKey != NULL);
return RegDeleteValue(m_hKey, (LPTSTR)lpszValue);
}

cRegKey.cpp --> Implementacion
/////////////////////////////////////////////////////////////////////////////
// CRegKey
#include "cregkey.h"
LONG CRegKey::Close()
{
LONG lRes = ERROR_SUCCESS;
if (m_hKey != NULL)
{
lRes = RegCloseKey(m_hKey);
m_hKey = NULL;
}
return lRes;
}
LONG CRegKey::Create(HKEY hKeyParent, LPCTSTR lpszKeyName,
LPTSTR lpszClass, DWORD dwOptions, REGSAM samDesired,
LPSECURITY_ATTRIBUTES lpSecAttr, LPDWORD lpdwDisposition)
{
_ASSERTE(hKeyParent != NULL);
DWORD dw;
HKEY hKey = NULL;
LONG lRes = RegCreateKeyEx(hKeyParent, lpszKeyName, 0,
lpszClass, dwOptions, samDesired, lpSecAttr, &hKey, &dw);
if (lpdwDisposition != NULL)
*lpdwDisposition = dw;
if (lRes == ERROR_SUCCESS)
{
lRes = Close();
m_hKey = hKey;
}
return lRes;
}
LONG CRegKey::Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired)
{
_ASSERTE(hKeyParent != NULL);
HKEY hKey = NULL;
LONG lRes = RegOpenKeyEx(hKeyParent, lpszKeyName, 0, samDesired, &hKey);
if (lRes == ERROR_SUCCESS)
{
lRes = Close();
_ASSERTE(lRes == ERROR_SUCCESS);
m_hKey = hKey;
}
return lRes;
}
LONG CRegKey::QueryValue(DWORD& dwValue, LPCTSTR lpszValueName)
{
DWORD dwType = NULL;
DWORD dwCount = sizeof(DWORD);
LONG lRes = RegQueryValueEx(m_hKey, (LPTSTR)lpszValueName, NULL, &dwType,
(LPBYTE)&dwValue, &dwCount);
_ASSERTE((lRes!=ERROR_SUCCESS) || (dwType == REG_DWORD));
_ASSERTE((lRes!=ERROR_SUCCESS) || (dwCount == sizeof(DWORD)));
return lRes;
}
LONG CRegKey::QueryValue(LPTSTR szValue, LPCTSTR lpszValueName, DWORD* pdwCount)
{
_ASSERTE(pdwCount != NULL);
DWORD dwType = NULL;
LONG lRes = RegQueryValueEx(m_hKey, (LPTSTR)lpszValueName, NULL, &dwType,
(LPBYTE)szValue, pdwCount);
_ASSERTE((lRes!=ERROR_SUCCESS) || (dwType == REG_SZ) ||
(dwType == REG_MULTI_SZ) || (dwType == REG_EXPAND_SZ));
return lRes;
}
LONG WINAPI CRegKey::SetValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName)
{
_ASSERTE(lpszValue != NULL);
CRegKey key;
LONG lRes = key.Create(hKeyParent, lpszKeyName);
if (lRes == ERROR_SUCCESS)
lRes = key.SetValue(lpszValue, lpszValueName);
return lRes;
}
LONG CRegKey::SetKeyValue(LPCTSTR lpszKeyName, LPCTSTR lpszValue, LPCTSTR lpszValueName)
{
_ASSERTE(lpszValue != NULL);
CRegKey key;
LONG lRes = key.Create(m_hKey, lpszKeyName);
if (lRes == ERROR_SUCCESS)
lRes = key.SetValue(lpszValue, lpszValueName);
return lRes;
}
LONG CRegKey::SetValue(DWORD dwValue, LPCTSTR lpszValueName)
{
_ASSERTE(m_hKey != NULL);
return RegSetValueEx(m_hKey, lpszValueName, NULL, REG_DWORD,
(BYTE * const)&dwValue, sizeof(DWORD));
}
HRESULT CRegKey::SetValue(LPCTSTR lpszValue, LPCTSTR lpszValueName)
{
_ASSERTE(lpszValue != NULL);
_ASSERTE(m_hKey != NULL);
return RegSetValueEx(m_hKey, lpszValueName, NULL, REG_SZ,
(BYTE * const)lpszValue, (lstrlen(lpszValue)+1)*sizeof(TCHAR));
}
//RecurseDeleteKey is necessary because on NT RegDeleteKey doesn't work if the
//specified key has subkeys
LONG CRegKey::RecurseDeleteKey(LPCTSTR lpszKey)
{
CRegKey key;
LONG lRes = key.Open(m_hKey, lpszKey);
if (lRes != ERROR_SUCCESS)
return lRes;
FILETIME time;
TCHAR szBuffer[256];
DWORD dwSize = 256;
while (RegEnumKeyEx(key.m_hKey, 0, szBuffer, &dwSize, NULL, NULL, NULL,
&time)==ERROR_SUCCESS)
{
lRes = key.RecurseDeleteKey(szBuffer);
if (lRes != ERROR_SUCCESS)
return lRes;
dwSize = 256;
}
key.Close();
return DeleteSubKey(lpszKey);
}
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform