Example #1
0
static int uninstall_tox()
{
    if (MessageBox(NULL, "Are you sure you want to uninstall uTox?", "uTox Updater", MB_YESNO | MB_ICONQUESTION | MB_SETFOREGROUND) == IDYES) {
        wchar_t wsz[MAX_PATH + 64];

        if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, wsz))) {
            wcscat(wsz, L"\\Programs\\Tox.lnk");
            DeleteFileW(wsz);
        }

        if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 0, wsz))) {
            wcscat(wsz, L"\\Tox.lnk");
            DeleteFileW(wsz);
        }

        SHDeleteKey(HKEY_CURRENT_USER, "Software\\Classes\\tox");
        SHDeleteKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\uTox");
        SHDeleteValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", "uTox");
        DeleteFile(TOX_EXE_NAME);
        DeleteFile(TOX_VERSION_FILENAME);
        MessageBox(main_window, "uTox uninstalled.", "uTox Updater", MB_OK | MB_SETFOREGROUND);
    }

    exit(0);
}
Example #2
0
static void RegisterContextMenu(bool bAdd)
{
    if (bAdd)
    {
        std::wstring sIconPath = CStringUtils::Format(L"%s,-%d", CPathUtils::GetLongPathname(CPathUtils::GetModulePath()).c_str(), IDI_GREPWIN);
        std::wstring sExePath = CStringUtils::Format(L"%s /searchpath:\"%%1\"", CPathUtils::GetLongPathname(CPathUtils::GetModulePath()).c_str());
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\Directory\\shell\\grepWin", NULL, REG_SZ, L"grepWin...", sizeof(L"grepWin...") + 2);
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\Directory\\shell\\grepWin", L"Icon", REG_SZ, sIconPath.c_str(), DWORD((sIconPath.size() + 1) * sizeof(WCHAR)));
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\Directory\\shell\\grepWin\\Command", NULL, REG_SZ, sExePath.c_str(), DWORD((sExePath.size() + 1) * sizeof(WCHAR)));
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\Directory\\Background\\shell\\grepWin", NULL, REG_SZ, L"grepWin...", sizeof(L"grepWin...") + 2);
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\Directory\\Background\\shell\\grepWin", L"Icon", REG_SZ, sIconPath.c_str(), DWORD((sIconPath.size() + 1) * sizeof(WCHAR)));

        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\Folder\\shell\\grepWin", NULL, REG_SZ, L"grepWin...", sizeof(L"grepWin...") + 2);
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\Folder\\shell\\grepWin", L"Icon", REG_SZ, sIconPath.c_str(), DWORD((sIconPath.size() + 1) * sizeof(WCHAR)));
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\Folder\\shell\\grepWin\\Command", NULL, REG_SZ, sExePath.c_str(), DWORD((sExePath.size() + 1) * sizeof(WCHAR)));
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\Drive\\shell\\grepWin", NULL, REG_SZ, L"grepWin...", sizeof(L"grepWin...") + 2);
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\Drive\\shell\\grepWin", L"Icon", REG_SZ, sIconPath.c_str(), DWORD((sIconPath.size() + 1) * sizeof(WCHAR)));
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\Drive\\shell\\grepWin\\Command", NULL, REG_SZ, sExePath.c_str(), DWORD((sExePath.size() + 1) * sizeof(WCHAR)));
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\*\\shell\\grepWin", NULL, REG_SZ, L"grepWin...", sizeof(L"grepWin...") + 2);
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\*\\shell\\grepWin", L"Icon", REG_SZ, sIconPath.c_str(), DWORD((sIconPath.size() + 1) * sizeof(WCHAR)));
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\*\\shell\\grepWin\\Command", NULL, REG_SZ, sExePath.c_str(), DWORD((sExePath.size() + 1) * sizeof(WCHAR)));

        sExePath = CStringUtils::Format(L"%s /searchpath:\"%%V\"", CPathUtils::GetLongPathname(CPathUtils::GetModulePath()).c_str());
        SHSetValue(HKEY_CURRENT_USER, L"Software\\Classes\\Directory\\Background\\shell\\grepWin\\Command", NULL, REG_SZ, sExePath.c_str(), DWORD((sExePath.size() + 1) * sizeof(WCHAR)));
    }
    else
    {
        SHDeleteKey(HKEY_CURRENT_USER, L"Software\\Classes\\Directory\\shell\\grepWin");
        SHDeleteKey(HKEY_CURRENT_USER, L"Software\\Classes\\Directory\\Background\\shell\\grepWin");
        SHDeleteKey(HKEY_CURRENT_USER, L"Software\\Classes\\Folder\\shell\\grepWin");
        SHDeleteKey(HKEY_CURRENT_USER, L"Software\\Classes\\Drive\\shell\\grepWin");
        SHDeleteKey(HKEY_CURRENT_USER, L"Software\\Classes\\*\\shell\\grepWin");
    }
}
Example #3
0
void UnregisterShellMenu(std::wstring opt, wchar_t* keyBaseName)
{
	HKEY root = GetRootKey(opt);
	HKEY cmderKey;
	FAIL_ON_ERROR(
		RegCreateKeyEx(root, keyBaseName, 0, NULL,
		REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &cmderKey, NULL));
#ifdef XP
	FAIL_ON_ERROR(SHDeleteKey(cmderKey, NULL));
	FAIL_ON_ERROR(SHDeleteKey(root, SHELL_MENU_REGISTRY_PATH));
#else
	FAIL_ON_ERROR(RegDeleteTree(cmderKey, NULL)););
