Example #1
0
static BOOL UnloadHive(HWND hWnd)
{
    TCHAR Caption[128];
    LPCTSTR pszKeyPath;
    HKEY hRootKey;
    LONG regUnloadResult;

    /* get the item key to unload */
    pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
    /* load and set the caption and flags for dialog */
    LoadString(hInst, IDS_UNLOAD_HIVE, Caption, COUNT_OF(Caption));
    /* now unload the hive */
    regUnloadResult = RegUnLoadKey(hRootKey, pszKeyPath);
    if(regUnloadResult == ERROR_SUCCESS)
    {
        /* refresh tree and list views */
        RefreshTreeView(g_pChildWnd->hTreeWnd);
        pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
        RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath);
    }
    else
    {
        ErrorMessageBox(hWnd, Caption, regUnloadResult);
        return FALSE;
    }
    return TRUE;
}
Example #2
0
static BOOL UnloadHive(HWND hWnd)
{
    WCHAR Caption[128];
    LPCWSTR pszKeyPath;
    HKEY hRootKey;
    LONG regUnloadResult;

    /* get the item key to unload */
    pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
    /* load and set the caption and flags for dialog */
    LoadStringW(hInst, IDS_UNLOAD_HIVE, Caption, COUNT_OF(Caption));

    /* Enable the 'restore' privilege, unload the hive, disable the privilege */
    EnablePrivilege(SE_RESTORE_NAME, NULL, TRUE);
    regUnloadResult = RegUnLoadKeyW(hRootKey, pszKeyPath);
    EnablePrivilege(SE_RESTORE_NAME, NULL, FALSE);

    if(regUnloadResult == ERROR_SUCCESS)
    {
        /* refresh tree and list views */
        RefreshTreeView(g_pChildWnd->hTreeWnd);
        pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
        RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath);
    }
    else
    {
        ErrorMessageBox(hWnd, Caption, regUnloadResult);
        return FALSE;
    }
    return TRUE;
}
Example #3
0
static BOOL LoadHive(HWND hWnd)
{
    OPENFILENAME ofn;
    WCHAR Caption[128];
    LPCWSTR pszKeyPath;
    WCHAR xPath[LOADHIVE_KEYNAMELENGTH];
    HKEY hRootKey;
    WCHAR Filter[1024];
    FILTERPAIR filter;
    /* get the item key to load the hive in */
    pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
    /* initialize the "open file" dialog */
    InitOpenFileName(hWnd, &ofn);
    /* build the "All Files" filter up */
    filter.DisplayID = IDS_FLT_ALLFILES;
    filter.FilterID = IDS_FLT_ALLFILES_FLT;
    BuildFilterStrings(Filter, &filter, 1);
    ofn.lpstrFilter = Filter;
    /* load and set the caption and flags for dialog */
    LoadStringW(hInst, IDS_LOAD_HIVE, Caption, COUNT_OF(Caption));
    ofn.lpstrTitle = Caption;
    ofn.Flags |= OFN_ENABLESIZING;
    /*    ofn.lCustData = ;*/
    /* now load the hive */
    if (GetOpenFileName(&ofn))
    {
        if (DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_LOADHIVE), hWnd,
                            &LoadHive_KeyNameInHookProc, (LPARAM)xPath))
        {
            LONG regLoadResult;

            /* Enable the 'restore' privilege, load the hive, disable the privilege */
            EnablePrivilege(SE_RESTORE_NAME, NULL, TRUE);
            regLoadResult = RegLoadKeyW(hRootKey, xPath, ofn.lpstrFile);
            EnablePrivilege(SE_RESTORE_NAME, NULL, FALSE);

            if(regLoadResult == ERROR_SUCCESS)
            {
                /* refresh tree and list views */
                RefreshTreeView(g_pChildWnd->hTreeWnd);
                pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
                RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath);
            }
            else
            {
                ErrorMessageBox(hWnd, Caption, regLoadResult);
                return FALSE;
            }
        }
    }
    else
    {
        CheckCommDlgError(hWnd);
    }
    return TRUE;
}
Example #4
0
UINT WinSpyDlg_ExitSizeMove(HWND hwnd)
{
	RECT rect;
	UINT uLayout;
	HWND hwndTree;
	HTREEITEM hItem;

	static UINT uOldLayout = WINSPY_MINIMIZED;


	GetWindowRect(hwnd, &rect);

	szCurrent.cx = GetRectWidth(&rect);
	szCurrent.cy = GetRectHeight(&rect);

	fyMaxed = (szCurrent.cy > szMinimized.cy);
	fxMaxed = (szCurrent.cx >= szExpanded.cx);

	if (fyMaxed == FALSE)
	{
		uLayout = WINSPY_MINIMIZED;
	}
	else
	{
		if (fxMaxed)
			uLayout = WINSPY_EXPANDED;
		else
			uLayout = WINSPY_NORMAL;

		szLastMax = szCurrent;
	}

	SetSysMenuIconFromLayout(hwnd, uLayout);

	if (uLayout == WINSPY_EXPANDED && uOldLayout != WINSPY_EXPANDED)
	{
		hwndTree = GetDlgItem(hwnd, IDC_TREE1);

		RefreshTreeView(hwndTree);
		hItem = FindTreeItemByHwnd(hwndTree, spy_hCurWnd, NULL);
		if (hItem)
		{
			// Move it into view!
			SendMessage(hwndTree, TVM_ENSUREVISIBLE, 0, (LPARAM)hItem);
			SendMessage(hwndTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem);
		}
	}

	GetPinnedPosition(hwnd, &ptPinPos);

	uOldLayout = uLayout;

	return 0;
}
Example #5
0
static BOOL ImportRegistryFile(HWND hWnd)
{
    OPENFILENAME ofn;
    TCHAR Caption[128], szTitle[256], szText[256];
    LPCTSTR pszKeyPath;
    HKEY hRootKey;

    InitOpenFileName(hWnd, &ofn);
    LoadString(hInst, IDS_IMPORT_REG_FILE, Caption, COUNT_OF(Caption));
    ofn.lpstrTitle = Caption;
    ofn.Flags |= OFN_ENABLESIZING;
    /*    ofn.lCustData = ;*/
    if (GetOpenFileName(&ofn))
    {
        FILE *fp = _wfopen(ofn.lpstrFile, L"r");
        if (fp == NULL || !import_registry_file(fp))
        {
            LPSTR p = GetMultiByteString(ofn.lpstrFile);
            fprintf(stderr, "Can't open file \"%s\"\n", p);
            HeapFree(GetProcessHeap(), 0, p);
            if (fp != NULL)
                fclose(fp);
            return FALSE;
        }
        LoadString(hInst, IDS_APP_TITLE, szTitle, sizeof(szTitle));
        LoadString(hInst, IDS_IMPORTED_OK, szText, sizeof(szTitle));
        /* show successful import */
        MessageBox(NULL, szText, szTitle, MB_OK);
        fclose(fp);
    }
    else
    {
        CheckCommDlgError(hWnd);
    }

    RefreshTreeView(g_pChildWnd->hTreeWnd);
    pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
    RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath);

    return TRUE;
}
Example #6
0
/*******************************************************************************
 *
 *  FUNCTION: _CmdWndProc(HWND, unsigned, WORD, LONG)
 *
 *  PURPOSE:  Processes WM_COMMAND messages for the main frame window.
 *
 */
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HKEY hKeyRoot = 0, hKey = 0;
    LPCTSTR keyPath;
    LPCTSTR valueName;
    BOOL result = TRUE;
    REGSAM regsam = KEY_READ;
    LONG lRet;
    int item;

    UNREFERENCED_PARAMETER(lParam);
    UNREFERENCED_PARAMETER(message);

    switch (LOWORD(wParam))
    {
    case ID_REGISTRY_LOADHIVE:
        LoadHive(hWnd);
        return TRUE;
    case ID_REGISTRY_UNLOADHIVE:
        UnloadHive(hWnd);
        return TRUE;
    case ID_REGISTRY_IMPORTREGISTRYFILE:
        ImportRegistryFile(hWnd);
        return TRUE;
    case ID_REGISTRY_EXPORTREGISTRYFILE:
        ExportRegistryFile(hWnd);
        return TRUE;
    case ID_REGISTRY_CONNECTNETWORKREGISTRY:
    {
        IDsObjectPicker *ObjectPicker;
        TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
        HRESULT hRet;

        hRet = CoInitialize(NULL);
        if (SUCCEEDED(hRet))
        {
            hRet = InitializeRemoteRegistryPicker(&ObjectPicker);
            if (SUCCEEDED(hRet))
            {
                hRet = InvokeRemoteRegistryPickerDialog(ObjectPicker,
                                                        hWnd,
                                                        szComputerName,
                                                        sizeof(szComputerName) / sizeof(szComputerName[0]));
                if (hRet == S_OK)
                {
                    /* FIXME - connect to the registry */
                }

                FreeObjectPicker(ObjectPicker);
            }

            CoUninitialize();
        }

        return TRUE;
    }
    case ID_REGISTRY_DISCONNECTNETWORKREGISTRY:
        return TRUE;
    case ID_REGISTRY_PRINT:
        PrintRegistryHive(hWnd, _T(""));
        return TRUE;
    case ID_REGISTRY_EXIT:
        DestroyWindow(hWnd);
        return TRUE;
    case ID_VIEW_STATUSBAR:
        toggle_child(hWnd, LOWORD(wParam), hStatusBar);
        return TRUE;
    case ID_HELP_HELPTOPICS:
        WinHelp(hWnd, _T("regedit"), HELP_FINDER, 0);
        return TRUE;
    case ID_HELP_ABOUT:
        ShowAboutBox(hWnd);
        return TRUE;
    case ID_VIEW_SPLIT:
    {
        RECT rt;
        POINT pt, pts;
        GetClientRect(g_pChildWnd->hWnd, &rt);
        pt.x = rt.left + g_pChildWnd->nSplitPos;
        pt.y = (rt.bottom / 2);
        pts = pt;
        if(ClientToScreen(g_pChildWnd->hWnd, &pts))
        {
            SetCursorPos(pts.x, pts.y);
            SetCursor(LoadCursor(0, IDC_SIZEWE));
            SendMessage(g_pChildWnd->hWnd, WM_LBUTTONDOWN, 0, MAKELPARAM(pt.x, pt.y));
        }
        return TRUE;
    }
    case ID_EDIT_RENAME:
    case ID_EDIT_MODIFY:
    case ID_EDIT_MODIFY_BIN:
    case ID_EDIT_DELETE:
        regsam |= KEY_WRITE;
        break;
    }

    keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
    valueName = GetValueName(g_pChildWnd->hListWnd, -1);
    if (keyPath)
    {
        lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, regsam, &hKey);
        if (lRet != ERROR_SUCCESS) hKey = 0;
    }

    switch (LOWORD(wParam))
    {
    case ID_EDIT_MODIFY:
        if (valueName && ModifyValue(hWnd, hKey, valueName, FALSE))
            RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
        break;
    case ID_EDIT_MODIFY_BIN:
        if (valueName && ModifyValue(hWnd, hKey, valueName, TRUE))
            RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
        break;
    case ID_EDIT_RENAME:
        if (GetFocus() == g_pChildWnd->hListWnd)
        {
            if(ListView_GetSelectedCount(g_pChildWnd->hListWnd) == 1)
            {
                item = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_SELECTED);
                if(item > -1)
                {
                    (void)ListView_EditLabel(g_pChildWnd->hListWnd, item);
                }
            }
        }
        else if (GetFocus() == g_pChildWnd->hTreeWnd)
        {
            /* Get focused entry of treeview (if any) */
            HTREEITEM hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd);
            if (hItem != NULL)
                (void)TreeView_EditLabel(g_pChildWnd->hTreeWnd, hItem);
        }
        break;
    case ID_EDIT_DELETE:
    {
        if (GetFocus() == g_pChildWnd->hListWnd)
        {
            UINT nSelected = ListView_GetSelectedCount(g_pChildWnd->hListWnd);
            if(nSelected >= 1)
            {
                TCHAR msg[128], caption[128];
                LoadString(hInst, IDS_QUERY_DELETE_CONFIRM, caption, sizeof(caption)/sizeof(TCHAR));
                LoadString(hInst, (nSelected == 1 ? IDS_QUERY_DELETE_ONE : IDS_QUERY_DELETE_MORE), msg, sizeof(msg)/sizeof(TCHAR));
                if(MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONQUESTION | MB_YESNO) == IDYES)
                {
                    int ni, errs;

                    item = -1;
                    errs = 0;
                    while((ni = ListView_GetNextItem(g_pChildWnd->hListWnd, item, LVNI_SELECTED)) > -1)
                    {
                        valueName = GetValueName(g_pChildWnd->hListWnd, item);
                        if(RegDeleteValue(hKey, valueName) != ERROR_SUCCESS)
                        {
                            errs++;
                        }
                        item = ni;
                    }

                    RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
                    if(errs > 0)
                    {
                        LoadString(hInst, IDS_ERR_DELVAL_CAPTION, caption, sizeof(caption)/sizeof(TCHAR));
                        LoadString(hInst, IDS_ERR_DELETEVALUE, msg, sizeof(msg)/sizeof(TCHAR));
                        MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONSTOP);
                    }
                }
            }
        }
        else if (GetFocus() == g_pChildWnd->hTreeWnd)
        {
            if (keyPath == 0 || *keyPath == 0)
            {
                MessageBeep(MB_ICONHAND);
            }
            else if (DeleteKey(hWnd, hKeyRoot, keyPath))
            {
                DeleteNode(g_pChildWnd->hTreeWnd, 0);
                RefreshTreeView(g_pChildWnd->hTreeWnd);
            }
        }
        break;
    }
    case ID_EDIT_NEW_STRINGVALUE:
        CreateNewValue(hKeyRoot, keyPath, REG_SZ);
        break;
    case ID_EDIT_NEW_BINARYVALUE:
        CreateNewValue(hKeyRoot, keyPath, REG_BINARY);
        break;
    case ID_EDIT_NEW_DWORDVALUE:
        CreateNewValue(hKeyRoot, keyPath, REG_DWORD);
        break;
    case ID_EDIT_NEW_MULTISTRINGVALUE:
        CreateNewValue(hKeyRoot, keyPath, REG_MULTI_SZ);
        break;
    case ID_EDIT_NEW_EXPANDABLESTRINGVALUE:
        CreateNewValue(hKeyRoot, keyPath, REG_EXPAND_SZ);
        break;
    case ID_EDIT_FIND:
        FindDialog(hWnd);
        break;
    case ID_EDIT_FINDNEXT:
        FindNext(hWnd);
        break;
    case ID_EDIT_COPYKEYNAME:
        CopyKeyName(hWnd, hKeyRoot, keyPath);
        break;
    case ID_EDIT_PERMISSIONS:
        RegKeyEditPermissions(hWnd, hKeyRoot, NULL, keyPath);
        break;
    case ID_REGISTRY_PRINTERSETUP:
        /*PRINTDLG pd;*/
        /*PrintDlg(&pd);*/
        /*PAGESETUPDLG psd;*/
        /*PageSetupDlg(&psd);*/
        break;
    case ID_REGISTRY_OPENLOCAL:
        break;

    case ID_VIEW_REFRESH:
        RefreshTreeView(g_pChildWnd->hTreeWnd);
        /*RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); */
        break;
        /*case ID_OPTIONS_TOOLBAR:*/
        /*	toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
        /*    break;*/
    case ID_EDIT_NEW_KEY:
        CreateNewKey(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd));
        break;
    default:
        if ((LOWORD(wParam) >= ID_FAVORITES_MIN) && (LOWORD(wParam) <= ID_FAVORITES_MAX))
        {
            HMENU hMenu;
            MENUITEMINFO mii;
            TCHAR szFavorite[512];

            hMenu = GetSubMenu(GetMenu(hWnd), FAVORITES_MENU_POSITION);

            memset(&mii, 0, sizeof(mii));
            mii.cbSize = sizeof(mii);
            mii.fMask = MIIM_TYPE;
            mii.fType = MFT_STRING;
            mii.dwTypeData = szFavorite;
            mii.cch = sizeof(szFavorite) / sizeof(szFavorite[0]);

            if (GetMenuItemInfo(hMenu, LOWORD(wParam) - ID_FAVORITES_MIN, TRUE, &mii))
            {
                ChooseFavorite(szFavorite);
            }
        }
        else
        {
            result = FALSE;
        }
        break;
    }

    if(hKey)
        RegCloseKey(hKey);
    return result;
}
Example #7
0
static BOOL ImportRegistryFile(HWND hWnd)
{
    BOOL bRet = FALSE;
    OPENFILENAME ofn;
    WCHAR Caption[128], szTitle[512], szText[512];
    HKEY hKeyRoot;
    LPCWSTR pszKeyPath;

    /* Figure out in which key path we are importing */
    pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);

    InitOpenFileName(hWnd, &ofn);
    LoadStringW(hInst, IDS_IMPORT_REG_FILE, Caption, COUNT_OF(Caption));
    ofn.lpstrTitle = Caption;
    ofn.Flags |= OFN_ENABLESIZING;
    /*    ofn.lCustData = ;*/
    if (GetOpenFileName(&ofn))
    {
        /* Look at the extension of the file to determine its type */
        if (ofn.nFileExtension >= 1 &&
            _wcsicmp(ofn.lpstrFile + ofn.nFileExtension, L"reg") == 0) /* REGEDIT4 or Windows Registry Editor Version 5.00 */
        {
            /* Open the file */
            FILE* fp = _wfopen(ofn.lpstrFile, L"r");

            /* Import it */
            if (fp == NULL || !import_registry_file(fp))
            {
                /* Error opening the file */
                LoadStringW(hInst, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
                LoadStringW(hInst, IDS_IMPORT_ERROR, szText, COUNT_OF(szText));
                InfoMessageBox(hWnd, MB_OK | MB_ICONERROR, szTitle, szText, ofn.lpstrFile);
                bRet = FALSE;
            }
            else
            {
                /* Show successful import */
                LoadStringW(hInst, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
                LoadStringW(hInst, IDS_IMPORT_OK, szText, COUNT_OF(szText));
                InfoMessageBox(hWnd, MB_OK | MB_ICONINFORMATION, szTitle, szText, ofn.lpstrFile);
                bRet = TRUE;
            }

            /* Close the file */
            if (fp) fclose(fp);
        }
        else /* Registry Hive Files */
        {
            LoadStringW(hInst, IDS_QUERY_IMPORT_HIVE_CAPTION, szTitle, COUNT_OF(szTitle));
            LoadStringW(hInst, IDS_QUERY_IMPORT_HIVE_MSG, szText, COUNT_OF(szText));

            /* Display a confirmation message */
            if (MessageBoxW(g_pChildWnd->hWnd, szText, szTitle, MB_ICONWARNING | MB_YESNO) == IDYES)
            {
                LONG lResult;
                HKEY hSubKey;

                /* Open the subkey */
                lResult = RegOpenKeyExW(hKeyRoot, pszKeyPath, 0, KEY_WRITE, &hSubKey);
                if (lResult == ERROR_SUCCESS)
                {
                    /* Enable the 'restore' privilege, restore the hive then disable the privilege */
                    EnablePrivilege(SE_RESTORE_NAME, NULL, TRUE);
                    lResult = RegRestoreKey(hSubKey, ofn.lpstrFile, REG_FORCE_RESTORE);
                    EnablePrivilege(SE_RESTORE_NAME, NULL, FALSE);

                    /* Flush the subkey and close it */
                    RegFlushKey(hSubKey);
                    RegCloseKey(hSubKey);
                }

                /* Set the return value */
                bRet = (lResult == ERROR_SUCCESS);

                /* Display error, if any */
                if (!bRet) ErrorMessageBox(hWnd, Caption, lResult);
            }
        }
    }
    else
    {
        CheckCommDlgError(hWnd);
    }

    /* refresh tree and list views */
    RefreshTreeView(g_pChildWnd->hTreeWnd);
    pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
    RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, pszKeyPath);

    return bRet;
}