예제 #1
0
void enumKeys(HKEY hkeyparent, LPCTSTR subkey) 
{
	//TCHAR    subname[MAX_KEY_LENGTH];   // buffer for subkey name
	int i = 0;
	HKEY hkey;
	DWORD psdsize = 1;
	REGSAM sam = KEY_READ | KEY_ENUMERATE_SUB_KEYS;
	//FILETIME ftLastWriteTime;      // last write time 

	LONG err = RegOpenKeyEx(hkeyparent, subkey, 0, sam, &hkey);

	if(err != 0 || hkey == 0)
		printf("ERROR in enumKeys()");

	QueryKey(hkey);

	/*
	do 
	{
	cbName = MAX_KEY_LENGTH;
	long result = RegEnumKeyEx(hkey, i, subname, &cbName, NULL, NULL, NULL, &ftLastWriteTime);

	if(result == ERROR_NO_MORE_ITEMS) 
	break;

	if(result == ERROR_SUCCESS)
	wprintf(L"ENUM==> name: %s\n", subname); 
	else
	printf("Error enumming\n");
	}
	while(++i > 0);
	*/
}
예제 #2
0
BOOL QueryUSBDeviceKeys
(
   PCHAR InstanceKey,
   PCHAR  DeviceFriendlyName,
   PCHAR  ControlFileName
)
{
   HKEY hTestKey;
   char fullKeyName[MAX_KEY_LENGTH];
   BOOL ret = FALSE;

   sprintf(fullKeyName, "%s\\%s", QCNET_REG_HW_KEY, InstanceKey);

   // printf("B-full key name: [%s]\n", fullKeyName);

   if (RegOpenKeyExA
       (
          HKEY_LOCAL_MACHINE,
          fullKeyName,
          0,
          KEY_READ,
          &hTestKey
       ) == ERROR_SUCCESS
      )
   {
      ret = QueryKey(hTestKey, DeviceFriendlyName, ControlFileName, fullKeyName);
      RegCloseKey(hTestKey);

      return ret;
   }

   return FALSE;
}  // QueryUSBDeviceKeys
예제 #3
0
파일: main.c 프로젝트: mundolivre/C
int main(int argc, char *argv[])
{
	HKEY hTestKey;
	int i, digit;

	if( RegOpenKeyEx( HKEY_USERS,
		//TEXT("Software\\Microsoft\\Internet Explorer\\Main"),
		0,
		0,
		KEY_READ,
		&hTestKey) == ERROR_SUCCESS
	)
	{
		QueryKey(hTestKey);
	} else {
		printf("Nao foi possivel ler\n");
	}

	RegCloseKey(hTestKey);

	// Coleta subkey escolhida
	scanf ("%d",&digit);
	digit--;
	for(i = 0; i<8; i++) {
		if(digit == i) {
			printf("Subkey escolhido : %s\n",listKeys[i].chosenKey);
			break;
		}
	}
	
	// Enumera as subkeys
	sprintf(subChave, listKeys[i].chosenKey);
	sprintf(subChave, "\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones");
	if( RegOpenKeyEx( HKEY_USERS, listKeys[i].chosenKey, 0,	KEY_WRITE, &hTestKey) == ERROR_SUCCESS
	)
	{
		// Grava o valor correto para a subChave selecionada	
		if(!RegSetKeyValueEx(HKEY_USERS, subChave, TEXT("SelfHealCount"), REG_DWORD, 00000001, 0)) {
			printf("Erro ao gravar SubChave %s\n", subChave);
		}
	} else {
		printf("Nao foi possivel abrir a subChave %s\n", subChave);
	}
	RegCloseKey(hTestKey);
	
	system("PAUSE");	

	return 0;
}
예제 #4
0
void CSerialPort::Hkey2ComboBox(CComboBox& m_PortNO)
{
    HKEY hTestKey;
    bool Flag = FALSE;

    ///仅是XP系统的注册表位置,其他系统根据实际情况做修改
    if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DEVICEMAP\\SERIALCOMM"), 0, KEY_READ, &hTestKey) ) {
        QueryKey(hTestKey);
    }
    RegCloseKey(hTestKey);

    int i = 0;
    m_PortNO.ResetContent();///刷新时,清空下拉列表内容
    while(i < MaxSerialPortNum && -1 != m_nComArray[i]) {
        CString szCom;
        szCom.Format(_T("COM%d"), m_nComArray[i]);
        m_PortNO.InsertString(i, szCom.GetBuffer(5));
        ++i;
        Flag = TRUE;
        if (Flag)///把第一个发现的串口设为下拉列表的默认值
            m_PortNO.SetCurSel(0);
    }

}
char * Get_Uninstallstr(char * regname,char * installer_name)

