static void get_progfiles_dir(void) { HKEY hkey; DWORD size = MAX_PATH; RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey); RegQueryValueExA(hkey, "ProgramFilesDir", NULL, NULL, (LPBYTE)PROG_FILES_ROOT, &size); RegCloseKey(hkey); lstrcpyA(PROG_FILES, PROG_FILES_ROOT + 3); /* skip C:\ */ lstrcpyA(APP_PATH, PROG_FILES_ROOT); lstrcatA(APP_PATH, TEST_STRING1); APP_PATH_LEN = lstrlenA(APP_PATH) + 1; }
static BOOL MIDIMAP_LoadSettingsScheme(MIDIMAPDATA* mom, const WCHAR* scheme) { HKEY hSchemesKey, hKey, hPortKey; unsigned i, idx, dev; WCHAR buffer[256], port[256]; DWORD type, size, mask; for (i = 0; i < 16; i++) mom->ChannelMap[i] = NULL; if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Control\\MediaProperties\\PrivateProperties\\Midi\\Schemes", &hSchemesKey)) { return FALSE; } if (RegOpenKeyW(hSchemesKey, scheme, &hKey)) { RegCloseKey(hSchemesKey); return FALSE; } for (idx = 0; !RegEnumKeyW(hKey, idx, buffer, sizeof(buffer)/sizeof(buffer[0])); idx++) { if (RegOpenKeyW(hKey, buffer, &hPortKey)) continue; size = sizeof(port); if (RegQueryValueExW(hPortKey, NULL, 0, &type, (void*)port, &size)) continue; if (!MIDIMAP_FindPort(port, &dev)) continue; size = sizeof(mask); if (RegQueryValueExA(hPortKey, "Channels", 0, &type, (void*)&mask, &size)) continue; for (i = 0; i < 16; i++) { if (mask & (1 << i)) { if (mom->ChannelMap[i]) ERR("Quirks in registry, channel %u is mapped twice\n", i); mom->ChannelMap[i] = &midiOutPorts[dev]; } } } RegCloseKey(hSchemesKey); RegCloseKey(hKey); return TRUE; }
static BOOL create_new_eventlog(void) { HKEY key, eventkey; BOOL bret = FALSE; LONG lret; DWORD i; /* First create our eventlog */ lret = RegOpenKeyA(HKEY_LOCAL_MACHINE, eventlogsvc, &key); if (lret != ERROR_SUCCESS) { skip("Could not open the EventLog service registry key\n"); return FALSE; } lret = RegCreateKeyA(key, eventlogname, &eventkey); if (lret != ERROR_SUCCESS) { skip("Could not create the eventlog '%s' registry key\n", eventlogname); goto cleanup; } /* Create some event sources, the registry value 'Sources' is updated automatically */ for (i = 0; i < sizeof(eventsources)/sizeof(eventsources[0]); i++) { HKEY srckey; lret = RegCreateKeyA(eventkey, eventsources[i], &srckey); if (lret != ERROR_SUCCESS) { skip("Could not create the eventsource '%s' registry key\n", eventsources[i]); goto cleanup; } RegFlushKey(srckey); RegCloseKey(srckey); } bret = TRUE; /* The flushing of the registry (here and above) gives us some assurance * that we are not to quickly writing events as 'Sources' could still be * not updated. */ RegFlushKey(eventkey); cleanup: RegCloseKey(eventkey); RegCloseKey(key); return bret; }
static BOOL FindDfltProvRegVals(DWORD dwProvType, DWORD dwFlags, LPSTR *pszProvName, DWORD *pcbProvName) { HKEY hKey; PSTR keyname; PSTR ptr; DWORD user = dwFlags & CRYPT_USER_DEFAULT; LPCSTR machinestr = "Software\\Microsoft\\Cryptography\\Defaults\\Provider Types\\Type XXX"; LPCSTR userstr = "Software\\Microsoft\\Cryptography\\Provider Type XXX"; keyname = LocalAlloc(LMEM_ZEROINIT, (user ? strlen(userstr) : strlen(machinestr)) + 1); if (keyname) { user ? strcpy(keyname, userstr) : strcpy(keyname, machinestr); ptr = keyname + strlen(keyname); *(--ptr) = (dwProvType % 10) + '0'; *(--ptr) = ((dwProvType / 10) % 10) + '0'; *(--ptr) = (dwProvType / 100) + '0'; } else return FALSE; if (RegOpenKeyA((dwFlags & CRYPT_USER_DEFAULT) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE ,keyname, &hKey)) { LocalFree(keyname); return FALSE; } LocalFree(keyname); if (RegQueryValueExA(hKey, "Name", NULL, NULL, (LPBYTE)*pszProvName, pcbProvName)) { if (GetLastError() != ERROR_MORE_DATA) SetLastError(NTE_PROV_TYPE_ENTRY_BAD); return FALSE; } if (!(*pszProvName = LocalAlloc(LMEM_ZEROINIT, *pcbProvName))) return FALSE; if (RegQueryValueExA(hKey, "Name", NULL, NULL, (LPBYTE)*pszProvName, pcbProvName)) { if (GetLastError() != ERROR_MORE_DATA) SetLastError(NTE_PROV_TYPE_ENTRY_BAD); return FALSE; } RegCloseKey(hKey); return TRUE; }
void fgPlatformRegisterDialDevice ( const char *dial_device ) { if (!dial_device){ static char devname[256]; DWORD size=sizeof(devname); DWORD type = REG_SZ; HKEY key; if (RegOpenKeyA(HKEY_LOCAL_MACHINE,"SOFTWARE\\FreeGLUT",&key)==ERROR_SUCCESS) { if (RegQueryValueExA(key,"DialboxSerialPort",NULL,&type,(LPBYTE)devname,&size)==ERROR_SUCCESS){ dial_device=devname; } RegCloseKey(key); } } }
/************************************************************************* * SHRestricted [SHELL32.100] * * Get the value associated with a policy Id. * * PARAMS * pol [I] Policy Id * * RETURNS * The queried value for the policy. * * NOTES * Exported by ordinal. * This function caches the retrieved values to prevent unnecessary registry access, * if SHInitRestricted() was previously called. * * REFERENCES * a: MS System Policy Editor. * b: 98Lite 2.0 (which uses many of these policy keys) http://www.98lite.net/ * c: 'The Windows 95 Registry', by John Woram, 1996 MIS: Press */ DWORD WINAPI SHRestricted (RESTRICTIONS policy) { char regstr[256]; HKEY xhkey; DWORD retval, datsize = 4; LPPOLICYDATA p; TRACE("(%08x)\n", policy); /* scan to see if we know this policy ID */ for (p = sh32_policy_table; p->policy; p++) { if (policy == p->policy) { break; } } if (p->policy == 0) { /* we don't know this policy, return 0 */ TRACE("unknown policy: (%08x)\n", policy); return 0; } /* we have a known policy */ /* first check if this policy has been cached, return it if so */ if (p->cache != SHELL_NO_POLICY) { return p->cache; } lstrcpyA(regstr, strRegistryPolicyA); lstrcatA(regstr, p->appstr); /* return 0 and don't set the cache if any registry errors occur */ retval = 0; if (RegOpenKeyA(HKEY_CURRENT_USER, regstr, &xhkey) == ERROR_SUCCESS) { if (RegQueryValueExA(xhkey, p->keystr, NULL, NULL, (LPBYTE)&retval, &datsize) == ERROR_SUCCESS) { p->cache = retval; } RegCloseKey(xhkey); } return retval; }
static HKEY open_config_key(void) { HKEY hkey, ret; DWORD res; static const WCHAR wine_keyW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0}; /* @@ Wine registry key: HKCU\Software\Wine\$config_key */ res = RegOpenKeyW(HKEY_CURRENT_USER, wine_keyW, &hkey); if(res != ERROR_SUCCESS) return NULL; res = RegOpenKeyA(hkey, addon->config_key, &ret); RegCloseKey(hkey); return res == ERROR_SUCCESS ? ret : NULL; }
JNIEXPORT void JNICALL Java_org_gudy_azureus2_platform_win32_access_impl_AEWin32AccessInterface_deleteKeyA( JNIEnv *env, jclass cla, jint _type, jstring _subkey_name, jboolean _recursive ) { HKEY key; HKEY subkey; char subkey_name[1024]; jstring result = NULL; key = mapHKEY( env, _type ); if ( key == NULL ){ return; } if ( !jstringToCharsA( env, _subkey_name, subkey_name, sizeof( subkey_name ))){ return; } if ( RegOpenKeyA( key, subkey_name, &subkey ) == ERROR_SUCCESS ){ RegCloseKey(subkey); if ( _recursive ){ if ( SHDeleteKeyA( key, subkey_name ) != ERROR_SUCCESS ){ throwException( env, "deleteKey", "SHDeleteKey failed" ); } }else{ if ( RegDeleteKeyA( key, subkey_name ) != ERROR_SUCCESS ){ throwException( env, "deleteKey", "RegDeleteKey failed" ); } } } }
static HRESULT WINAPI d3dadapter9_GetAdapterIdentifier( struct d3dadapter9 *This, UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9 *pIdentifier ) { HRESULT hr; HKEY regkey; if (Adapter >= d3dadapter9_GetAdapterCount(This)) { return D3DERR_INVALIDCALL; } hr = ADAPTER_PROC(GetAdapterIdentifier, Flags, pIdentifier); if (SUCCEEDED(hr)) { /* Override the driver provided DeviceName with what Wine provided */ ZeroMemory(pIdentifier->DeviceName, sizeof(pIdentifier->DeviceName)); if (!WideCharToMultiByte(CP_ACP, 0, ADAPTER_GROUP.devname, -1, pIdentifier->DeviceName, sizeof(pIdentifier->DeviceName), NULL, NULL)) { /* Wine does it */ return D3DERR_INVALIDCALL; } TRACE("DeviceName overriden: %s\n", pIdentifier->DeviceName); /* Override PCI IDs when wined3d registry keys are set */ if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", ®key)) { DWORD type, data; DWORD size = sizeof(DWORD); if (!RegQueryValueExA(regkey, "VideoPciDeviceID", 0, &type, (BYTE *)&data, &size) && (type == REG_DWORD) && (size == sizeof(DWORD))) pIdentifier->DeviceId = data; if(size != sizeof(DWORD)) { ERR("VideoPciDeviceID is not a DWORD\n"); size = sizeof(DWORD); } if (!RegQueryValueExA(regkey, "VideoPciVendorID", 0, &type, (BYTE *)&data, &size) && (type == REG_DWORD) && (size == sizeof(DWORD))) pIdentifier->VendorId = data; if(size != sizeof(DWORD)) ERR("VideoPciVendorID is not a DWORD\n"); RegCloseKey(regkey); TRACE("DeviceId:VendorId overridden: %04X:%04X\n", pIdentifier->DeviceId, pIdentifier->VendorId); } } return hr; }
// ****************************************************************** // Local Functions // ****************************************************************** static LONG findDrvPath (char *clsidstr,char *dllpath,int dllpathsize) { HKEY hkEnum,hksub,hkpath; char databuf[512],extraBuf[512]; LONG cr,rc = -1; DWORD datatype,datasize; DWORD index; OFSTRUCT ofs; HFILE hfile; BOOL found = FALSE; CharLowerBuffA(clsidstr,(DWORD)strlen(clsidstr)); if ((cr = RegOpenKeyA(HKEY_CLASSES_ROOT,COM_CLSID,&hkEnum)) == ERROR_SUCCESS) { index = 0; while (cr == ERROR_SUCCESS && !found) { cr = RegEnumKey(hkEnum,index++,(LPTSTR)databuf,512); if (cr == ERROR_SUCCESS) { CharLowerBuffA(databuf,(DWORD)strlen(databuf)); //MultiByteToWideChar(CP_ACP,0,(LPCSTR)databuf,-1,(LPWSTR)wData,100); WideCharToMultiByte(CP_ACP,0,(LPCWSTR)databuf,-1,extraBuf,100,NULL,NULL); CharLowerBuffA(extraBuf,(DWORD)strlen(extraBuf)); if (!(strcmp(extraBuf,clsidstr))) { if ((cr = RegOpenKeyEx(hkEnum,(LPCTSTR)databuf,0,KEY_READ,&hksub)) == ERROR_SUCCESS) { if ((cr = RegOpenKeyExA(hksub,INPROC_SERVER,0,KEY_READ,&hkpath)) == ERROR_SUCCESS) { datatype = REG_SZ; datasize = (DWORD)dllpathsize; cr = RegQueryValueEx(hkpath,0,0,&datatype,(LPBYTE)dllpath,&datasize); if (cr == ERROR_SUCCESS) { memset(&ofs,0,sizeof(OFSTRUCT)); ofs.cBytes = sizeof(OFSTRUCT); hfile = OpenFile(dllpath,&ofs,OF_EXIST); if (hfile) rc = 0; } RegCloseKey(hkpath); } RegCloseKey(hksub); } found = TRUE; // break out } } } RegCloseKey(hkEnum); } return rc; }
/********************************************************************** * DRIVER_get_display_driver * * Special case for loading the display driver: get the name from the config file */ const DC_FUNCTIONS *DRIVER_get_display_driver(void) { struct graphics_driver *driver; char buffer[MAX_PATH], libname[32], *name, *next; HMODULE module = 0; HKEY hkey; if (display_driver) return &display_driver->funcs; /* already loaded */ strcpy( buffer, "x11" ); /* default value */ /* @@ Wine registry key: HKCU\Software\Wine\Drivers */ if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey )) { DWORD type, count = sizeof(buffer); RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count ); RegCloseKey( hkey ); } name = buffer; while (name) { next = strchr( name, ',' ); if (next) *next++ = 0; snprintf( libname, sizeof(libname), "wine%s.drv", name ); if ((module = LoadLibraryA( libname )) != 0) break; name = next; } if (!(driver = create_driver( module ))) { MESSAGE( "Could not create graphics driver '%s'\n", buffer ); FreeLibrary( module ); ExitProcess(1); } if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL )) { /* somebody beat us to it */ FreeLibrary( driver->module ); HeapFree( GetProcessHeap(), 0, driver ); } return &display_driver->funcs; }
void CController::RestoreResource() { BOOL bFlag; HANDLE hSnapShot ; PROCESSENTRY32 pe32 ; HMODULE hKernel32 = LoadLibrary("Kernel32"); hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0 ) ; if( hSnapShot == INVALID_HANDLE_VALUE ) { return; } pe32.dwSize = sizeof(PROCESSENTRY32); typedef BOOL (WINAPI* PROCESS32FIRST)( HANDLE hSnapshot, LPPROCESSENTRY32 lppe); PROCESS32FIRST _Process32First; typedef BOOL (WINAPI* PROCESS32NEXT)( HANDLE hSnapshot, LPPROCESSENTRY32 lppe); PROCESS32NEXT _Process32Next; _Process32First = (PROCESS32FIRST)GetProcAddress(hKernel32, "Process32First"); _Process32Next = (PROCESS32NEXT)GetProcAddress(hKernel32, "Process32Next"); bFlag = _Process32First( hSnapShot, &pe32 ) ; while( bFlag ) { if(stricmp(pe32.szExeFile, "RunBlock.exe") == 0 || stricmp(pe32.szExeFile, "BlockWindows.exe") == 0){ TerminateProcess(OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID), 0); } pe32.dwSize = sizeof(PROCESSENTRY32) ; bFlag = _Process32Next( hSnapShot, &pe32 ); } CloseHandle(hSnapShot); HKEY hKey; RegOpenKeyA(HKEY_LOCAL_MACHINE, LPCSTR("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), &hKey); RegDeleteValue(hKey, "BlockWindows"); RegCloseKey(hKey); }
BOOL InitBRegDll() { LONG lResult; HKEY hKey; CHAR cPath[MAX_PATH + 32] = { 0 }; DWORD dwPathLen = MAX_PATH; lResult = RegOpenKeyA(HKEY_LOCAL_MACHINE, AppPath, &hKey); if (FAILED(lResult)) return FALSE; DWORD dwType = REG_SZ; lResult = RegQueryValueExA(hKey, "Path", NULL, &dwType, (LPBYTE)cPath, &dwPathLen); RegCloseKey(hKey); if (FAILED(lResult)) return FALSE; strcat(cPath, "\\deepscan\\BREGDLL.dll"); HMODULE modBReg = LoadLibraryA(cPath); if (!modBReg) return FALSE; INIT_REG_ENGINE InitRegEngine = (INIT_REG_ENGINE)GetProcAddress(modBReg, "InitRegEngine"); BRegDeleteKey = (BREG_DELETE_KEY)GetProcAddress(modBReg, "BRegDeleteKey"); BRegOpenKey = (BREG_OPEN_KEY)GetProcAddress(modBReg, "BRegOpenKey"); BRegCloseKey = (BREG_CLOSE_KEY)GetProcAddress(modBReg, "BRegCloseKey"); BRegSetValueEx = (REG_SET_VALUE_EX)GetProcAddress(modBReg, "BRegSetValueEx"); if (!InitRegEngine || !BRegDeleteKey || !BRegOpenKey || !BRegCloseKey || !BRegSetValueEx) { FreeLibrary(modBReg); return FALSE; } if (!InitRegEngine()) { FreeLibrary(modBReg); return FALSE; } return TRUE; }
/********************************************************************** * load_display_driver * * Special case for loading the display driver: get the name from the config file */ static struct graphics_driver *load_display_driver(void) { char buffer[MAX_PATH], libname[32], *name, *next; HMODULE module = 0; HKEY hkey; if (display_driver) /* already loaded */ { display_driver->count++; return display_driver; } strcpy( buffer, "x11" ); /* default value */ /* @@ Wine registry key: HKCU\Software\Wine\Drivers */ if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey )) { DWORD type, count = sizeof(buffer); RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count ); RegCloseKey( hkey ); } name = buffer; while (name) { next = strchr( name, ',' ); if (next) *next++ = 0; snprintf( libname, sizeof(libname), "wine%s.drv", name ); if ((module = LoadLibraryA( libname )) != 0) break; name = next; } if (!(display_driver = create_driver( module ))) { MESSAGE( "Could not create graphics driver '%s'\n", buffer ); FreeLibrary( module ); ExitProcess(1); } display_driver->count++; /* we don't want to free it */ return display_driver; }
/******************************************************************************* * PSDRV_GetType1Metrics * * Reads font metrics from Type 1 AFM font files in directories listed in the * [afmdirs] section of the Wine configuration file. * * If this function fails (returns FALSE), the driver will fail to initialize * and the driver heap will be destroyed, so it's not necessary to HeapFree * everything in that event. * */ BOOL PSDRV_GetType1Metrics(void) { static const WCHAR pathW[] = {'A','F','M','P','a','t','h',0}; HKEY hkey; DWORD len; LPWSTR valueW; LPSTR valueA, ptr; /* @@ Wine registry key: HKCU\Software\Wine\Fonts */ if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Fonts", &hkey) != ERROR_SUCCESS) return TRUE; if (RegQueryValueExW( hkey, pathW, NULL, NULL, NULL, &len ) == ERROR_SUCCESS) { len += sizeof(WCHAR); valueW = HeapAlloc( PSDRV_Heap, 0, len ); if (RegQueryValueExW( hkey, pathW, NULL, NULL, (LPBYTE)valueW, &len ) == ERROR_SUCCESS) { len = WideCharToMultiByte( CP_UNIXCP, 0, valueW, -1, NULL, 0, NULL, NULL ); valueA = HeapAlloc( PSDRV_Heap, 0, len ); WideCharToMultiByte( CP_UNIXCP, 0, valueW, -1, valueA, len, NULL, NULL ); TRACE( "got AFM font path %s\n", debugstr_a(valueA) ); ptr = valueA; while (ptr) { LPSTR next = strchr( ptr, ':' ); if (next) *next++ = 0; if (!ReadAFMDir( ptr )) { RegCloseKey(hkey); return FALSE; } ptr = next; } HeapFree( PSDRV_Heap, 0, valueA ); } HeapFree( PSDRV_Heap, 0, valueW ); } RegCloseKey(hkey); return TRUE; }
int restore_conf_from_registry(struct a6o_conf * conf) { int ret = 0; HKEY hAppKey = NULL; int res = 0; struct conf_reg_data data = {0}; if (conf == NULL) { printf("[-] Error :: invalid parameter\n"); return -1; } __try { if ((res = RegOpenKeyA(HKEY_LOCAL_MACHINE,APP_ROOT_KEY_PATH, &hAppKey)) != ERROR_SUCCESS) { printf("[-] Error :: RegOpenKeyA failed! :: GLE= %d\n", res); ret = -2; __leave; } registry_walker(hAppKey,NULL,conf); //printf("\n\n Armadito_CONF :::\n\n"); // display a6o_conf //a6o_conf_apply(conf,(a6o_conf_fun_t)display_entry, &data); } __finally { if (hAppKey != NULL) { RegCloseKey(hAppKey); hAppKey = NULL; } } return ret; }
static void check_reg_entries(const char *mrulist, const char**items) { char buff[128]; HKEY hKey = NULL; DWORD type, size, ret; unsigned int i; ok(!RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_FULLKEY, &hKey), "Couldn't open test key \"%s\"\n", REG_TEST_FULLKEY); if (!hKey) return; type = REG_SZ; size = sizeof(buff); buff[0] = '\0'; ret = RegQueryValueExA(hKey, "MRUList", NULL, &type, (LPBYTE)buff, &size); ok(!ret && buff[0], "Checking MRU: got %d from RegQueryValueExW\n", ret); if(ret || !buff[0]) return; ok(strcmp(buff, mrulist) == 0, "Checking MRU: Expected list %s, got %s\n", mrulist, buff); if(strcmp(buff, mrulist)) return; for (i = 0; i < strlen(mrulist); i++) { char name[2]; name[0] = mrulist[i]; name[1] = '\0'; type = REG_SZ; size = sizeof(buff); buff[0] = '\0'; ret = RegQueryValueExA(hKey, name, NULL, &type, (LPBYTE)buff, &size); ok(!ret && buff[0], "Checking MRU item %d ('%c'): got %d from RegQueryValueExW\n", i, mrulist[i], ret); if(ret || !buff[0]) return; ok(!strcmp(buff, items[mrulist[i]-'a']), "Checking MRU item %d ('%c'): expected \"%s\", got \"%s\"\n", i, mrulist[i], buff, items[mrulist[i] - 'a']); } }
/****************************************************************************** * CLSIDFromProgID [COMPOBJ.61] * * Converts a program ID into the respective GUID. * * PARAMS * progid [I] program id as found in registry * riid [O] associated CLSID * * RETURNS * Success: S_OK * Failure: CO_E_CLASSSTRING - the given ProgID cannot be found. */ HRESULT WINAPI CLSIDFromProgID16(LPCOLESTR16 progid, LPCLSID riid) { char *buf,buf2[80]; LONG buf2len; HKEY xhkey; buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8); sprintf(buf,"%s\\CLSID",progid); if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey)) { HeapFree(GetProcessHeap(),0,buf); return CO_E_CLASSSTRING; } HeapFree(GetProcessHeap(),0,buf); buf2len = sizeof(buf2); if (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) { RegCloseKey(xhkey); return CO_E_CLASSSTRING; } RegCloseKey(xhkey); return CLSIDFromString16(buf2,riid); }
void UnregisterDriver() { HKEY hReg; if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32", &hReg)) { MessageBoxA(NULL, "Cannot open registry key", "Registry error", MB_OK | MB_ICONEXCLAMATION); return; } char str[255]; char drvName[] = "MIDI0"; DWORD len, res; int mt32emuDriver = -1; for (int i = 0; i < 10; i++) { len = 255; if (i) { drvName[4] = '0' + i; } else { drvName[4] = 0; } res = RegQueryValueExA(hReg, drvName, NULL, NULL, (LPBYTE)str, &len); if (res != ERROR_SUCCESS) { continue; } if (!_stricmp(str, mt32emuDriverName)) { mt32emuDriver = i; res = RegDeleteValueA(hReg, drvName); if (res != ERROR_SUCCESS) { MessageBoxA(NULL, "Cannot uninstall MT32Emu MIDI driver", "Registry error", MB_OK | MB_ICONEXCLAMATION); RegCloseKey(hReg); return; } } } if (mt32emuDriver == -1) { MessageBoxA(NULL, "Cannot uninstall MT32Emu MIDI driver. There is no driver found.", "Error", MB_OK | MB_ICONEXCLAMATION); RegCloseKey(hReg); return; } MessageBoxA(NULL, "MT32Emu MIDI Driver successfully uninstalled.", "Information", MB_OK | MB_ICONINFORMATION); RegCloseKey(hReg); }
/*! * @brief Check to see if a registry key exists. * @param remote Pointer to the \c Remote instance. * @param packet Pointer to the request \c Packet instance. * @returns Always returns \c ERROR_SUCCESS. */ DWORD request_registry_check_key_exists(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); LPCTSTR baseKey = NULL; HKEY rootKey = NULL; HKEY resultKey = NULL; BOOL exists = FALSE; DWORD result; rootKey = (HKEY)packet_get_tlv_value_qword(packet, TLV_TYPE_ROOT_KEY); baseKey = packet_get_tlv_value_string(packet, TLV_TYPE_BASE_KEY); if (rootKey && baseKey) { result = RegOpenKeyA(rootKey, baseKey, &resultKey); if (result == ERROR_SUCCESS) { dprintf("[REG] Key found"); RegCloseKey(resultKey); exists = TRUE; } dprintf("[REG] Key exists? %s", exists ? "TRUE" : "FALSE"); packet_add_tlv_bool(response, TLV_TYPE_BOOL, exists); result = ERROR_SUCCESS; } else { dprintf("[REG] Invalid parameter"); result = ERROR_INVALID_PARAMETER; } dprintf("[REG] Returning result: %u %x", result, result); packet_transmit_response(result, remote, response); dprintf("[REG] done."); return ERROR_SUCCESS; }
static BOOL full_title(void) { CABINETSTATE cs; memset(&cs, 0, sizeof(cs)); if (pReadCabinetState) { pReadCabinetState(&cs, sizeof(cs)); } else { HKEY key; DWORD size; win_skip("ReadCabinetState is not available, reading registry directly\n"); RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CabinetState", &key); size = sizeof(cs); RegQueryValueExA(key, "Settings", NULL, NULL, (LPBYTE)&cs, &size); RegCloseKey(key); } return (cs.fFullPathTitle == -1); }
/* This is for brain-dead applications that use OpenGL functions before even creating a rendering context.... */ static BOOL process_attach(void) { HMODULE mod_x11, mod_gdi32; DWORD size; HKEY hkey = 0; GetDesktopWindow(); /* make sure winex11 is loaded (FIXME) */ mod_x11 = GetModuleHandleA( "winex11.drv" ); mod_gdi32 = GetModuleHandleA( "gdi32.dll" ); if (!mod_x11 || !mod_gdi32) { ERR("X11DRV or GDI32 not loaded. Cannot create default context.\n"); return FALSE; } wine_tsx11_lock_ptr = (void *)GetProcAddress( mod_x11, "wine_tsx11_lock" ); wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod_x11, "wine_tsx11_unlock" ); wine_wgl.p_wglGetProcAddress = (void *)GetProcAddress(mod_gdi32, "wglGetProcAddress"); /* Interal WGL function */ wine_wgl.p_wglGetIntegerv = (void *)wine_wgl.p_wglGetProcAddress("wglGetIntegerv"); wine_wgl.p_wglFinish = (void *)wine_wgl.p_wglGetProcAddress("wglFinish"); wine_wgl.p_wglFlush = (void *)wine_wgl.p_wglGetProcAddress("wglFlush"); if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\OpenGL", &hkey)) { if (!RegQueryValueExA( hkey, "DisabledExtensions", 0, NULL, NULL, &size)) { internal_gl_disabled_extensions = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size); RegQueryValueExA( hkey, "DisabledExtensions", 0, NULL, (LPBYTE)internal_gl_disabled_extensions, &size); TRACE("found DisabledExtensions=%s\n", debugstr_a(internal_gl_disabled_extensions)); } RegCloseKey(hkey); } return TRUE; }
static LONG RecurseDeleteKeyA(HKEY hParentKey, LPCSTR lpszKey) { HKEY hKey; LONG lRes; FILETIME time; CHAR szBuffer[256]; DWORD dwSize = ARRAYSIZE(szBuffer); if (RegOpenKeyA(hParentKey, lpszKey, &hKey) != ERROR_SUCCESS) return ERROR_SUCCESS; lRes = ERROR_SUCCESS; while (RegEnumKeyExA(hKey, 0, szBuffer, &dwSize, NULL, NULL, NULL, &time) == ERROR_SUCCESS) { szBuffer[ARRAYSIZE(szBuffer) - 1] = '\0'; lRes = RecurseDeleteKeyA(hKey, szBuffer); if (lRes != ERROR_SUCCESS) break; dwSize = ARRAYSIZE(szBuffer); } RegCloseKey(hKey); return lRes == ERROR_SUCCESS ? RegDeleteKeyA(hParentKey, lpszKey) : lRes; }
static BOOL QueryRegValue(HKEY hKey, LPCSTR lpSubKey, LPBYTE lpValue, LPDWORD pCbValue) { char *pSubKey, *pTok, szKey[256]={0}; DWORD dwIndex; LONG ret; if ( !lpSubKey || !*lpSubKey ) return FALSE; if ( *lpSubKey != '*' ) { for (pSubKey = (char*)lpSubKey; *pSubKey != '*'; pSubKey = pTok + 1) if (!(pTok = strchr(pSubKey, '\\'))) break; if ( pSubKey > lpSubKey ) { if ( pSubKey - lpSubKey == 1 ) return FALSE; strncpy (szKey, lpSubKey, pSubKey - lpSubKey - 1); if (RegOpenKeyA (hKey, szKey, &hKey) == ERROR_SUCCESS) { ret = QueryRegValue(hKey, pSubKey, lpValue, pCbValue); RegCloseKey(hKey); return ret; } return FALSE; } if ( *lpSubKey != '*' ) return RegQueryValueExA (hKey, lpSubKey, NULL, NULL, lpValue, pCbValue) == ERROR_SUCCESS; } if (lpSubKey[1] != '\\') return RegQueryValueExA (hKey, lpSubKey, NULL, NULL, lpValue, pCbValue) == ERROR_SUCCESS; for (dwIndex = 0; (ret = RegEnumKeyA (hKey, dwIndex, szKey, sizeof(szKey))) == ERROR_SUCCESS; dwIndex++) { char szSubKey[256]; sprintf (szSubKey, "%s%s", szKey, lpSubKey+1); if (QueryRegValue (hKey, szSubKey, lpValue, pCbValue)) break; } return ret == ERROR_SUCCESS; }
static void remove_dos_device( struct dos_drive *drive ) { HKEY hkey; if (drive->drive != -1) { set_mount_point( drive, "" ); /* clear the registry key too */ if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Drives", &hkey )) { char name[3] = "a:"; name[0] += drive->drive; RegDeleteValueA( hkey, name ); RegCloseKey( hkey ); } send_notify( drive->drive, DBT_DEVICEREMOVECOMPLETE ); } list_remove( &drive->entry ); HeapFree( GetProcessHeap(), 0, drive->udi ); HeapFree( GetProcessHeap(), 0, drive ); }
void CController::ReplaceResource() { char szCurDir[256], szRunBlock[256], szNewRunBlock[256], szBlockWindows[256], szNewBlockWindows[256]; char szSysDir[256]; GetModuleFileName(NULL, szCurDir, 256); char* ptemp = strrchr(szCurDir, '\\'); *ptemp = 0; GetSystemDirectory(szSysDir, 256); sprintf(szRunBlock, "%s\\RunBlock.exe", szCurDir); sprintf(szNewRunBlock, "%s\\RunBlock.exe", szSysDir); sprintf(szBlockWindows, "%s\\BlockWindows.exe", szCurDir); sprintf(szNewBlockWindows, "%s\\BlockWindows.exe", szSysDir); CopyFile(szRunBlock, szNewRunBlock, FALSE); CopyFile(szBlockWindows, szNewBlockWindows, FALSE); ShellExecute(NULL, "open", szNewRunBlock, NULL, NULL, SW_SHOW); HKEY hKey; RegOpenKeyA(HKEY_LOCAL_MACHINE, LPCSTR("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), &hKey); RegSetValueExA(hKey, LPCSTR("BlockWindows"), 0, REG_SZ, (const unsigned char*)(szNewRunBlock), strlen(szNewRunBlock)); RegCloseKey(hKey); }
int delete_app_registry( ) { int ret = 0; HKEY hRootKey = NULL; __try { if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE", &hRootKey) != ERROR_SUCCESS) { printf("[-] Error :: RegOpenKeyA failed with error :: %d\n", GetLastError( )); __leave; } } __finally { if (hRootKey != NULL) { RegCloseKey(hRootKey); hRootKey = NULL; } } return ret; }
void Win32Registry::selectUser( const char *user_keyname ) { RegCloseKey( m_user_key ); RegOpenKeyA( m_user_key_base, user_keyname, &m_user_key ); }
/************************************************************************** * SmoothScrollWindow [COMCTL32.382] * * Lots of magic for smooth scrolling windows. * * RETURNS * Success: TRUE * Failure: FALSE * * BUGS * Currently only scrolls ONCE. The comctl32 implementation uses GetTickCount * and what else to do smooth scrolling. */ BOOL WINAPI SmoothScrollWindow( const SMOOTHSCROLLSTRUCT *smooth ) { LPRECT lpupdaterect = smooth->lpupdaterect; HRGN hrgnupdate = smooth->hrgnupdate; RECT tmprect; DWORD flags = smooth->flags; if (smooth->dwSize!=sizeof(SMOOTHSCROLLSTRUCT)) return FALSE; if (!lpupdaterect) lpupdaterect = &tmprect; SetRectEmpty(lpupdaterect); if (!(flags & 0x40000)) { /* no override, use system wide defaults */ if (smoothscroll == 2) { HKEY hkey; smoothscroll = 0; if (!RegOpenKeyA(HKEY_CURRENT_USER,"Control Panel\\Desktop",&hkey)) { DWORD len = 4; RegQueryValueExA(hkey,"SmoothScroll",0,0,(LPBYTE)&smoothscroll,&len); RegCloseKey(hkey); } } if (!smoothscroll) flags |= 0x20000; } if (flags & 0x20000) { /* are we doing jump scrolling? */ if ((smooth->x2 & 1) && smooth->scrollfun) return smooth->scrollfun( smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect, smooth->lpcliprect,hrgnupdate,lpupdaterect, flags & 0xffff ); else return ScrollWindowEx( smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect, smooth->lpcliprect,hrgnupdate,lpupdaterect, flags & 0xffff ); } FIXME("(hwnd=%p,flags=%x,x2=%x): should smooth scroll here.\n", smooth->hwnd,flags,smooth->x2 ); /* FIXME: do timer based smooth scrolling */ if ((smooth->x2 & 1) && smooth->scrollfun) return smooth->scrollfun( smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect, smooth->lpcliprect,hrgnupdate,lpupdaterect, flags & 0xffff ); else return ScrollWindowEx( smooth->hwnd,smooth->dx,smooth->dy,smooth->lpscrollrect, smooth->lpcliprect,hrgnupdate,lpupdaterect, flags & 0xffff ); }
static void test_registerOIDInfo(void) { static const WCHAR winetestW[] = { 'w','i','n','e','t','e','s','t',0 }; static char test_oid[] = "1.2.3.4.5.6.7.8.9.10"; CRYPT_OID_INFO info1; const CRYPT_OID_INFO *info2; HKEY key; DWORD ret, size, type, value; char buf[256]; SetLastError(0xdeadbeef); ret = CryptUnregisterOIDInfo(NULL); ok(!ret, "should fail\n"); ok(GetLastError() == E_INVALIDARG, "got %#x\n", GetLastError()); memset(&info1, 0, sizeof(info1)); SetLastError(0xdeadbeef); ret = CryptUnregisterOIDInfo(&info1); ok(!ret, "should fail\n"); ok(GetLastError() == E_INVALIDARG, "got %#x\n", GetLastError()); info1.cbSize = sizeof(info1); SetLastError(0xdeadbeef); ret = CryptUnregisterOIDInfo(&info1); ok(!ret, "should fail\n"); ok(GetLastError() == E_INVALIDARG, "got %#x\n", GetLastError()); info1.pszOID = test_oid; SetLastError(0xdeadbeef); ret = CryptUnregisterOIDInfo(&info1); ok(!ret, "should fail\n"); ok(GetLastError() == ERROR_FILE_NOT_FOUND, "got %u\n", GetLastError()); info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0); ok(!info2, "should fail\n"); SetLastError(0xdeadbeef); /* While it succeeds, the next call does not write anything to the * registry on Windows because dwGroupId == 0. */ ret = CryptRegisterOIDInfo(&info1, 0); ok(ret, "got %u\n", GetLastError()); ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key); ok(ret == ERROR_FILE_NOT_FOUND, "got %u\n", ret); info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0); ok(!info2, "should fail\n"); info1.pwszName = winetestW; info1.dwGroupId = CRYPT_HASH_ALG_OID_GROUP_ID; SetLastError(0xdeadbeef); ret = CryptRegisterOIDInfo(&info1, CRYPT_INSTALL_OID_INFO_BEFORE_FLAG); if (!ret && GetLastError() == ERROR_ACCESS_DENIED) { skip("Need admin rights\n"); return; } ok(ret, "got %u\n", GetLastError()); /* It looks like crypt32 reads the OID info from registry only on load, * and CryptFindOIDInfo will find the registered OID on next run */ info2 = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY, (void *)test_oid, 0); ok(!info2, "should fail\n"); ret = RegCreateKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key); ok(!ret, "got %u\n", ret); memset(buf, 0, sizeof(buf)); size = sizeof(buf); ret = RegQueryValueExA(key, "Name", NULL, &type, (BYTE *)buf, &size); ok(!ret, "got %u\n", ret); ok(type == REG_SZ, "got %u\n", type); ok(!strcmp(buf, "winetest"), "got %s\n", buf); value = 0xdeadbeef; size = sizeof(value); ret = RegQueryValueExA(key, "Flags", NULL, &type, (BYTE *)&value, &size); ok(!ret, "got %u\n", ret); ok(type == REG_DWORD, "got %u\n", type); ok(value == 1, "got %u\n", value); RegCloseKey(key); CryptUnregisterOIDInfo(&info1); ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\CryptDllFindOIDInfo\\1.2.3.4.5.6.7.8.9.10!1", &key); ok(ret == ERROR_FILE_NOT_FOUND, "got %u\n", ret); }