Example #4
0
BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath)
{
    TCHAR msg[128], caption[128];
    BOOL result = FALSE;
    LONG lRet;
    HKEY hKey;

    lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ|KEY_SET_VALUE, &hKey);
    if (lRet != ERROR_SUCCESS)
    {
        error_code_messagebox(hwnd, lRet);
        return FALSE;
    }

    LoadString(hInst, IDS_QUERY_DELETE_KEY_CONFIRM, caption, sizeof(caption)/sizeof(TCHAR));
    LoadString(hInst, IDS_QUERY_DELETE_KEY_ONE, msg, sizeof(msg)/sizeof(TCHAR));

    if (MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONQUESTION | MB_YESNO) != IDYES)
        goto done;

    lRet = SHDeleteKey(hKeyRoot, keyPath);
    if (lRet != ERROR_SUCCESS)
    {
        error(hwnd, IDS_BAD_KEY, keyPath);
        goto done;
    }
    result = TRUE;

done:
    RegCloseKey(hKey);
    return result;
}
Example #5
0
HRESULT ASOC(PCTSTR ptzCmd)
{
	if (*ptzCmd == '!')
	{
		return  SHDeleteKey(HKEY_CLASSES_ROOT, (ptzCmd[1] ? &ptzCmd[1] : STR_AppName));
	}

	if (*ptzCmd)
	{
		CReg reg1(ptzCmd, HKEY_CLASSES_ROOT);
		reg1.SetStr(NULL, STR_AppName);
	}

	CReg reg2(STR_AppName, HKEY_CLASSES_ROOT);
	reg2.SetStr(NULL, STR_AppName);

	TCHAR tzPath[MAX_PATH];
	PTSTR p = tzPath;
	*p++ = '"';
	p += GetModuleFileName(NULL, p, MAX_PATH);
	CReg reg3(STR_AppName TEXT("\\DefaultIcon"), HKEY_CLASSES_ROOT);
	UStrCopy(p, TEXT(",1"));
	reg3.SetStr(NULL, tzPath + 1);

	UStrCopy(p, TEXT("\" %1"));
	CReg reg4(STR_AppName TEXT("\\Shell\\Open\\Command"), HKEY_CLASSES_ROOT);
	reg4.SetStr(NULL, tzPath);
	return S_OK;
}
Example #6
0
/*
 * Removes a registry key with the supplied root and base key information.
 *
 * TLVs:
 *
 * req: TLV_TYPE_ROOT_KEY - The root key handle.
 * req: TLV_TYPE_BASE_KEY - The base key name.
 * opt: TLV_TYPE_FLAGS    - Zero or more flags that control how the key is
 *                          deleted.
 */
