Registry Edit to change NIC Speed

Attempting to change NIC speed through Registry

Page 1 of 1

5 Replies - 2575 Views - Last Post: 09 December 2009 - 02:05 PM Rate Topic: -----

#1 mcamardo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 29-June 08

Registry Edit to change NIC Speed

Posted 25 November 2009 - 10:58 AM

I am trying to change the NIC speed through the registry.. But my problem is that I dont fully understand the command RegSetValueEx. I have checked the Internet up and down for some good examples but have fallen short.. Here is what I have..

LPTSTR lptstrRegSubKey;
LPCTSTR Caption2 = "Speed Change Successfull!";
HKEY hKey;

if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\*SpeedDuplex\\enum", 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS)
{
	lptstrRegSubKey = "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\*SpeedDuplex\\default";
	RegCloseKey (hKey);
}

if (RegSetValueEx(HKEY_LOCAL_MACHINE, lptstrRegSubKey, 0, REG_DWORD,   (PBYTE) 0, sizeof(0))==ERROR_SUCCESS)
{
	 MessageBox(NULL, "NIC Speed was changed to Auto..", Caption2,MB_OK);
}



Is This A Good Question/Topic? 0
  • +

Replies To: Registry Edit to change NIC Speed

#2 mcamardo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 29-June 08

Re: Registry Edit to change NIC Speed

Posted 01 December 2009 - 07:59 AM

Is anyone able to assist with this..

I have updated the code..

/* <-- Libraries, Headers and Declarations Section --> */
#include <windows.h>
#include <string>
#include "resource.h"

using namespace std;

HWND gHWndDlg;

#define GETITEM(item) GetDlgItem(gHWndDlg, item)

/* <-- Declare Function Section --> */
void ChangeNIC2Auto();
void ChangeNIC210Full();
void ChangeNIC2100Full();
void ChangeNIC21GBPSFull();
void DetermineSubKey();

LPCTSTR Caption = "Help";
LPCTSTR Caption2 = "Speed Change Successfull!";

/* <-- Global Variables Section --> */
HKEY hKey;
LPTSTR lptstrRegSubKey;
LPCTSTR lptstrSpeed;

/* <-- Dialog Proceedure --> */
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
 switch(Msg)
 {
  case WM_INITDIALOG:
	// Initiate what loads when the application starts
	gHWndDlg = hWndDlg;
	DetermineSubKey();
  return TRUE;
  
  case WM_COMMAND:
	switch(LOWORD(wParam))
	{
	  case IDC_AUTO:
				ChangeNIC2Auto();
	  return TRUE;

		case IDC_10FULL:
			ChangeNIC210Full();
		return TRUE;

		case IDC_100FULL:
			ChangeNIC2100Full();
		return TRUE;

		case IDC_1GBPSFULL:
			ChangeNIC21GBPSFull();
		return TRUE;

	  case IDM_ABOUT:
			MessageBox(NULL, "This NIC Speed Changer application was created by Michael S. Camardo. Assistance by Nick McFadden", Caption,MB_OK);
	  return TRUE;
		
	  case WM_DESTROY: // command for the close option at top right of screen
			EndDialog(gHWndDlg, 0); 
	  break;

	  case IDM_FILE_EXIT:
			 EndDialog(gHWndDlg, 0); 
	  break;
	}
	break;
  }
  return FALSE; 
}

/* <-- Functions Section --> */

// Change NIC speed to Auto
void ChangeNIC2Auto()
{  
   lptstrSpeed= "0";
   if (RegSetValueEx(HKEY_LOCAL_MACHINE, lptstrRegSubKey, 0, REG_SZ, (LPBYTE) lptstrSpeed, strlen(lptstrSpeed)+1) == ERROR_SUCCESS)
   {
	 RegCloseKey (hKey);
	 MessageBox(NULL, "NIC Speed was changed to Auto..", Caption2,MB_OK);
   }
}

// Change NIC speed to 10Full
void ChangeNIC210Full()
{
  lptstrSpeed= "4";
   if (RegSetValueEx(HKEY_LOCAL_MACHINE, lptstrRegSubKey, 0, REG_SZ, (LPBYTE) lptstrSpeed, strlen(lptstrSpeed)+1) == ERROR_SUCCESS)
   {
	 RegCloseKey (hKey);
	 MessageBox(NULL, "NIC Speed was changed to 10Full..", Caption2,MB_OK);
   }
}

