Remote Registrys

This is a discussion on Remote Registrys within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'm develping in Code::Blocks and wxWidgets (if that matters!) What I want to know is, how can I read ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Location
    Northamptonshire, UK
    Posts
    18

    Remote Registrys

    Hi,

    I'm develping in Code::Blocks and wxWidgets (if that matters!)

    What I want to know is, how can I read values from another machine's registry (I'm logged on as a domain user which is a member of the local admins on the machine in question).

    I don't (at this stage anyway!) want to make any changes.

    Ideas, anyone?

    Grateful thanks for reading this and (hopefully) responding.

    Paul

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Example of reading registry string (REG_SZ)

    Code:
    #pragma comment( lib, "advapi32.lib" )
    #include <windows.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    BOOL ReadRegistryString(HKEY hKey, LPCTSTR szValueName, LPTSTR * lpszReturnValue)
    {
    	DWORD dwType = 0, dwDataSize = 0, dwBufferSize = 0;
    	if(RegQueryValueEx(hKey, szValueName, 0, &dwType, NULL, &dwDataSize ) != ERROR_SUCCESS) return  FALSE;
    	else if (dwType != REG_SZ) return FALSE;
    	dwBufferSize = dwDataSize + (1 * sizeof(CHAR));
    	if((*lpszReturnValue = (LPTSTR) malloc(dwBufferSize)) == NULL)
    		return FALSE;
    	if( RegQueryValueEx(hKey, szValueName, 0, &dwType, (LPBYTE) *lpszReturnValue, &dwDataSize ) != ERROR_SUCCESS)
    	{ 
    		free(*lpszReturnValue);
    		return FALSE;
    	}
    	else if (dwType != REG_SZ)
    	{
    		free(*lpszReturnValue);
    		return FALSE;
    	}
    	(*lpszReturnValue)[(dwBufferSize / sizeof(CHAR)) - 1] = '\0';
    	return TRUE;
    }
    
    INT main(void)
    {
    	HKEY hKey = NULL;
    	HKEY hKeyRemote = NULL;
    	LPTSTR szReturnValue;
    	CHAR szComputerName[] = {"\\\\myPC"};
    
    	if(RegConnectRegistry(szComputerName, HKEY_LOCAL_MACHINE, &hKeyRemote) == ERROR_SUCCESS)
    	{
    		if(RegOpenKeyEx(hKeyRemote, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
    		{
    			if( ReadRegistryString(hKey,"ProgramFilesDir", &szReturnValue) == TRUE)
    			{
    				printf("The returned value is %s\n", szReturnValue);
    				RegCloseKey(hKey); 
    			}
    			else printf("ReadRegistryString failed\n");
    		}
    		RegCloseKey(hKeyRemote); 
    	}
    	else printf("RegConnectRegistry failed\n");
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    Jan 2007
    Location
    Northamptonshire, UK
    Posts
    18
    Many thanks :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Remote debug not working in Visual Studio 2003
    By Bassquake in forum Tech Board
    Replies: 12
    Last Post: 08-22-2008, 01:11 PM
  2. Howto make own application for remote control handling
    By s-men in forum Windows Programming
    Replies: 16
    Last Post: 08-16-2008, 05:22 PM
  3. Visual Studio remote debugging
    By George2 in forum Windows Programming
    Replies: 1
    Last Post: 07-08-2008, 01:26 AM
  4. Remote thread problem
    By RubbeR DuckY in forum C++ Programming
    Replies: 6
    Last Post: 08-08-2006, 01:24 PM
  5. remote dirinfo
    By AngKar in forum C# Programming
    Replies: 0
    Last Post: 06-19-2006, 01:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21