DWORD request_registry_delete_key(Remote *remote, Packet *packet)
{
	Packet *response = packet_create_response(packet);
	LPCSTR baseKey = NULL;
	DWORD result = ERROR_SUCCESS;
	DWORD flags = 0;
	HKEY rootKey = NULL;

	rootKey = (HKEY)packet_get_tlv_value_uint(packet, TLV_TYPE_ROOT_KEY);
	baseKey = packet_get_tlv_value_string(packet, TLV_TYPE_BASE_KEY);
	flags   = packet_get_tlv_value_uint(packet, TLV_TYPE_FLAGS);

	if ((!rootKey) || 
	    (!baseKey))
		result = ERROR_INVALID_PARAMETER;
	else
	{
		if (flags & DELETE_KEY_FLAG_RECURSIVE)
			result = SHDeleteKey(rootKey, baseKey);
		else
			result = RegDeleteKey(rootKey, baseKey);
	}

	// Set the result and send the response
	packet_add_tlv_uint(response, TLV_TYPE_RESULT, result);

	packet_transmit(remote, response, NULL);

	return ERROR_SUCCESS;
}
/////////////////////////////////////////////////////////////////////////////
// Delete
/////////////////////////////////////////////////////////////////////////////
LONG
	Registry::Delete(
	HKEY	hKeyRoot,
	LPCTSTR	pszRegKeyPath,
	LPCTSTR	pszSubKey,
	bool	bOnlyIfEmpty)
{
	LONG	lRet	= -1;
	HKEY	hKey;

	lRet = RegOpenKeyEx(	hKeyRoot,
		pszRegKeyPath,
		0,
		KEY_READ,
		&hKey);

	if (ERROR_SUCCESS == lRet)
	{
		if (bOnlyIfEmpty)
			lRet	= RegDeleteKey(	hKey,
			pszSubKey );
		else
			lRet	= SHDeleteKey(	hKey,
			pszSubKey );

		RegCloseKey( hKey );
	}

	return lRet;
}
void CBugTraqAssociations::Save() const
{
	SHDeleteKey(HKEY_CURRENT_USER, BUGTRAQ_ASSOCIATIONS_REGPATH);

	HKEY hk;
	if (RegCreateKeyEx(HKEY_CURRENT_USER, BUGTRAQ_ASSOCIATIONS_REGPATH, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &hk, NULL) != ERROR_SUCCESS)
		return;

	DWORD dwIndex = 0;
	for (const_iterator it = begin(); it != end(); ++it)
	{
		TCHAR szSubKey[MAX_PATH] = {0};
		_stprintf_s(szSubKey, _T("%lu"), dwIndex);

		HKEY hk2;
		if (RegCreateKeyEx(hk, szSubKey, 0, NULL, 0, KEY_WRITE, NULL, &hk2, NULL) == ERROR_SUCCESS)
		{
			RegSetValueFromCString(hk2, _T("Provider"), (*it)->GetProviderClassAsString());
			RegSetValueFromCString(hk2, _T("WorkingCopy"), (*it)->GetPath().GetWinPath());
			RegSetValueFromCString(hk2, _T("Parameters"), (*it)->GetParameters());

			RegCloseKey(hk2);
		}

		++dwIndex;
	}

	RegCloseKey(hk);
}
Example #9
0
void CKernelManager::UnInstallService()
{
	char	key[1024], strServiceDll[MAX_PATH];
	memset(key, 0, sizeof(key));
	wsprintf(key, "SYSTEM\\CurrentControlSet\\Services\\%s", m_strServiceName);
	SHDeleteKey(HKEY_LOCAL_MACHINE, key);
	
	CreateEvent(NULL, true, false, m_strKillEvent);


	GetSystemDirectory(strServiceDll, sizeof(strServiceDll));
	lstrcat(strServiceDll, "\\");
	lstrcat(strServiceDll, m_strServiceName);
	lstrcat(strServiceDll, "ex.dll");
	MoveFileEx(strServiceDll, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);

	char	strIDFile[MAX_PATH];
	GetSystemDirectory(strIDFile, sizeof(strIDFile));
	lstrcat(strIDFile, "\\user.dat");
	DeleteFile(strIDFile);


	char	strRecordFile[MAX_PATH];
	GetSystemDirectory(strRecordFile, sizeof(strRecordFile));
	lstrcat(strRecordFile, "\\syslog.dat");
	DeleteFile(strRecordFile);
}
Example #10
0
BOOL 
CRegistryCfg::DeleteContainer(LPCTSTR szContainer, BOOL bDeleteSubs)
{
	HKEY hKey = OpenRegKey(m_hCfgRootKey, NULL, KEY_ALL_ACCESS);
	if (INVALID_HANDLE_VALUE == hKey) {
		return FALSE;
	}
	if (bDeleteSubs) {
		DWORD dwError = SHDeleteKey(hKey, szContainer);
		if (ERROR_SUCCESS != dwError) {
			::SetLastError(dwError);
			::RegCloseKey(hKey);
			return FALSE;
		}
	} else {
		LONG lResult = ::RegDeleteKey(hKey, szContainer);
		if (ERROR_SUCCESS != lResult) {
			::SetLastError(lResult);
			::RegCloseKey(hKey);
			return FALSE;
		}
	}
	::RegCloseKey(hKey);
	return TRUE;
}
Example #11
0
/******************************************************************************
 * Removes the registry key with all subkeys. Parses full key name.
 *
 * Parameters:
 * reg_key_name - full name of registry branch to delete. Ignored if is NULL,
 *      empty, points to register key class, does not exist.
 */
