-5

我正在寻找打开注册表编辑器并显示一些特定键或值的方法。例如,如果我通过了,"HKLM\\SOFTWARE\\Skype\\Installer"我想得到这样的结果:在此处输入图像描述

system()欢迎来电以外的所有建议。

4

2 回答 2

1

只要打电话system。用Raymond Chen 的话说:宁愿在这个密闭舱口的另一边。任何相关的攻击都需要破坏机器,以至于您的system呼叫完全无关紧要。事实上,任何可以更改的攻击者也RegEdit可以更改您的程序,因此他可以添加该system调用。(他不会,因为无论如何这毫无意义)

于 2013-07-25T18:30:23.407 回答
0

这就是我需要的。

String GetFullHKEY (HKEY hKeyRoot)
{
    if (HKEY_LOCAL_MACHINE == hKeyRoot) return _T("HKEY_LOCAL_MACHINE\\");
    if (HKEY_CLASSES_ROOT == hKeyRoot) return _T("HKEY_CLASSES_ROOT\\");
    if (HKEY_CURRENT_CONFIG == hKeyRoot) return _T("HKEY_CURRENT_CONFIG\\");
    if (HKEY_CURRENT_USER == hKeyRoot) return _T("HKEY_CURRENT_USER\\");
    if (HKEY_USERS == hKeyRoot) return _T("HKEY_USERS\\");
}

bool RegistryGoTo (HKEY hKeyRoot, const String &lpctPath, String lpctValue)
{
    if (lpctPath.empty() || 0 == hKeyRoot) 
        return false;
    if( lpctValue.empty() && lpctValue.empty() == 0)
    {
        lpctValue.clear();
    }

    SHELLEXECUTEINFO shi = { 0 };
    DEVMODE dm = { 0 };

    HWND hWndRegedit = ::FindWindow (_T("RegEdit_RegEdit"), NULL);
    if (NULL == hWndRegedit)
    {
        shi.cbSize = sizeof(SHELLEXECUTEINFO);
        shi.fMask  = SEE_MASK_NOCLOSEPROCESS; 
        shi.lpVerb = _T("open"); 
        shi.lpFile = _T("regedit.exe"); 
        shi.nShow  = SW_SHOWNORMAL; 

        ShellExecuteEx (&shi);
        if( GetLastError() != 0 )
        {
            Sleep(200);
            ShellExecuteEx (&shi);
        }
        WaitForInputIdle (shi.hProcess, INFINITE);

        hWndRegedit = ::FindWindow (_T("RegEdit_RegEdit"), NULL);
    }

    if (NULL == hWndRegedit) return FALSE;

    SetForegroundWindow (hWndRegedit);
    ShowWindow (hWndRegedit, SW_SHOWNORMAL);

    HWND hWndTreeView = FindWindowEx (hWndRegedit, NULL, _T ("SysTreeView32"), NULL);
    SetForegroundWindow (hWndTreeView);
    SetFocus (hWndTreeView);

    for (int i = 0; i < 30; i++)
    {
        SendMessage (hWndTreeView, WM_KEYDOWN, VK_LEFT, 0);
    } 

    dm.dmSize = sizeof (DEVMODE);
    EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &dm);

    if (8 < dm.dmBitsPerPel) Sleep (100);

    // the path must start with a backslash
    String stRegPath = String (_T("\\")) + GetFullHKEY(hKeyRoot) + lpctPath;

    // open path
    for (int iIndex = 0; iIndex < (int) stRegPath.length (); iIndex++)
    {
        if (_T('\\') == stRegPath [iIndex])  
        {
            SendMessage (hWndTreeView, WM_KEYDOWN, VK_RIGHT, 0);

            if (8 < dm.dmBitsPerPel) 
                Sleep (100);
        } 
        else SendMessage (hWndTreeView, WM_CHAR, toupper (stRegPath [iIndex]), 0);
    } 

    SetForegroundWindow (hWndRegedit);
    SetFocus (hWndRegedit);

    if (lpctValue.length())
    {
        HWND hWndListView = FindWindowEx (hWndRegedit, NULL, _T("SysListView32"), NULL);
        SetForegroundWindow (hWndListView);
        SetFocus (hWndListView);

        Sleep (100); 

        SendMessage (hWndListView, WM_KEYDOWN, VK_HOME, 0);

        String stValue = lpctValue;

        for (String::iterator it = stValue.begin (); it != stValue.end (); ++it)
        {
            SendMessage (hWndListView, WM_CHAR, toupper (*it), 0);
        } 
    } 

    return true;
}
于 2013-07-26T05:40:31.747 回答