{

   HKEY hTestKey,tmp_subtestkey,subtestkey;

   char **List,**sub_List1;

   char *uninstall_str=(char *)malloc(500*sizeof(char));

   DWORD subkey_num,subkey_num1;

   if( RegOpenKeyEx( HKEY_LOCAL_MACHINE,

        TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData"),

        0,

        KEY_READ,

        &hTestKey) == ERROR_SUCCESS

      )

   {

      subkey_num = QueryKey(hTestKey, &List);

   }

   

   // search from the List

   int i,j;

   char *reg=(char *)malloc(500*sizeof(char));

   char *display_name=(char*)malloc(sizeof(char) * 1024);

   //TCHAR uninstall_str[500];

   DWORD dwSize = sizeof(char)*1024;

   DWORD dwtype = REG_EXPAND_SZ;



   for(i=0;i<subkey_num;i++)

   {

        memset(reg,0,500);

        //src ="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\";

        strcpy(reg,regname);

        strcat(reg,List[i]);

        strcat(reg,"\\Products");



        //printf("1. %s\n",reg );

        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT(reg),0,KEY_READ,&tmp_subtestkey)==ERROR_SUCCESS)

        {

            

            subkey_num1=QueryKey(tmp_subtestkey,&sub_List1);

            for (j=0;j<subkey_num1;j++)

            {

              char *reg1=(char *)malloc(500*sizeof(char));

              memset(reg1,0,500);

              strcpy(reg1,reg);

              strcat(reg1,"\\");

              strcat(reg1,sub_List1[j]);

              strcat(reg1,"\\InstallProperties");

              //printf("2. %s\t",reg1 );



              if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT(reg1),0,KEY_READ,&subtestkey)==ERROR_SUCCESS)

              {


                dwSize=1024;


                RegQueryValueEx(subtestkey,"DisplayName",NULL,NULL,(LPBYTE)display_name,&dwSize);

                //printf("\t%s\n",display_name);

                if(strstr(display_name,installer_name)!=NULL)

                {

                  printf("The regid is %s\n",reg1);

                  dwSize=1024;

                  RegQueryValueExA(subtestkey,_T("UninstallString"),NULL,&dwtype,(LPBYTE)uninstall_str,&dwSize);

                  printf("The uninstall_str is %s\n",uninstall_str);

                  break;

                }

                // else if(strstr(display_name,"Nsight Tegra") != NULL)

                // {

                //   dwSize=500;

                //   printf("Nsight Tegra's regid is %s\n",reg1);

                //   RegQueryValueEx(subtestkey,"UninstallString",NULL,NULL,(LPBYTE)uninstall_str,&dwSize);

                //   printf("NT uninstall_str is %s\n",uninstall_str);

                // }

                else

                {

                  continue;

                }

              }

             

            }

            if(j==subkey_num1)

            {

              char * err_str="cannot find";

              return err_str;

            }

        }

        return uninstall_str;

        

   }

    ListFree(&List);

    ListFree(&sub_List1);

    free(display_name);

    //free(uninstall_str);



   RegCloseKey(hTestKey);

   RegCloseKey(tmp_subtestkey);

   RegCloseKey(subtestkey);



}
예제 #6
0
MFX::MFXPluginsInHive::MFXPluginsInHive(int mfxStorageID, const msdk_disp_char *msdkLibSubKey, mfxVersion currentAPIVersion)
    : MFXPluginStorageBase(currentAPIVersion)
{
    HKEY rootHKey;
    bool bRes;
    WinRegKey regKey;

    if (MFX_LOCAL_MACHINE_KEY != mfxStorageID && MFX_CURRENT_USER_KEY != mfxStorageID)
        return;

    // open required registry key
    rootHKey = (MFX_LOCAL_MACHINE_KEY == mfxStorageID) ? (HKEY_LOCAL_MACHINE) : (HKEY_CURRENT_USER);
    if (msdkLibSubKey) {
        //dispatch/subkey/plugin
        bRes = regKey.Open(rootHKey, rootDispatchPath, KEY_READ);
        if (bRes)
        {
            bRes = regKey.Open(regKey, msdkLibSubKey, KEY_READ);
        }
        if (bRes)
        {
            bRes = regKey.Open(regKey, pluginSubkey, KEY_READ);
        }
    }
    else
    {
        bRes = regKey.Open(rootHKey, rootPluginPath, KEY_READ);
    }

    if (false == bRes) {
        return;
    }
    DWORD index = 0;
    if (!regKey.QueryInfo(&index)) {
        return;
    }
    try
    {
        resize(index);
    }
    catch (...) {
        TRACE_HIVE_ERROR("new PluginDescriptionRecord[%d] threw an exception: \n", index);
        return;
    }

    for(index = 0; ; index++)
    {
        wchar_t   subKeyName[MFX_MAX_REGISTRY_KEY_NAME];
        DWORD     subKeyNameSize = sizeof(subKeyName) / sizeof(subKeyName[0]);
        WinRegKey subKey;

        // query next value name
        bool enumRes = regKey.EnumKey(index, subKeyName, &subKeyNameSize);
        if (!enumRes) {
            break;
        }

        // open the sub key
        bRes = subKey.Open(regKey, subKeyName, KEY_READ);
        if (!bRes) {
            continue;
        }

        if (msdkLibSubKey)
        {
            TRACE_HIVE_INFO("Found Plugin: %s\\%S\\%S\\%S\\%S\n", (MFX_LOCAL_MACHINE_KEY == mfxStorageID) ? ("HKEY_LOCAL_MACHINE") : ("HKEY_CURRENT_USER"),
                rootDispatchPath, msdkLibSubKey, pluginSubkey, subKeyName);
        }
        else
        {
            TRACE_HIVE_INFO("Found Plugin: %s\\%S\\%S\n", (MFX_LOCAL_MACHINE_KEY == mfxStorageID) ? ("HKEY_LOCAL_MACHINE") : ("HKEY_CURRENT_USER"),
                rootPluginPath, subKeyName);
        }

        PluginDescriptionRecord descriptionRecord;

        if (!QueryKey(subKey, TypeKeyName, descriptionRecord.Type))
        {
            continue;
        }
        TRACE_HIVE_INFO(alignStr()" : %d\n", TypeKeyName, descriptionRecord.Type);

        if (QueryKey(subKey, CodecIDKeyName, descriptionRecord.CodecId))
        {
            TRACE_HIVE_INFO(alignStr()" : "MFXFOURCCTYPE()" \n", CodecIDKeyName, MFXU32TOFOURCC(descriptionRecord.CodecId));
        }
        else
        {
                TRACE_HIVE_INFO(alignStr()" : \n", CodecIDKeyName, "NOT REGISTERED");
        }

        if (!QueryKey(subKey, GUIDKeyName, descriptionRecord.PluginUID))
        {
            continue;
        }
        TRACE_HIVE_INFO(alignStr()" : "MFXGUIDTYPE()"\n", GUIDKeyName, MFXGUIDTOHEX(&descriptionRecord.PluginUID));

        mfxU32 nSize = sizeof(descriptionRecord.sPath)/sizeof(*descriptionRecord.sPath);
        if (!subKey.Query(PathKeyName, descriptionRecord.sPath, nSize))
        {
            TRACE_HIVE_WRN("no value for : %S\n", PathKeyName);
            continue;
        }
        TRACE_HIVE_INFO(alignStr()" : %S\n", PathKeyName, descriptionRecord.sPath);

        if (!QueryKey(subKey, DefaultKeyName, descriptionRecord.Default))
        {
            continue;
        }
        TRACE_HIVE_INFO(alignStr()" : %s\n", DefaultKeyName, descriptionRecord.Default ? "true" : "false");

        mfxU32 version;
        if (!QueryKey(subKey, PlgVerKeyName, version))
        {
            continue;
        }
        descriptionRecord.PluginVersion = static_cast<mfxU16>(version);
        if (0 == version)
        {
            TRACE_HIVE_ERROR(alignStr()" : %d, which is invalid\n", PlgVerKeyName, descriptionRecord.PluginVersion);
            continue;
        }
        else
        {
            TRACE_HIVE_INFO(alignStr()" : %d\n", PlgVerKeyName, descriptionRecord.PluginVersion);
        }

        mfxU32 APIVersion;
        if (!QueryKey(subKey, APIVerKeyName, APIVersion))
        {
            continue;
        }
        ConvertAPIVersion(APIVersion, descriptionRecord);
        TRACE_HIVE_INFO(alignStr()" : %d.%d \n", APIVerKeyName, descriptionRecord.APIVersion.Major, descriptionRecord.APIVersion.Minor);

        try
        {
            operator[](index) = descriptionRecord;
        }
        catch (...) {
            TRACE_HIVE_ERROR("operator[](%d) = descriptionRecord; - threw exception \n", index);
        }
    }
}
예제 #7
0
int LoadConfig() {
	HKEY myKey;
	DWORD type, size, tmp;
	PcsxConfig *Conf = &Config;
	int err;
#ifdef ENABLE_NLS
	char text[256];
#endif

	if (RegOpenKeyEx(HKEY_CURRENT_USER,cfgfile,0,KEY_ALL_ACCESS,&myKey)!=ERROR_SUCCESS) return -1;

	err = 1;
	QueryKey(256, "Bios", Conf->Bios);
	QueryKey(256, "Gpu",  Conf->Gpu);
	QueryKey(256, "Spu",  Conf->Spu);
	QueryKey(256, "Cdr",  Conf->Cdr);
	QueryKey(256, "Pad1", Conf->Pad1);
	QueryKey(256, "Pad2", Conf->Pad2);
#ifdef ENABLE_SIO1API
	QueryKey(256, "Sio1", Conf->Sio1);
#endif
	QueryKey(256, "Mcd1", Conf->Mcd1);
	QueryKey(256, "Mcd2", Conf->Mcd2);
	QueryKey(256, "PluginsDir", Conf->PluginsDir);
	QueryKey(256, "BiosDir",    Conf->BiosDir);
	err = 0;
	QueryKey(256, "Net",  Conf->Net);
	QueryKey(256, "Lang", Conf->Lang);

	QueryKeyV("Xa",       Conf->Xa);
	QueryKeyV("SioIrq",   Conf->SioIrq);
	QueryKeyV("Mdec",     Conf->Mdec);
	QueryKeyV("PsxAuto",  Conf->PsxAuto);
	QueryKeyV("Cdda",     Conf->Cdda);
	QueryKeyV("SlowBoot", Conf->SlowBoot);
	QueryKeyV("Debug",    Conf->Debug);
	QueryKeyV("PsxOut",   Conf->PsxOut);
	QueryKeyV("SpuIrq",   Conf->SpuIrq);
	QueryKeyV("RCntFix",  Conf->RCntFix);
	QueryKeyV("VSyncWA",  Conf->VSyncWA);
	QueryKeyV("Widescreen",  Conf->Widescreen);
	QueryKeyV("HideCursor",  Conf->HideCursor);
	QueryKeyV("SaveWindowPos",  Conf->SaveWindowPos);
	QueryKeyV("PerGameMcd", Conf->PerGameMcd);
	QueryKeyV("WindowPosX",  Conf->WindowPos[0]);
	QueryKeyV("WindowPosY",  Conf->WindowPos[1]);
	QueryKeyV("HackFix", Conf->HackFix);
	QueryKeyV("MemHack", Conf->MemHack);

	QueryKeyV("OverClock", Conf->OverClock);

	QueryKeyV("Cpu",      Conf->Cpu);
	QueryKeyV("PsxType",  Conf->PsxType);
	QueryKeyV("PsxClock", Conf->PsxClock);

	if (Config.Cpu == CPU_DYNAREC) {
		Config.Debug = 0; // don't enable debugger if using dynarec core
	}

	RegCloseKey(myKey);

#ifdef ENABLE_NLS
	sprintf(text, "LANGUAGE=%s", Conf->Lang);
	gettext_putenv(text);
#endif

	return 0;
}