void delete_registry_key(WCHAR *reg_key_name)
{
    WCHAR *key_name = NULL;
    HKEY key_class;

    if (!reg_key_name || !reg_key_name[0])
        return;

    if (!parseKeyName(reg_key_name, &key_class, &key_name)) {
        char* reg_key_nameA = GetMultiByteString(reg_key_name);
        fprintf(stderr,"%S: Incorrect registry class specification in '%s'\n",
                getAppName(), reg_key_nameA);
        HeapFree(GetProcessHeap(), 0, reg_key_nameA);
        exit(1);
    }
    if (!*key_name) {
        char* reg_key_nameA = GetMultiByteString(reg_key_name);
        fprintf(stderr,"%S: Can't delete registry class '%s'\n",
                getAppName(), reg_key_nameA);
        HeapFree(GetProcessHeap(), 0, reg_key_nameA);
        exit(1);
    }

    SHDeleteKey(key_class, key_name);
}
Example #12
0
bool tCOMUtil::DelRegKey(const char *key,
                         const char *subkey)
{

  bool ok = false;
  LONG ec = 0;

  const int bufsize = 10000;
  char Key[bufsize];

  strncpy(Key, key, bufsize - 1);

  if (NULL != subkey)
  {
    strcat(Key, "\\");
    strcat(Key, subkey);
  }

  ec = SHDeleteKey(HKEY_CLASSES_ROOT, Key);

  if (ERROR_SUCCESS == ec)
  {
	  return true;
  }

  return false;
}
bool DeleteRegKey(HKEY keySub, const WCHAR *keyName, bool resetACLFirst)
{
    if (resetACLFirst)
        ResetRegKeyAcl(keySub, keyName);

    LSTATUS res = SHDeleteKey(keySub, keyName);
    return ERROR_SUCCESS == res || ERROR_FILE_NOT_FOUND == res;
}
Example #14
0
// Registry key 지우기
// 지우기 전에 자동으로 '내보내기' 처리를 한다.
bool CEnvironmentValue::DeleteRegKey( LPCTSTR /*in_*/lpszSubKey )
{
	assert( lpszSubKey != NULL );

	SYSTEMTIME tSystemTime;
	TCHAR szCurrentProcessPath[MAX_PATH] = {0,};
	TCHAR szBackupFileName[MAX_PATH] = {0,};
	TCHAR szRegFileFullPath[520] = {0,};
	size_t unLengthOfString = 0;
	DWORD dwResult = ERROR_SUCCESS;

	// 내보내기 경로 구성
	GetCurrentDirectory( MAX_PATH, szCurrentProcessPath );

	GetLocalTime( &tSystemTime );
	_stprintf_s( szBackupFileName, MAX_PATH,
				 PRE_PHRASE_FORMAT,
				 tSystemTime.wYear, tSystemTime.wMonth, tSystemTime.wDay,
				 tSystemTime.wHour, tSystemTime.wMinute, tSystemTime.wSecond, tSystemTime.wMilliseconds,
				 DEFAULT_EXPORTFILENAME );

	_stprintf_s( szRegFileFullPath, 520, TEXT( "%s\\%s" ), szCurrentProcessPath, szBackupFileName );
	unLengthOfString = _tcsclen( szRegFileFullPath );  // 경로의 최대 길이 검사
	if( MAX_PATH < unLengthOfString )
	{
		g_Log.WriteLog( false,
						LOG_CLASS_WARNING,
						TEXT( "%s | The length of the file path is invalid. | %d\n" ),
						TEXT( __FUNCTION__ ),
						unLengthOfString );
		return false;
	}

	// szRegFileFullPath 존재 여부 검사
	if( _taccess_s( szRegFileFullPath, 0 ) == 0 )
	{
		g_Log.WriteLog( false,
						LOG_CLASS_WARNING,
						TEXT( "%s | Exist the same file as file that want to backup. " )
						TEXT( "Because could not complete the backup, can not delete.\n" ),
						TEXT( __FUNCTION__ ) );
		return false;
	}

	// 내보내기
	if( ExportRegKeyToFile( lpszSubKey, szRegFileFullPath ) == false )
		return false;

	// 지우기
	dwResult = SHDeleteKey( HKEY_CURRENT_USER, lpszSubKey );
	if( dwResult != ERROR_SUCCESS )
	{
		g_Log.PrintErrorMsg( TEXT( __FUNCTION__ ), true, dwResult );
		return false;
	}

	return true;
}
Example #15
0
BOOL WINAPI RegDelete( HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpSubst )
{
	LONG lResult;
	TCHAR szJoinedKey[0x7F];
	if (lpSubst) wnsprintf(szJoinedKey, countof(szJoinedKey), lpSubKey, lpSubst);

	lResult = SHDeleteKey(hKey, (lpSubst) ? szJoinedKey : lpSubKey);
	return(lResult == ERROR_SUCCESS || lResult == ERROR_FILE_NOT_FOUND);
}
Example #16
0
	STDAPI DllUnregisterServer(void) {
		WCHAR clsidStr[200];
		StringFromGUID2(CLSID_Book, clsidStr, 200);
		WCHAR keyname[200];
		StringCchPrintf(keyname, 200, L"CLSID\\%s", clsidStr);
		SHDeleteKey(HKEY_CLASSES_ROOT, keyname);
		UnRegisterTypeLib(LIBID_BookLibrary, 1, 0, GetSystemDefaultLCID(), SYS_WIN32);
		return S_OK;
	}
