Esempio n. 1
0
void regDeleteAutoStart () {
	HKEY hKey;
	if (RegOpenKeyExA(HKEY_CURRENT_USER, (LPCSTR)"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",0,KEY_ALL_ACCESS,&hKey) == ERROR_SUCCESS) {
		std::string exeName;
		getExeNameStr(&exeName);
		RegDeleteValueA(hKey, (LPCSTR)(exeName.c_str()));
		RegDeleteValueA(hKey, (LPCSTR) (exeName.append(" /minimized")).c_str());
		RegCloseKey(hKey);
	}
}
Esempio n. 2
0
static void test_AddERExcludedApplicationA(void)
{
    BOOL res;
    LONG lres;
    HKEY hroot;
    HKEY hexclude = 0;

    /* clean state */
    lres = RegCreateKeyA(HKEY_LOCAL_MACHINE, regpath_root, &hroot);
    if (lres == ERROR_ACCESS_DENIED)
    {
        skip("Not enough access rights\n");
        return;
    }

    if (!lres)
        lres = RegOpenKeyA(hroot, regpath_exclude, &hexclude);

    if (!lres)
        RegDeleteValueA(hexclude, "winetest_faultrep.exe");


    SetLastError(0xdeadbeef);
    res = AddERExcludedApplicationA(NULL);
    ok(!res, "got %d and 0x%x (expected FALSE)\n", res, GetLastError());

    SetLastError(0xdeadbeef);
    res = AddERExcludedApplicationA("");
    ok(!res, "got %d and 0x%x (expected FALSE)\n", res, GetLastError());

    SetLastError(0xdeadbeef);
    /* existence of the path doesn't matter this function succeeded */
    res = AddERExcludedApplicationA("winetest_faultrep.exe");
    if (is_process_limited())
    {
        /* LastError is not set! */
        ok(!res, "AddERExcludedApplicationA should have failed got %d\n", res);
    }
    else
    {
        ok(res, "AddERExcludedApplicationA failed (le=0x%x)\n", GetLastError());

        /* add, when already present */
        SetLastError(0xdeadbeef);
        res = AddERExcludedApplicationA("winetest_faultrep.exe");
        ok(res, "AddERExcludedApplicationA failed (le=0x%x)\n", GetLastError());
    }

    /* cleanup */
    RegDeleteValueA(hexclude, "winetest_faultrep.exe");

    RegCloseKey(hexclude);
    RegCloseKey(hroot);
}
Esempio n. 3
0
File: heap.c Progetto: baskanov/wine
static void test_debug_heap( const char *argv0, DWORD flags )
{
    char keyname[MAX_PATH];
    char buffer[MAX_PATH];
    PROCESS_INFORMATION	info;
    STARTUPINFOA startup;
    BOOL ret;
    DWORD err;
    HKEY hkey;
    const char *basename;

    if ((basename = strrchr( argv0, '\\' ))) basename++;
    else basename = argv0;

    sprintf( keyname, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\%s",
             basename );
    if (!strcmp( keyname + strlen(keyname) - 3, ".so" )) keyname[strlen(keyname) - 3] = 0;

    err = RegCreateKeyA( HKEY_LOCAL_MACHINE, keyname, &hkey );
    if (err == ERROR_ACCESS_DENIED)
    {
        skip("Not authorized to change the image file execution options\n");
        return;
    }
    ok( !err, "failed to create '%s' error %u\n", keyname, err );
    if (err) return;

    if (flags == 0xdeadbeef)  /* magic value for unsetting it */
        RegDeleteValueA( hkey, "GlobalFlag" );
    else
        RegSetValueExA( hkey, "GlobalFlag", 0, REG_DWORD, (BYTE *)&flags, sizeof(flags) );

    memset( &startup, 0, sizeof(startup) );
    startup.cb = sizeof(startup);

    sprintf( buffer, "%s heap.c 0x%x", argv0, flags );
    ret = CreateProcessA( NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info );
    ok( ret, "failed to create child process error %u\n", GetLastError() );
    if (ret)
    {
        winetest_wait_child_process( info.hProcess );
        CloseHandle( info.hThread );
        CloseHandle( info.hProcess );
    }
    RegDeleteValueA( hkey, "GlobalFlag" );
    RegCloseKey( hkey );
    RegDeleteKeyA( HKEY_LOCAL_MACHINE, keyname );
}
void unregisterDriver() {
	HKEY hReg;
	if (RegOpenKeyA(HKEY_LOCAL_MACHINE, DRIVERS_REGISTRY_KEY, &hReg)) {
		MessageBoxA(NULL, CANNOT_OPEN_REGISTRY_ERR, REGISTRY_ERROR_TITLE, MB_OK | MB_ICONEXCLAMATION);
		return;
	}
	char str[255];
	char drvName[] = "midi0";
	DWORD len, res;
	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, MT32EMU_DRIVER_NAME)) {
			res = RegDeleteValueA(hReg, drvName);
			if (res != ERROR_SUCCESS) {
				MessageBoxA(NULL, CANNOT_UNINSTALL_ERR, REGISTRY_ERROR_TITLE, MB_OK | MB_ICONEXCLAMATION);
				RegCloseKey(hReg);
				return;
			}
			MessageBoxA(NULL, SUCCESSFULLY_UNINSTALLED_MSG, INFORMATION_TITLE, MB_OK | MB_ICONINFORMATION);
			RegCloseKey(hReg);
			return;
		}
	}
	MessageBoxA(NULL, CANNOT_UNINSTALL_NOT_FOUND_ERR, ERROR_TITLE, MB_OK | MB_ICONEXCLAMATION);
	RegCloseKey(hReg);
}
Esempio n. 5
0
static void cleanup_eventlog(void)
{
    BOOL bret;
    LONG lret;
    HKEY key;
    DWORD i;
    char winesvc[MAX_PATH];

    /* Delete the registry tree */
    lstrcpyA(winesvc, eventlogsvc);
    lstrcatA(winesvc, "\\");
    lstrcatA(winesvc, eventlogname);

    RegOpenKeyA(HKEY_LOCAL_MACHINE, winesvc, &key);
    for (i = 0; i < sizeof(eventsources)/sizeof(eventsources[0]); i++)
        RegDeleteKeyA(key, eventsources[i]);
    RegDeleteValueA(key, "Sources");
    RegCloseKey(key);
    lret = RegDeleteKeyA(HKEY_LOCAL_MACHINE, winesvc);
    ok(lret == ERROR_SUCCESS, "Could not delete the registry tree : %d\n", lret);

    /* A handle to the eventlog is locked by services.exe. We can only
     * delete the eventlog file after reboot.
     */
    bret = MoveFileExA(eventlogfile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
    ok(bret, "Expected MoveFileEx to succeed: %d\n", GetLastError());
}
Esempio n. 6
0
 LONG DeleteValue(LPCSTR lpValueName)
   const
 {
   if (!IsValidHandle())
     return ERROR_INVALID_HANDLE;
   return RegDeleteValueA(hKey(), lpValueName);
 }
Esempio n. 7
0
void  sub_4AEBDA()
{
  char **v0; 
  char (**v1)[8]; 
  void cbData; 
  void hKey; 
  char Data; 
  char Buffer; 
  char FileName; 
void off_4A2D3C, off_4A2D40;
  cbData = 128;
  if ( off_4A2D3C )
  {
    v0 = &off_4A2D3C;
    v1 = &off_4A2D40;
    do
    {
      RegOpenKeyExA(*(&v1 - 2), *v0, 0, 0x20019u, &hKey);
      if ( !RegQueryValueExA(&hKey, *v1, 0, 0, &Data, &cbData) )
      {
        RegDeleteValueA(&hKey, *v1);
        GetSystemDirectoryA(&Buffer, 0x104u);
        sprintf(&FileName, "%s\\%s", &Buffer, *(v1 + 2));
        DeleteFileA(&FileName);
      }
      RegCloseKey(&hKey);
      v1 += 5;
      v0 = (char **)(v1 - 1);
    }
    while ( *(v1 - 1) );
  }
}
Esempio n. 8
0
void RemoveRegOpenWithExtEntry(const TCHAR *pszAppFileName,const char *pszFileExt)
{
	HKEY hRootKey,hAppsKey,hExeKey,hTypesKey;

	/* try to open interactive user's classes key */
	if (RegOpenKeyEx(HKEY_CURRENT_USER,_T("Software\\Classes"),0,KEY_QUERY_VALUE,&hRootKey))
		hRootKey=HKEY_CLASSES_ROOT;

	/* applications */
	if (!RegOpenKeyEx(hRootKey,_T("Applications"),0,KEY_QUERY_VALUE,&hAppsKey)) {
		/* filename */
		if (!RegOpenKeyEx(hAppsKey,pszAppFileName,0,KEY_QUERY_VALUE,&hExeKey)) {
			/* supported types */
			if (!RegOpenKeyEx(hExeKey,_T("SupportedTypes"),0,KEY_SET_VALUE,&hTypesKey)) {	
				RegDeleteValueA(hTypesKey,pszFileExt);
				RegCloseKey(hTypesKey);
			}
			RegCloseKey(hExeKey);
		}
		RegCloseKey(hAppsKey);
	}

	if (hRootKey!=HKEY_CLASSES_ROOT)
		RegCloseKey(hRootKey);
}
Esempio n. 9
0
// unregisters previously registered module 
int KL1_UnregisterModule (const WCHAR *name)
{
    HKEY hkey;

    int err = KL1_OpenHKey(hkey);

    if (err != KL1_SUCC)
    {
        return err;
    }

    if (g_os == KL1_OS_9X)
    {
		USES_CONVERSION;
		LONG nDelResult = RegDeleteValueA(hkey, W2A(name));
        if (nDelResult != ERROR_SUCCESS && nDelResult != ERROR_FILE_NOT_FOUND)
        {
			KL1_CloseHKey(hkey);
            return KL1_ERR;
        }
    }
    else
    {
		LONG nDelResult = RegDeleteValueW(hkey, name);
        if (nDelResult != ERROR_SUCCESS && nDelResult != ERROR_FILE_NOT_FOUND)
        {
			KL1_CloseHKey(hkey);
            return KL1_ERR;
        }
    }

	KL1_CloseHKey(hkey);

    return KL1_SUCC;
}
Esempio n. 10
0
	// Append/Remove to Autostart
	void TaskBarIcon::OnMenuAutoStart(wxCommandEvent& event)
	{
		// Registry Key
		HKEY hkRegistry;

		// Open Key
		if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\", 0, KEY_WRITE, &hkRegistry) == ERROR_SUCCESS)
		{
			// He checked it
			if (event.IsChecked())
			{
				// Get App Path
				wxString appPath = wxStandardPaths::Get().GetExecutablePath();

				// Close to Taskbar on Autostart
				appPath = "\"" + appPath + "\"" + " -taskbar";

				// Write in
				RegSetValueExW(hkRegistry, L"CallAdmin-Client", 0, REG_SZ, (BYTE*)appPath.wc_str(), (wcslen(appPath.wc_str()) + 1) * sizeof(wchar_t));

				LogAction("Added Call Admin to the auto start list");
			}
			else
			{
				// Remove it
				RegDeleteValueA(hkRegistry, "CallAdmin-Client");

				LogAction("Removed Call Admin from the auto start list");
			}

			// Close Key
			RegCloseKey(hkRegistry);
		}
	}
Esempio n. 11
0
/*****************************************************************
 *  WNetRemoveCachedPassword [MPR.@]
 */
UINT WINAPI WNetRemoveCachedPassword(
      LPSTR pbResource,   /* [in] resource ID to delete */
      WORD cbResource,    /* [in] number of bytes in the resource ID */
      BYTE nType )        /* [in] Type of the resource to delete */
{
    HKEY hkey;
    DWORD r;
    LPSTR valname;

    WARN( "(%p(%s), %d, %d): totally insecure\n",
           pbResource, debugstr_a(pbResource), cbResource, nType );

    /* @@ Wine registry key: HKCU\Software\Wine\Wine\Mpr */
    r = RegCreateKeyA( HKEY_CURRENT_USER, mpr_key, &hkey );
    if( r )
        return WN_ACCESS_DENIED;

    valname = MPR_GetValueName( pbResource, cbResource, nType );
    if( valname )
    {
        r = RegDeleteValueA( hkey, valname );
        if( r )
            r = WN_ACCESS_DENIED;
        else
            r = WN_SUCCESS;
        HeapFree( GetProcessHeap(), 0, valname );
    }
    else
        r = WN_OUT_OF_MEMORY;

    return r;
}
Esempio n. 12
0
static void restore_value(HKEY hkey, reg_save_value *saved)
{
    if (saved->data)
    {
        RegSetValueExA(hkey, saved->name, 0, saved->type, saved->data, saved->size);
        HeapFree(GetProcessHeap(), 0, saved->data);
    }
    else
        RegDeleteValueA(hkey, saved->name);
}
Esempio n. 13
0
/******************************************************************
 *                 DrvSetPrinterData     (GDI.281)
 *                 DrvSetPrinterData16   (GDI32.@)
 *
 */
DWORD WINAPI DrvSetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile,
                               DWORD lpType, LPBYTE lpPrinterData,
                               DWORD dwSize)
{
    LPSTR RegStr_Printer;
    HKEY hkey = 0;
    DWORD res = 0;

    if (HIWORD(lpPrinter))
            TRACE("printer %s\n",lpPrinter);
    else
            TRACE("printer %p\n",lpPrinter);
    if (HIWORD(lpProfile))
            TRACE("profile %s\n",lpProfile);
    else
            TRACE("profile %p\n",lpProfile);
    TRACE("lpType %08lx\n",lpType);

    if ((!lpPrinter) || (!lpProfile) ||
    ((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
    (!strcmp(lpProfile, PrinterModel))))
	return ERROR_INVALID_PARAMETER;

    RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
			strlen(Printers) + strlen(lpPrinter) + 2);
    strcpy(RegStr_Printer, Printers);
    strcat(RegStr_Printer, lpPrinter);

    if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
    (!strcmp(lpProfile, DefaultDevMode)))) {
	if ( RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)
	     != ERROR_SUCCESS ||
	     RegSetValueExA(hkey, DefaultDevMode, 0, REG_BINARY,
			      lpPrinterData, dwSize) != ERROR_SUCCESS )
	        res = ERROR_INVALID_PRINTER_NAME;
    }
    else
    {
	strcat(RegStr_Printer, "\\");

	if( (res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)) ==
	    ERROR_SUCCESS ) {

	    if (!lpPrinterData)
	        res = RegDeleteValueA(hkey, lpProfile);
	    else
                res = RegSetValueExA(hkey, lpProfile, 0, lpType,
				       lpPrinterData, dwSize);
	}
    }

    if (hkey) RegCloseKey(hkey);
    HeapFree(GetProcessHeap(), 0, RegStr_Printer);
    return res;
}
Esempio n. 14
0
void WinRegistryKey::deleteValue(const std::string& name)
{
	open();
#if defined(POCO_WIN32_UTF8)
	std::wstring uname;
	Poco::UnicodeConverter::toUTF16(name, uname);
	if (RegDeleteValueW(_hKey, uname.c_str()) != ERROR_SUCCESS)
		throw NotFoundException(key(name));
#else
	if (RegDeleteValueA(_hKey, name.c_str()) != ERROR_SUCCESS)
		throw NotFoundException(key(name));
#endif
}
Esempio n. 15
0
/*
 * Arguments: reg_udata, [name (string)]
 * Returns: [reg_udata]
 */
