标题:
c++builder 写的查询用户信息
[打印本页]
作者:
kkting
时间:
2005-2-1 13:45
标题:
c++builder 写的查询用户信息
//--------------------------------------------------------------------------- #include
#pragma hdrstop #include "MainReg.h" #include "UserInfo.h" #include
//--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::ExitButtonClick(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TForm1::QueryButtonClick(TObject *Sender) { LPCTSTR data_Set = "software\\Microsoft\\Ms Setup(ACME)\\User Info\\"; Memo1->Lines->Clear(); if (RadioButton1->Checked==true) { char username_Get[MAX_COMPUTERNAME_LENGTH+1]; char company_Get[MAX_COMPUTERNAME_LENGTH+1]; HKEY hKEY; long ret0 = ::RegOpenKeyEx(HKEY_CURRENT_USER, data_Set, 0, KEY_READ, &hKEY); if (ret0 != ERROR_SUCCESS) { ShowMessage("´íÎó£ºÎÞ·¨´ò¿ªÏà¹ØµÄhKEY!"); return; } DWORD type_1 = REG_SZ; DWORD cbData_1 = 40; long ret1 = ::RegQueryValueEx( hKEY, "DefName", NULL, &type_1, username_Get, &cbData_1); if (ret1 != ERROR_SUCCESS){ ShowMessage("´íÎó£ºÎÞ·¨´ò¿ªÓйØ×¢²áÐÅÏ¢£¡"); return; } DWORD type_2 = REG_SZ; DWORD cbData_2 = 40; long ret2 = ::RegQueryValueEx( hKEY, "DefCompany", NULL, &type_2, company_Get, &cbData_2); if (ret2 != ERROR_SUCCESS){ ShowMessage("´íÎó£ºÎÞ·¨¼ì²éÓйØ×¢²á±íÐÅÏ¢£¡"); return; } ::RegCloseKey(hKEY); Memo1->Lines->Add("ʹÓÃapiº¯Êý¶Á³É¹¦£¡"); Memo1->Lines->Add("Óû§Ãû£º"+AnsiString(username_Get)); Memo1->Lines->Add("¹«Ë¾Ãû£º"+AnsiString(company_Get)); } else if (RadioButton2->Checked==true) { TRegistry *Registry = new TRegistry; AnsiString username; AnsiString company; try { Registry->RootKey = HKEY_CURRENT_USER; Registry->OpenKey(data_Set,false); username = "Óû§Ãû£º"+Registry->ReadString("DefName"); company = "¹«Ë¾Ãû£º"+Registry->ReadString("DefCompany"); } __finally { delete Registry; } Memo1->Lines->Add("ʹÓÃTRegistryÀà¶Á³É¹¦£¡"); Memo1->Lines->Add(AnsiString(username)); Memo1->Lines->Add(AnsiString(company)); } } //--------------------------------------------------------------------------- void __fastcall TForm1::ModifyButtonClick(TObject *Sender) { int i; if (UserInfoForm->ShowModal()==IDOK){ Memo1->Lines->Clear(); AnsiString str_username = UserInfoForm->UserNameEdit->Text; AnsiString str_company = UserInfoForm->CompanyEdit->Text; HKEY hKEY; LPCTSTR data_Set = "Software\\Microsoft\\Ms Setup (ACME)\\User Info\\"; if (RadioButton1->Checked==true) { long ret0 = ::RegOpenKeyEx(HKEY_CURRENT_USER, data_Set, 0, KEY_WRITE, &hKEY); if (ret0 != ERROR_SUCCESS) { ShowMessage("´íÎó£ºÎÞ·¨´ò¿ªÏà¹ØµÄhKEY!"); return; } //ÐÞ¸ÄÓû§ÐÕÃû char *username_Set; username_Set=str_username.c_str(); DWORD type_1 = REG_SZ; DWORD cbData_1 = str_username.Length()+1; long ret1 = ::RegSetValueEx( hKEY, "DefName", NULL, type_1, username_Set, cbData_1); if (ret1 != ERROR_SUCCESS){ ShowMessage("´íÎó£ºÎÞ·¨ÐÞ¸ÄÓû§ÐÕÃû£¡"); return; } //Ð޸Ĺ«Ë¾Ãû³Æ char *company_Set; company_Set = str_company.c_str(); DWORD type_2 = REG_SZ; DWORD cbData_2 = str_company.Length() + 1; long ret2 = ::RegSetValueEx(hKEY, //ÒÑ´ò¿ªµÄ¼üµÄ¾ä±ú "DefCompany", //ÒªÐ޸ĵļüÃû NULL, type_2, company_Set, //ÐÂÊý¾ÝµÄ cbData_2); //ÐÂÖµµÄÊý¾Ý³¤¶È if (ret2!=ERROR_SUCCESS) { //ÈôÎÞ·¨Ð޸ģ¬ÔòÖÕÖ¹³ÌÐòÔËÐÐ] ShowMessage("´íÎó£ºÎÞ·¨Ð޸Ĺ«Ë¾Ãû³Æ"); return; } Memo1->Lines->Add("ʹÓÃAPIº¯Êý×¢²á±íÓû§ÐÅÏ¢Ð޸ijɹ¦£¡"); } else if (RadioButton2->Checked==true) { TRegistry *Registry = new TRegistry; AnsiString username; AnsiString company; try { Registry->RootKey = HKEY_CURRENT_USER; Registry->OpenKey(data_Set,false); Registry->WriteString("DefName",str_username); Registry->WriteString("DefCompany",str_company); } __finally { delete Registry; } Memo1->Lines->Add("ʹÓÃTRegistryÀà×¢²á±íÓû§ÐÅÏ¢Ð޸ijɹ¦£¡"); } } } //--------------------------------------------------------------------------- 上面全是mainreg.cpp的内容,相关的组件要自己加上去!
作者:
kkting
时间:
2005-2-1 13:48
标题:
c++builder 写的查询用户信息
自己现在在学 c++builder ,写的不对的,请高手指出来,我会改正的!
编译器用的是 BORLAND 公司的 c++BUILDER 5.0
欢迎光临 黑色海岸线论坛 (http://bbs.thysea.com/)
Powered by Discuz! 7.2