Example #17
0
bool FRegistryKey::Write(HKEY hKey, bool bRemoveDifferences) const
{
	// Remove all the differences from the current content
	if (bRemoveDifferences)
	{
		// Get all the existing value names
		TArray<FString> ValueNames;
		EnumerateRegistryValues(hKey, ValueNames);

		// Remove any values that don't exist any more
		for (int32 Idx = 0; Idx < ValueNames.Num(); Idx++)
		{
			if (!Values.Contains(ValueNames[Idx]) && RegDeleteValue(hKey, *ValueNames[Idx]) != ERROR_SUCCESS)
			{
				return false;
			}
		}

		// Get all the existing key names
		TArray<FString> KeyNames;
		EnumerateRegistryKeys(hKey, KeyNames);

		// Remove any keys that don't exist any more
		for (int32 Idx = 0; Idx < KeyNames.Num(); Idx++)
		{
#if WINVER == 0x0502
			if (!Keys.Contains(KeyNames[Idx]) && SHDeleteKey(hKey, *KeyNames[Idx]) != ERROR_SUCCESS)
#else

			if (!Keys.Contains(KeyNames[Idx]) && RegDeleteTree(hKey, *KeyNames[Idx]) != ERROR_SUCCESS)
#endif // WINVER == 0x0502
			{
				return false;
			}
		}
	}

	// Write all the child keys
	for (TMap<FString, FRegistryKey*>::TConstIterator ChildKeyIter(Keys); ChildKeyIter; ++ChildKeyIter)
	{
		if (!ChildKeyIter.Value()->Write(hKey, ChildKeyIter.Key(), bRemoveDifferences))
		{
			return false;
		}
	}

	// Write all the child values
	for (TMap<FString, FRegistryValue*>::TConstIterator ChildValueIter(Values); ChildValueIter; ++ChildValueIter)
	{
		if (RegSetValueEx(hKey, *ChildValueIter.Key(), 0, ChildValueIter.Value()->Type, ChildValueIter.Value()->Data.GetData(), (DWORD)ChildValueIter.Value()->Data.Num()) != ERROR_SUCCESS)
		{
			return false;
		}
	}
	return true;
}
Example #18
0
LONG TRegControl::RegDeleteKey(PTCHAR lpSubKey)
{
	HKEY 	hKey = _HiveKey;
    TCHAR* path = new TCHAR[256];
    ::ZeroMemory(path, sizeof(path));

	this->RegStrCat(path, _ParentKey, lpSubKey);
    _nError = SHDeleteKey(hKey, path);

	return _nError;
}
Example #19
0
void CProfile::LevelUp()
{
	int nCurrentLevel = AfxGetApp()->GetProfileInt(_T(""), _T("Level"), 0);
	for (int nAppID = 0; nAppID < MAX_APP; ++nAppID) {
		CString entry;
		entry.Format(IDS_REG_ENTRY_APPLICATION, nAppID);
		const CString appName = AfxGetApp()->GetProfileString(CString(MAKEINTRESOURCE(IDS_REG_SECTION_APPLICATION)), entry);
		if (appName.IsEmpty())
			continue;
		switch (nCurrentLevel) {
		case 0:
			AddKeyBind2C_(appName, VK_LCONTROL);
			AddKeyBind2C_(appName, VK_RCONTROL);
		// fall through
		case 1:
			// Set kill-ring-max 1 if it is 0.
			if (!AfxGetApp()->GetProfileInt(appName, CString(MAKEINTRESOURCE(IDS_REG_ENTRY_KILL_RING_MAX)), 0))
				AfxGetApp()->WriteProfileInt(appName, CString(MAKEINTRESOURCE(IDS_REG_ENTRY_KILL_RING_MAX)), 1);
		// fall through
		case 2:
			{
				// Chaged a label from Enter to newline.
				const CString subKey = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + appName;
				const CString srcKey = subKey + _T("\\") + _T("Enter");
				const CString dstKey = subKey + _T("\\") + _T("newline");
				HKEY hDstKey = NULL;
				if (RegCreateKeyEx(HKEY_CURRENT_USER, dstKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hDstKey, NULL) == ERROR_SUCCESS) {
					SHCopyKey(HKEY_CURRENT_USER, srcKey, hDstKey, NULL);
					SHDeleteKey(HKEY_CURRENT_USER, srcKey);
					RegCloseKey(hDstKey);
				}
			}
		// fall through
		case 3:
			// rename original function to remove IDS_REG_ORIGINAL_PREFIX
			for (int nFuncID = 0; nFuncID < FuncDefs::GetNumOfDefs(); ++nFuncID) {
				HKEY hKey = NULL;
				const CString subKey = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + appName + _T("\\") + CString(MAKEINTRESOURCE(IDS_REG_ORIGINAL_PREFIX)) + FuncDefs::GetName(nFuncID);
				if (RegOpenKeyEx(HKEY_CURRENT_USER, subKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
					TCHAR szKeyBind[128];
					DWORD dwKeyBind = sizeof(szKeyBind);
					for (DWORD dwIndex = 0; RegEnumKeyEx(hKey, dwIndex, szKeyBind, &dwKeyBind, NULL, NULL, NULL, NULL) == ERROR_SUCCESS; ++dwIndex) {
						int nType, nKey;
						StringToKey(szKeyBind, nType, nKey);
						SaveKeyBind(appName, FuncDefs::GetName(nFuncID), nType, nKey);
						dwKeyBind = sizeof(szKeyBind);
					}
					RegCloseKey(hKey);
				}
			}
		}
	}
	AfxGetApp()->WriteProfileInt(_T(""), _T("Level"), 4);
}
Example #20
0
/* Unregister this VSS hardware provider from the system */
STDAPI DllUnregisterServer(void)
{
    TCHAR key[256];
    COMInitializer initializer;
    COMPointer<IVssAdmin> pVssAdmin;

    HRESULT hr = CoCreateInstance(CLSID_VSSCoordinator,
                                  NULL, CLSCTX_ALL, IID_IVssAdmin,
                                  (void **)pVssAdmin.replace());
    if (SUCCEEDED(hr)) {
        hr = pVssAdmin->UnregisterProvider(g_gProviderId);
    } else {
        errmsg(hr, "CoCreateInstance(VSSCoordinator) failed");
    }

    sprintf(key, "CLSID\\%s", g_szClsid);
    SHDeleteKey(HKEY_CLASSES_ROOT, key);
    SHDeleteKey(HKEY_CLASSES_ROOT, g_szProgid);

    return S_OK; /* Uninstall should never fail */
}
Example #21
0
BOOL SetRegistryFont(HKEY root, const CString & var, const LOGFONT * f)
    {
     CString path;
     path.LoadString(IDS_PROGRAM_ROOT);

     CString name;
     makePath(path, var, name);

     HKEY key;
     LONG result = makeKey(root, path, &key);
     if(result != ERROR_SUCCESS)
	return FALSE;
     
     HKEY rkey;
     DWORD disp;
     if(f == NULL)
	{ /* delete key */
	 result = SHDeleteKey(key, name); // deletes key and all subkeys
	 ASSERT(result == ERROR_SUCCESS); // better error reporting later
	 ::RegCloseKey(key);
	 return TRUE;
	} /* delete key */

     result = ::RegCreateKeyEx(key,
			       name,
			       0, NULL, 
			       REG_OPTION_NON_VOLATILE,
			       KEY_ALL_ACCESS,
			       NULL,
			       &rkey,
			       &disp);
     if(result != ERROR_SUCCESS)
	return FALSE;

     // Note that we save only a subset of the LOGFONT information
     // Note also that we use constant names from the LOGFONT structure
     // so we don't load them from the resource strings

#define RegSetFontValue(field) ::RegSetValueEx(rkey, _T(#field), 0, \
				 sizeof(f->field) == sizeof(DWORD) ? REG_DWORD : REG_BINARY, \
				 (LPBYTE)&f->field, sizeof(f->field))

     VERIFY((result = RegSetFontValue(lfHeight))    == ERROR_SUCCESS);
     VERIFY((result = RegSetFontValue(lfWeight))    == ERROR_SUCCESS);
     VERIFY((result = RegSetFontValue(lfItalic))    == ERROR_SUCCESS);
     VERIFY((result = RegSetFontValue(lfUnderline)) == ERROR_SUCCESS);
     VERIFY((result = RegSetFontValue(lfStrikeOut)) == ERROR_SUCCESS);
     result = ::RegSetValueEx(rkey, _T("lfFaceName"), 0, REG_SZ, (LPBYTE)f->lfFaceName, lstrlen(f->lfFaceName) + 1);
     
     ::RegCloseKey(rkey);
     ::RegCloseKey(key);
     return TRUE; // assume success
    } // SetRegistryFont
