e3 Rental Property Templates

Welcome Guest (Register -  Login)  Active Topics Active Topics Display List of Forum Members Memberlist Search The Forum Search Help Help
 Navigation
 Skin Chooser

Choose Skin:


There are 2 skins total.
The newest skin is Classis Default

 Latest Forum Posts

Files, Folders, & Directories
 C++ GamesFiles, Folders, & Directories
Subject Topic: registry Post ReplyPost New Topic
 registry
<< Prev Topic | Next Topic >>
blackfox
Posted: 19-February-2006 at 11:37pm | IP Logged Quote blackfox

Newbie
Newbie


Group: Newbie
Joined: 19-February-2006
Posts: 1

can we edit registry by using a c++ program??

if  yes can anyone show me an example program?

 
Online Status: Offline
View blackfox's Profile Search for other posts by blackfox Back to Top
 
DutchDude
Posted: 21-April-2007 at 4:52am | IP Logged Quote DutchDude
Avatar
Super Dedicated Groupie
Super Dedicated Groupie


Group: Super Dedicated Groupie
Joined: 02-April-2007
Location: Netherlands
Posts: 71
I found out the delete function 
its pretty long, but i got from MSDN
hope this helps

The example in this topic uses the RegOpenKeyEx, RegEnumKeyEx, and RegDeleteKey functions to delete a registry key with subkeys.

To test this example, create the following registry key by using Regedt32.exe, and then add a few values and subkeys:

HKEY_CURRENT_USER\Software\TestDir

After running the code, use the F5 key to refresh the registry data, and notice that the TestDir key is deleted.

____________________________________________________________________

#include <windows.h>
#include <stdio.h>
#include <strsafe.h>
//*************************************************************
//
// RegDelnodeRecurse()
//
// Purpose: Deletes a registry key and all it's subkeys / values.
//
// Parameters: hKeyRoot - Root key
// lpSubKey - SubKey to delete
//
// Return: TRUE if successful.
// FALSE if an error occurs.
//
//*************************************************************

BOOL RegDelnodeRecurse (HKEY hKeyRoot, LPTSTR lpSubKey)
{
LPTSTR lpEnd;
LONG lResult;
DWORD dwSize;
TCHAR szName[MAX_PATH];
HKEY hKey;
FILETIME ftWrite;

// First, see if we can delete the key without having
// to recurse.

lResult = RegDeleteKey(hKeyRoot, lpSubKey);

if (lResult == ERROR_SUCCESS)
return TRUE;

lResult = RegOpenKeyEx (hKeyRoot, lpSubKey, 0, KEY_READ, &hKey);

if (lResult != ERROR_SUCCESS)
{
if (lResult == ERROR_FILE_NOT_FOUND) {
printf("Key not found.\n");
return TRUE;
}
else {
printf("Error opening key.\n");
return FALSE;
}
}

// Check for an ending slash and add one if it is missing.

lpEnd = lpSubKey + lstrlen(lpSubKey);

if (*(lpEnd - 1) != TEXT('\\'))
{
*lpEnd = TEXT('\\');
lpEnd++;
*lpEnd = TEXT('\0');
}

// Enumerate the keys

dwSize = MAX_PATH;
lResult = RegEnumKeyEx(hKey, 0, szName, &dwSize, NULL,
NULL, NULL, &ftWrite);

if (lResult == ERROR_SUCCESS)
{
do {

StringCchCopy (lpEnd, MAX_PATH*2, szName);

if (!RegDelnodeRecurse(hKeyRoot, lpSubKey)) {
break;
}

dwSize = MAX_PATH;

lResult = RegEnumKeyEx(hKey, 0, szName, &dwSize, NULL,
NULL, NULL, &ftWrite);

} while (lResult == ERROR_SUCCESS);
}

lpEnd--;
*lpEnd = TEXT('\0');

RegCloseKey (hKey);

// Try again to delete the key.

lResult = RegDeleteKey(hKeyRoot, lpSubKey);

if (lResult == ERROR_SUCCESS)
return TRUE;

return FALSE;
}

//*************************************************************
//
// RegDelnode()
//
// Purpose: Deletes a registry key and all it's subkeys / values.
//
// Parameters: hKeyRoot - Root key
// lpSubKey - SubKey to delete
//
// Return: TRUE if successful.
// FALSE if an error occurs.
//
//*************************************************************

BOOL RegDelnode (HKEY hKeyRoot, LPTSTR lpSubKey)
{
TCHAR szDelKey[2 * MAX_PATH];

StringCchCopy (szDelKey, MAX_PATH*2, lpSubKey);
return RegDelnodeRecurse(hKeyRoot, szDelKey);

}

void main()
{
BOOL bSuccess;

bSuccess = RegDelnode(HKEY_CURRENT_USER,
TEXT("Software\\TestDir"));

if(bSuccess)
printf("Success!\n");
else printf("Failure.\n");
}
-------------------------------------------------------------------------------------------------
 
Online Status: Offline
View DutchDude's Profile Search for other posts by DutchDude Visit DutchDude's CppGames Back to Top
 
johnnei
Posted: 08-July-2009 at 5:43am | IP Logged Quote johnnei

Newbie
Newbie


Group: Newbie
Joined: 08-July-2009
Location: Netherlands
Posts: 1
this is for a console aplication:

#include "stdafx.h"
using namespace Microsoft::Win32;

int main(){
String^ cad = (String^)Registry::GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Autodesk\\AutoCAD\\R18.0\\ACAD-8001:409\\","AcadLocation","None");
cout << cad;
}

this will recieve the location of autocad 2010.
but the sintax is eay
Registery::GetValue(registery_key_folder,registery_key_name,text_to_be_return_when_not_exists);

you can find more of these key's in: http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.aspx
 
Online Status: Offline
View johnnei's Profile Search for other posts by johnnei Back to Top
 
1 User(s) are browsing this topic, 1 Guest(s) and 0 Member(s)
0 Members:
<< Prev Topic Files, Folders, & Directories Next Topic >>

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.2188 seconds.

[ Users browsing page: none ]



Terms and Conditions | Privacy | Contact Us

Copyright © 2010 Cpp Games. All rights reserved.

This site is best viewed at 1024x768 screen resolution.
Back to Top

Designed by Micronet Technologies