static int
reg_del_value (lua_State *L)
{
    HKEY hk = lua_unboxpointer(L, 1, WREG_TYPENAME);
    const char *name = lua_tostring(L, 2);
    int res;

    res = RegDeleteValueA(hk, name);
    if (!res) {
	lua_settop(L, 1);
	return 1;
    }
    return sys_seterror(L, res);
}
Esempio n. 16
0
bool QSettingsPrivate::sysRemoveEntry( const QString &key )
{
    QString value;
    long ret = -1;

    HKEY hkey = sysd->openKey( key , KEY_SET_VALUE, value, globalScope );
    if ( hkey ) {
        /* This just deletes a value, not a subkey ... */
        ret = QT_WA_INLINE( RegDeleteValueW( hkey, ( LPCTSTR ) value.ucs2() ),
                            RegDeleteValueA( hkey, ( LPCSTR ) value.latin1() ) );
        RegCloseKey( hkey );
    }
    return ( ret == ERROR_SUCCESS );
}
Esempio n. 17
0
// RunAtStartupEnabled
void MakeRT::RunAtStartupEnabled(bool startup)
{
    _settings->setValue(RUNATSTARTUP, startup);

#ifdef Q_OS_WIN
    HKEY key;
    RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS, &key);
    if (startup)
    {
        QString appFileName = qApp->applicationFilePath();
        if (RegSetValueExA(key, "MakeRT", 0, REG_SZ, (BYTE*)appFileName.toStdString().c_str(), appFileName.length()) != ERROR_SUCCESS)
        {
            QMessageBox::critical(this, tr("Failed!"), tr("Cannot set autostart in registry."));
            RunAtStartupEnabled(false);
        }
    }
    else
    {
        RegDeleteValueA(key, "MakeRT");
    }
    RegCloseKey(key);