// CHange NIC speed to 100Full
void ChangeNIC2100Full()
{
  
}

// Change NIC speed to 1GBPSFull
void ChangeNIC21GBPSFull()
{
  
}

// Determines Registry SubKey and saves it to variable LPTSTR lptstrRegSubKey
void DetermineSubKey()
{ 
 // HP D530
  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\RequestedMediaType"), 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS)
  {
	lptstrRegSubKey = TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\RequestedMediaType");
  }
  
  // HP DC7100
  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\RequestedMediaType"), 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS)
  {
	lptstrRegSubKey = TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\RequestedMediaType");
  }
  
  // Dell GX520
  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\RequestedMediaType"), 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS)
  {
	lptstrRegSubKey = TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\RequestedMediaType");
  }
  
  // Dell GX620
  if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\RequestedMediaType"), 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS)
  {
	lptstrRegSubKey = TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\RequestedMediaType");
  }
  
  // HP DC7800
  if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\SpeedDuplex"), 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS)
  {
	lptstrRegSubKey = TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\SpeedDuplex");
  }

  // HP DC7900
  if(RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\*SpeedDuplex"), &hKey) == ERROR_SUCCESS)
  {
	lptstrRegSubKey = TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\*SpeedDuplex");
	MessageBox(NULL, "NIC Driver Found..", Caption2,MB_OK);
  }
}

/* <-- WinMain Section --> */
int APIENTRY WinMain (HINSTANCE hInst, HINSTANCE unused, LPSTR cmdLine, int cmdShow)
{
 DialogBox(hInst, MAKEINTRESOURCE(IDD_CONTROLS_DLG), 0, (DLGPROC)(DlgProc));
 return 0;
}



This post has been edited by mcamardo: 01 December 2009 - 08:06 AM

Was This Post Helpful? 0
  • +
  • -

#3 mcamardo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 29-June 08

Re: Registry Edit to change NIC Speed

Posted 09 December 2009 - 06:56 AM

I figured it out on my own... Thanks for no help at all.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6081
  • View blog
  • Posts: 23,557
  • Joined: 23-August 08

Re: Registry Edit to change NIC Speed

Posted 09 December 2009 - 07:23 AM

I have a snippet here, but snippets aren't all that easy to find on here, unfortunately. It doesn't do exactly what you want, but it demonstrates the RegSetValueEx function.
Was This Post Helpful? 0
  • +
  • -

#5 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Registry Edit to change NIC Speed

Posted 09 December 2009 - 07:45 AM

I am sorry that no one was able to help but this really was not an area that I felt qualified to comment on. I have never actually changed a registry value from C/C++ before, and those times I did from VB (way way way back) were just for local program configuration.

I didn't really want to make an example program because messing around with the registry is NOT something anyone should ever do when they don't know specifically what they are doing. -- And since programs don't necessarily monitor live the registry values, any changes generally require a reboot of the system to take affect -- so I was not even sure that you COULD actually change the NIC card speed in the registry and have it do anything...

So I just wanted to point out that sometimes we don't help because we don't know or don't feel comfortable with our knowledge level on the subject.
Was This Post Helpful? 0
  • +
  • -

#6 mcamardo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 29-June 08

Re: Registry Edit to change NIC Speed

Posted 09 December 2009 - 02:05 PM

Here is what I have and it works, you just need to reboot for it to change the speed...

/* <-- Libraries, Headers and Declarations Section --> */
#include <windows.h>
#include <string>
#include "resource.h"

using namespace std;

HWND gHWndDlg;

#define GETITEM(item) GetDlgItem(gHWndDlg, item)

/* <-- Declare Function Section --> */
void ChangeNIC2Auto();
void ChangeNIC210Full();
void DetermineSubKey();
void ResetRegistry();

LPCTSTR Caption = "Help";
LPCTSTR Caption2 = "Speed Change Successfull!";
LPCTSTR Caption3 = "Error";

/* <-- Global Variables Section --> */
HKEY hKey, hKey2;
LPCTSTR strRegSubKey;
LPTSTR SetSpeed;

/* <-- Dialog Proceedure --> */
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
 switch(Msg)
 {
  case WM_INITDIALOG:
	// Initiate what loads when the application starts
	gHWndDlg = hWndDlg;
	DetermineSubKey();
  return TRUE;
  
  case WM_COMMAND:
	switch(LOWORD(wParam))
	{
	  case IDC_AUTO:
				ChangeNIC2Auto();
			ResetRegistry();
	  return TRUE;

		case IDC_10FULL:
			ChangeNIC210Full();
			ResetRegistry();
		return TRUE;

	  case IDM_ABOUT:
			MessageBox(NULL, "This NIC Speed Changer application was created by Michael S. Camardo.", Caption,MB_OK);
	  return TRUE;
		
	  case WM_DESTROY: // command for the close option at top right of screen
			EndDialog(gHWndDlg, 0); 
	  break;

	  case IDM_FILE_EXIT:
			 EndDialog(gHWndDlg, 0); 
	  break;
	}
	break;
  }
  return FALSE; 
}