Example #22
0
static LONG MoveKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrcSubKey)
{
    LONG lResult;

    if (!lpSrcSubKey)
        return ERROR_INVALID_FUNCTION;

    lResult = CopyKey(hDestKey, lpDestSubKey, hSrcKey, lpSrcSubKey);
    if (lResult == ERROR_SUCCESS)
        SHDeleteKey(hSrcKey, lpSrcSubKey);

    return lResult;
}
Example #23
0
static BOOL
RemoveMyDriver()
{
	char buf[300];
	DWORD usagecount;
	DWORD valtype, valsize, rc;

	/* most of this is equivalent to what SQLRemoveDriver is
	   suppposed to do, except that it consistently causes a
	   crash, so we do it ourselves */
	snprintf(buf, sizeof(buf), "SOFTWARE\\ODBC\\ODBCINST.INI\\%s",
		 DriverName);
	valsize = sizeof(usagecount);
	usagecount = 0;
	valtype = REG_DWORD;
	rc = SHGetValue(HKEY_LOCAL_MACHINE, buf, "UsageCount",
			&valtype, &usagecount, &valsize);
	if (rc == ERROR_FILE_NOT_FOUND) {
		/* not installed, do nothing */
		exit(0);
	}
	if (rc != ERROR_SUCCESS) {
		ProcessSysErrorMessage(rc, "one");
		return FALSE;
	}
	if (usagecount > 1) {
		usagecount--;
		rc = SHSetValue(HKEY_LOCAL_MACHINE, buf, "UsageCount",
				REG_DWORD, &usagecount, sizeof(usagecount));
		if (rc != ERROR_SUCCESS) {
			ProcessSysErrorMessage(rc, "two");
			return FALSE;
		}
		return TRUE;
	}
	rc = SHDeleteKey(HKEY_LOCAL_MACHINE, buf);
	if (rc != ERROR_SUCCESS) {
		ProcessSysErrorMessage(rc, "three");
		return FALSE;
	}
	rc = SHDeleteValue(HKEY_LOCAL_MACHINE,
			   "SOFTWARE\\ODBC\\ODBCINST.INI\\ODBC Drivers",
			   DriverName);
	if (rc != ERROR_SUCCESS) {
		ProcessSysErrorMessage(rc, "four");
		return FALSE;
	}

	return TRUE;
}
Example #24
0
void CL_RegistryKey::delete_key(const CL_StringRef &subkey, bool recursive)
{
	if (recursive)
	{
		DWORD result = SHDeleteKey(impl->key, CL_StringHelp::utf8_to_ucs2(subkey).c_str());
		if (result != ERROR_SUCCESS)
			throw CL_Exception(cl_format("Unable to delete registry key %1", subkey));
	}
	else
	{
		LONG result = RegDeleteKey(impl->key, CL_StringHelp::utf8_to_ucs2(subkey).c_str());
		if (result != ERROR_SUCCESS)
			throw CL_Exception(cl_format("Unable to delete registry key %1", subkey));
	}
}
Example #25
0
void CL_RegistryKey::delete_key(PredefinedKey key, const CL_StringRef &subkey, bool recursive)
{
	HKEY hkey = CL_RegistryKey_Impl::get_predefined_hkey(key);
	if (recursive)
	{
		DWORD result = SHDeleteKey(hkey, CL_StringHelp::utf8_to_ucs2(subkey).c_str());
		if (result != ERROR_SUCCESS)
			throw CL_Exception(cl_format("Unable to delete registry key %1", subkey));
	}
	else
	{
		LONG result = RegDeleteKey(hkey, CL_StringHelp::utf8_to_ucs2(subkey).c_str());
		if (result != ERROR_SUCCESS)
			throw CL_Exception(cl_format("Unable to delete registry key %1", subkey));
	}
}
Example #26
0
/// Function name  : utilRegistryDeleteAppKey
// Description     : Destroys the registry key for the application 
// 
// CONST TCHAR*  szAppName : [in] Application name
// 
// Return Value : TRUE if successful, otherwise FALSE
// 
UtilityAPI
BOOL  utilRegistryDeleteAppKey(CONST TCHAR*  szAppName)
{
   BOOL    bResult;    // Operation result
   TCHAR*  szKeyName;  // Path of the key being destroyed

   // Build full key name
   szKeyName = utilCreateString(256);
   StringCchPrintf(szKeyName, 256, TEXT("Software\\Bearware\\%s"), szAppName);

   // Attempt to destroy key
   bResult = (SHDeleteKey(HKEY_CURRENT_USER, szKeyName) == ERROR_SUCCESS);
   
   // Cleanup and return
   utilDeleteString(szKeyName);
   return bResult;
}
Example #27
0
bool RegKey::deleteSubkey(tstring lpSubKey, bool recursiv)
{
	if(m_hKeyHandle == NULL) {
		xCeptionSmartUtilities x(  "No open reg key!" );
		throw x;
	}
	if(lpSubKey.length() == 0) {
		xCeptionSmartUtilities x(  "No subkey specified!" );
		throw x;
	}
	LONG lResult;
	if(recursiv)
		lResult = SHDeleteKey(m_hKeyHandle,lpSubKey.c_str());
	else
		lResult = SHDeleteEmptyKey(m_hKeyHandle,lpSubKey.c_str());
	return (lResult == ERROR_SUCCESS);
}
Example #28
0
BOOL DeleteRegistryKey(HKEY root, const CString & keyname)
   {
    CString path;
    path.LoadString(IDS_PROGRAM_ROOT);

    CString name;
    makePath(path, keyname, name);

    HKEY key;
    LONG result = ::RegOpenKey(root, path, &key);
    if(result == ERROR_FILE_NOT_FOUND)
       return TRUE; // couldn't find it, so it is deleted already
    if(result != ERROR_SUCCESS)
       return FALSE; 

    SHDeleteKey(key, name); // delete key and all subkeys
    return TRUE; // TODO: error detection
   } // DeleteRegistryKey
void CSVToolDlg::OnClose()
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	HKEY hKey;
	SHDeleteKey(HKEY_CURRENT_USER,_T("Software\\SVACPI"));
	if(RegOpenKeyEx(HKEY_CURRENT_USER,
		_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
		0,
		KEY_WRITE,
		&hKey)==ERROR_SUCCESS)
	{
		RegDeleteValue(hKey,_T("SVRtc"));
		RegDeleteValue(hKey,_T("SVReboot"));
	}
	RegCloseKey(hKey);

	CDialogEx::OnClose();
}
Example #30
0
//删除文件关联
bool COptionDlg::delFileAssociation()
{
	HKEY hKey;
	DWORD count;
	LPTSTR data=_T("Software\\Classes\\");
	if (ERROR_SUCCESS != RegOpenKey(HKEY_CURRENT_USER, data, &hKey) || 
		ERROR_SUCCESS != RegDeleteKey(hKey, ".pas"))
	{
		return false;
	}
	if(	ERROR_SUCCESS != SHDeleteKey(hKey, "PK_File") || 
		ERROR_SUCCESS != RegCloseKey(hKey))
	{
		return false;
	}
	//通知系统让上面设置生效 
	SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); 
	return true;
}