#elif defined Q_OS_LINUX
    QString dir = QDir::homePath() + "/.config/autostart/";
    QString fileName = "MakeRT.desktop";
    QString data;
    if (startup)
    {
        QDir tmp(dir);
        if (!tmp.exists())
            tmp.mkpath(dir);
        QFile file(dir + fileName);
        if (!file.open(QFile::WriteOnly))
        {
            QMessageBox::critical(this, tr("Failed!"), tr("Cannot create autostart file!"));
            RunAtStartupEnabled(false);
            return;
        }

        data = "[Desktop Entry]\n";
        data += "Type=Application\n";
        data += "Name=MakeRT\n";
        data += "Exec=" + qApp->applicationFilePath() + "\n";
        file.write(data.toStdString().c_str());
        file.close();
    }
    else
        QFile::remove(dir + fileName);
#endif // Q_OS_WIN
}
Esempio n. 18
0
int CGlobalSettings::SetGlobalValue(const char *product, const char *key, const char *value, const char *buffer)
{
	HKEY hKey,hSubKey;
	DWORD dwLen;
	cvs::string regkey;

	if(!isAdmin())
		return -1;

	if(!product || !strcmp(product,"cvsnt"))
		regkey="Software\\CVS";
	else
		cvs::sprintf(regkey,64,"Software\\March Hare Software Ltd\\%s",product);

	if(RegOpenKeyExA(HKEY_LOCAL_MACHINE,regkey.c_str(),0,KEY_READ|KEY_WRITE,&hKey) &&
	   RegCreateKeyExA(HKEY_LOCAL_MACHINE,regkey.c_str(),0,NULL,0,KEY_READ|KEY_WRITE,NULL,&hKey,NULL))
	{
		return -1; // Couldn't open or create key
	}

	if(key)
	{
		if(RegOpenKeyExA(hKey,key,0,KEY_WRITE,&hSubKey) &&
		   RegCreateKeyExA(hKey,key,0,NULL,0,KEY_WRITE,NULL,&hSubKey,NULL))
		{
			RegCloseKey(hKey);
			return -1; // Couldn't open or create key
		}
		RegCloseKey(hKey);
		hKey=hSubKey;
	}

	if(!buffer)
	{
		RegDeleteValueA(hKey,value);
	}
	else
	{
		dwLen=(DWORD)strlen(buffer);
		if(RegSetValueExA(hKey,value,0,REG_SZ,(LPBYTE)buffer,dwLen+1))
		{
			RegCloseKey(hKey);
			return -1;
		}
	}
	RegCloseKey(hKey);

	return 0;
}
Esempio n. 19
0
/**
poistaa rekisteristä arvon
*/
void MyRegistryClass::MyRegistryClass::deleteValue(std::string subkey)
{
	int n = RegDeleteValueA(key, (LPCSTR)(subkey.data()));
	if (n == ERROR_SUCCESS)
	{
		std::cout << "subkey \"" << subkey << "\" deleted successfully." << std::endl;
	}
	else
	{
		/* ERROR: 2 == subkey not found  */
		std::cout << "ERROR: " << n << std::endl;
		std::cout << "unable to delete subkey \"" << subkey << "\"." << std::endl;
	}

}
Esempio n. 20
0
void ZLWin32Config::registryRemoveValue(const std::string &category, const std::string &group, const std::string &valueName) {
	HKEY key;
	const std::string fullKeyName = rootKeyName() + "\\" + category + "\\" + group;
	LONG code = RegOpenKeyExA(HKEY_CURRENT_USER, fullKeyName.c_str(), 0, KEY_WRITE, &key);
	if (code != ERROR_SUCCESS) {
		std::string groupAlias = myGroupAliases[group];
		if (!groupAlias.empty()) {
			const std::string alternateKeyName = rootKeyName() + "\\" + category + "\\" + groupAlias;
			code = RegOpenKeyExA(HKEY_CURRENT_USER, alternateKeyName.c_str(), 0, KEY_WRITE, &key);
		}
	}
	if (code == ERROR_SUCCESS) {
		RegDeleteValueA(key, valueName.c_str());
		RegCloseKey(key);
		// TODO: remove empty group
	}
}
Esempio n. 21
0
string HomeDirPlugin::getConfig()
{
    if (!m_bSave)
        return "";
    HKEY subKey;
    DWORD disposition;
    if (RegCreateKeyExA(HKEY_CURRENT_USER, key_name, 0, "",
                        REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &subKey, &disposition) != ERROR_SUCCESS)
        return "";
    if (!m_bDefault){
        RegSetValueExA(subKey, path_value, 0, REG_SZ, (const unsigned char*)m_homeDir.c_str(), m_homeDir.length());
    }else{
        RegDeleteValueA(subKey, path_value);
    }
    RegCloseKey(subKey);
    return "";
}
Esempio n. 22
0
/**************************************************************************
*  IStream_fnRelease
*/
static ULONG WINAPI IStream_fnRelease(IStream *iface)
{
	ISHRegStream *This = impl_from_IStream(iface);
	ULONG refCount = InterlockedDecrement(&This->ref);

	TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);

	if (!refCount)
	{
	  TRACE(" destroying SHReg IStream (%p)\n",This);

	  if (This->hKey)
	  {
	    /* write back data in REG_BINARY */
	    if (This->dwMode == STGM_READWRITE || This->dwMode == STGM_WRITE)
	    {
	      if (This->dwLength)
	      {
	        if (This->bUnicode)
	          RegSetValueExW(This->hKey, This->u.keyNameW, 0, REG_BINARY,
	                         (const BYTE *) This->pbBuffer, This->dwLength);
	        else
	          RegSetValueExA(This->hKey, This->u.keyNameA, 0, REG_BINARY,
	                        (const BYTE *) This->pbBuffer, This->dwLength);
	      }
	      else
	      {
	        if (This->bUnicode)
	          RegDeleteValueW(This->hKey, This->u.keyNameW);
	        else
	          RegDeleteValueA(This->hKey, This->u.keyNameA);
	      }
	    }

	    RegCloseKey(This->hKey);
	  }

	  HeapFree(GetProcessHeap(),0,This->u.keyNameA);
	  HeapFree(GetProcessHeap(),0,This->pbBuffer);
	  HeapFree(GetProcessHeap(),0,This);
	  return 0;
	}

	return refCount;
}
Esempio n. 23
0
void RemoveRegFileExt(const char *pszFileExt,const char *pszClassName)
{
	HKEY hRootKey,hExtKey,hSubKey;
	DWORD nOpenWithCount;
	TCHAR *pszPrevClassName=NULL;
	BOOL fRestored=FALSE;

	/* try to open interactive user's classes key */
	if (RegOpenKeyEx(HKEY_CURRENT_USER,_T("Software\\Classes"),0,DELETE,&hRootKey))
		hRootKey=HKEY_CLASSES_ROOT;

	/* file ext */
	if (!RegOpenKeyExA(hRootKey,pszFileExt,0,KEY_QUERY_VALUE|KEY_SET_VALUE|DELETE,&hExtKey)) {
		/* class name (the important part) */
		if (!RestoreRegTree(hRootKey,pszFileExt,"bak_")) {
			pszPrevClassName=GetRegStrValue(hExtKey,NULL);
			if (pszPrevClassName!=NULL) {
				/* previous class name still exists? */
				/* using the merged view classes key for reading */
				if (!RegOpenKeyEx(HKEY_CLASSES_ROOT,pszPrevClassName,0,KEY_QUERY_VALUE,&hSubKey)) {
					fRestored=TRUE;
					RegCloseKey(hSubKey);
				} else RegDeleteValue(hExtKey,NULL);
				mir_free(pszPrevClassName);
			}
		}
		if (pszPrevClassName==NULL) RegDeleteValue(hExtKey,NULL);
		/* open with progids (remove if empty) */
		nOpenWithCount=0;
		if (!RegOpenKeyEx(hExtKey,_T("OpenWithProgids"),0,KEY_SET_VALUE|KEY_QUERY_VALUE,&hSubKey)) {
			/* remove current class (if set by another app) */
			RegDeleteValueA(hSubKey,pszClassName);
			RegQueryInfoKey(hSubKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&nOpenWithCount,NULL,NULL,NULL);
			RegCloseKey(hSubKey);
		}
		if (!nOpenWithCount) RegDeleteKey(hExtKey,_T("OpenWithProgids")); /* delete if no values */
		RegCloseKey(hExtKey);
	} else DeleteRegTreeBackup(pszFileExt,"bak_");
	if (!fRestored) RegDeleteKeyA(hRootKey,pszFileExt); /* try to remove it all */

	if (hRootKey!=HKEY_CLASSES_ROOT)
		RegCloseKey(hRootKey);
}
Esempio n. 24
0
static void test_machine_guid(void)
{
   char originalGuid[40];
   LONG r;
   HKEY key;
   DWORD size;
   HCRYPTPROV hCryptProv;
   BOOL restoreGuid = FALSE, ret;

   r = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography",
                     0, KEY_ALL_ACCESS, &key);
   if (r != ERROR_SUCCESS)
   {
       skip("couldn't open HKLM\\Software\\Microsoft\\Cryptography\n");
       return;
   }
   /* Cache existing MachineGuid, and delete it */
   size = sizeof(originalGuid);
   r = RegQueryValueExA(key, "MachineGuid", NULL, NULL, (BYTE *)originalGuid,
                        &size);
   if (r == ERROR_SUCCESS)
   {
       restoreGuid = TRUE;
       r = RegDeleteValueA(key, "MachineGuid");
       ok(!r, "RegDeleteValueA failed: %d\n", r);
   }
   else
       ok(r == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n",
          r);
   /* Create and release a provider */
   ret = pCryptAcquireContextA(&hCryptProv, szKeySet, NULL, PROV_RSA_FULL, 0);
   ok(ret || broken(!ret && GetLastError() == NTE_KEYSET_ENTRY_BAD /* NT4 */),
      "CryptAcquireContextA failed: %08x\n", GetLastError());
   pCryptReleaseContext(hCryptProv, 0);

   if (restoreGuid)
       RegSetValueExA(key, "MachineGuid", 0, REG_SZ, (const BYTE *)originalGuid,
                      strlen(originalGuid)+1);
   RegCloseKey(key);
}
Esempio n. 25
0
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);
}
Esempio n. 26
0
LONG winfrip_confstore_RegDeleteValue(HKEY hKey, LPCSTR lpValueName)
{
    WINFRIPP_CONFSTORE_DEBUG_ASSERT(hKey);
    WINFRIPP_CONFSTORE_DEBUG_ASSERT(lpValueName);

    /*
     * XXX document
     */
    switch (winfrip_confstore_backend_get()) {
    default:
	WINFRIPP_CONFSTORE_DEBUG_FAIL();
	return ERROR_INVALID_FUNCTION;

    case WINFRIP_GENERAL_STORE_BACKEND_REGISTRY:
	return RegDeleteValueA(hKey, lpValueName);

    case WINFRIP_GENERAL_STORE_BACKEND_EPHEMERAL:
    case WINFRIP_GENERAL_STORE_BACKEND_FILE:
	/* TODO implement */
	return ERROR_INVALID_FUNCTION;
    }
}
Esempio n. 27
0
HRESULT RemoveCOMRegistryEntries()
{
	HKEY hRootKey;
	if ( !RegOpenKeyExA(HKEY_CLASSES_ROOT, "miranda.shlext", 0, KEY_READ, &hRootKey)) {
		// need to delete the subkey before the parent key is deleted under NT/2000/XP
		RegDeleteKeyA(hRootKey, "CLSID");
		// close the key
		RegCloseKey(hRootKey);
		// delete it
		if ( RegDeleteKeyA(HKEY_CLASSES_ROOT, "miranda.shlext") != ERROR_SUCCESS)
			MessageBoxA(0,
				"Unable to delete registry key for 'shlext COM', this key may already be deleted or you may need admin rights.",
				"Problem", MB_ICONERROR);
	}
	if ( !RegOpenKeyExA(HKEY_CLASSES_ROOT, "\\*\\shellex\\ContextMenuHandlers", 0, KEY_ALL_ACCESS, &hRootKey)) {
		if ( RegDeleteKeyA(hRootKey, "miranda.shlext") != ERROR_SUCCESS)
			MessageBoxA(0,
				"Unable to delete registry key for 'File context menu handlers', this key may already be deleted or you may need admin rights.",
				"Problem", MB_ICONERROR);
		RegCloseKey(hRootKey);
	}
	if ( !RegOpenKeyExA(HKEY_CLASSES_ROOT, "Directory\\shellex\\ContextMenuHandlers", 0, KEY_ALL_ACCESS, &hRootKey)) {
		if ( RegDeleteKeyA(hRootKey, "miranda.shlext") != ERROR_SUCCESS)
			MessageBoxA(0,
				"Unable to delete registry key for 'Directory context menu handlers', this key may already be deleted or you may need admin rights.",
				"Problem", MB_ICONERROR);
		RegCloseKey(hRootKey);
	}
	if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", 0, KEY_ALL_ACCESS, &hRootKey)) {
		if ( RegDeleteValueA(hRootKey, "{72013A26-A94C-11d6-8540-A5E62932711D}") != ERROR_SUCCESS) {
			MessageBoxA(0,
				"Unable to delete registry entry for 'Approved context menu handlers', this key may already be deleted or you may need admin rights.",
				"Problem", MB_ICONERROR);
		}
		RegCloseKey(hRootKey);
	}
	return S_OK;
}
Esempio n. 28
0
DWORD
VmAfWinCfgDeleteValue(
    PVMAF_CFG_KEY       pKey,
    PCSTR               pszValue
    )
{
    DWORD dwError = 0;

    if (!pKey || IsNullOrEmptyString(pszValue))
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    dwError = RegDeleteValueA(
                    pKey->hKey,
                    pszValue
                    );
    BAIL_ON_VMAFD_ERROR(dwError);

error:

    return dwError;
}
Esempio n. 29
0
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 );
}
Esempio n. 30
0
static void test_ExitCode(void)
{
    static const char* AeDebug="Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug";
    char test_exe[MAX_PATH];
    DWORD ret;
    HKEY hkey;
    DWORD disposition;
    LPBYTE auto_val=NULL;
    DWORD auto_size, auto_type;
    LPBYTE debugger_val=NULL;
    DWORD debugger_size, debugger_type;

    GetModuleFileNameA(GetModuleHandle(NULL), test_exe, sizeof(test_exe));
    if (GetFileAttributes(test_exe) == INVALID_FILE_ATTRIBUTES)
        strcat(test_exe, ".so");
    if (GetFileAttributesA(test_exe) == INVALID_FILE_ATTRIBUTES)
    {
        ok(0, "could not find the test executable '%s'\n", test_exe);
        return;
    }

    ret=RegCreateKeyExA(HKEY_LOCAL_MACHINE, AeDebug, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &disposition);
    if (ret == ERROR_SUCCESS)
    {
        auto_size=0;
        ret=RegQueryValueExA(hkey, "auto", NULL, &auto_type, NULL, &auto_size);
        if (ret == ERROR_SUCCESS)
        {
            auto_val=HeapAlloc(GetProcessHeap(), 0, auto_size);
            RegQueryValueExA(hkey, "auto", NULL, &auto_type, auto_val, &auto_size);
        }

        debugger_size=0;
        ret=RegQueryValueExA(hkey, "debugger", NULL, &debugger_type, NULL, &debugger_size);
        if (ret == ERROR_SUCCESS)
        {
            debugger_val=HeapAlloc(GetProcessHeap(), 0, debugger_size);
            RegQueryValueExA(hkey, "debugger", NULL, &debugger_type, debugger_val, &debugger_size);
        }
    }
    else if (ret == ERROR_ACCESS_DENIED)
    {
        skip("not enough privileges to change the debugger\n");
        return;
    }
    else if (ret != ERROR_FILE_NOT_FOUND)
    {
        ok(0, "could not open the AeDebug key: %d\n", ret);
        return;
    }

    if (debugger_val && debugger_type == REG_SZ &&
        strstr((char*)debugger_val, "winedbg --auto"))
        crash_and_winedbg(hkey, test_exe);

    crash_and_debug(hkey, test_exe, "dbg,none");
    crash_and_debug(hkey, test_exe, "dbg,event,order");
    crash_and_debug(hkey, test_exe, "dbg,attach,event,code2");
    if (pDebugSetProcessKillOnExit)
        crash_and_debug(hkey, test_exe, "dbg,attach,event,nokill");
    if (pDebugActiveProcessStop)
        crash_and_debug(hkey, test_exe, "dbg,attach,event,detach");

    if (disposition == REG_CREATED_NEW_KEY)
    {
        RegCloseKey(hkey);
        RegDeleteKeyA(HKEY_LOCAL_MACHINE, AeDebug);
    }
    else
    {
        if (auto_val)
        {
            RegSetValueExA(hkey, "auto", 0, auto_type, auto_val, auto_size);
            HeapFree(GetProcessHeap(), 0, auto_val);
        }
        else
            RegDeleteValueA(hkey, "auto");
        if (debugger_val)
        {
            RegSetValueExA(hkey, "debugger", 0, debugger_type, debugger_val, debugger_size);
            HeapFree(GetProcessHeap(), 0, debugger_val);
        }
        else
            RegDeleteValueA(hkey, "debugger");
        RegCloseKey(hkey);
    }
}