/* <-- Functions Section --> */

// Change NIC speed to Auto
void ChangeNIC2Auto()
{  
   SetSpeed= "0";
   RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001", 0, KEY_SET_VALUE, &hKey);
   if (RegSetValueEx(hKey, strRegSubKey, 0, REG_SZ, (LPBYTE) SetSpeed, strlen(SetSpeed)+1) == ERROR_SUCCESS)
   {
	 RegCloseKey (hKey);
	 MessageBox(NULL, "NIC Speed was changed to Auto..", Caption2,MB_OK);
   }
}

// Change NIC speed to 10Full
void ChangeNIC210Full()
{
  SetSpeed= "4";
  RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001", 0, KEY_SET_VALUE, &hKey);
  if (RegSetValueEx(hKey, strRegSubKey, 0, REG_SZ, (LPBYTE) SetSpeed, strlen(SetSpeed)+1) == ERROR_SUCCESS)
  {
	RegCloseKey (hKey);
	MessageBox(NULL, "NIC Speed was changed to 10Full..", Caption2,MB_OK);
  }
}

// Determines Registry SubKey and saves it to variable LPTSTR lptstrRegSubKey
void DetermineSubKey()
{ 
  if (RegOpenKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\RequestedMediaType", &hKey2) == ERROR_SUCCESS)
  { 
	RegCloseKey(hKey2);
	strRegSubKey = "RequestedMediaType"; // RegSubKey for HP D530, DC7100, Dell GX520 and GX620
	MessageBox(NULL, "This is a HP D530, DC7100, Dell GX520 or GX620.", Caption2,MB_OK); 
  }
  
  if (RegOpenKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\SpeedDuplex", &hKey2) == ERROR_SUCCESS)
  {
	RegCloseKey(hKey2);
	strRegSubKey = "SpeedDuplex"; // RegSubKey for HP DC7800
	MessageBox(NULL, "This is a HP DC7800.", Caption2,MB_OK);
  }

  if (RegOpenKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}\\0001\\Ndi\\Params\\*SpeedDuplex", &hKey2) == ERROR_SUCCESS)
  {
	RegCloseKey(hKey2);
	strRegSubKey = "*SpeedDuplex"; // RegSubKey for HP 7900
	MessageBox(NULL, "This is a HP 7900.", Caption2,MB_OK);
  } 
} 

void ResetRegistry()
{
 // Current work in progress to refresh registry without reboot... 
 DWORD dwReturnValue;
 SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) "Environment", SMTO_ABORTIFHUNG, 5000, &dwReturnValue);
 if (dwReturnValue = 0)
 {
   MessageBox(NULL, "Registry was not updated..", Caption3,MB_OK);
 }
}
/* <-- WinMain Section --> */
int APIENTRY WinMain (HINSTANCE hInst, HINSTANCE unused, LPSTR cmdLine, int cmdShow)
{
 DialogBox(hInst, MAKEINTRESOURCE(IDD_CONTROLS_DLG), 0, (DLGPROC)(DlgProc));
 return 0;
}



If anyone has an idea how to refresh the registry without rebooting it would be great. I have tried killing explorer.exe process using the system function, and as you can see in the current code the SendMessageTimeout function..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1