我用ShellExecute(NULL,"open","regedit.exe","c:\\a.reg",NULL,SW_SHOWNORMAL);将一个注册表文件导入注册表,系统会提示“是否要导入?”,导入结束后还会提示“成功信息”。有什么办法不出现提示和结果信息,直接执行啊???

解决方案 »

  1.   

    可以阿。开启一个线程,用来模拟手工操作就行了,下面是我模拟弹出格式化d盘,并且点取消按钮的代码HWND cancel = 0;
    BOOL CALLBACK myenumchildwindows( HWND hwnd, LPARAM lparam );
    BOOL CALLBACK
    myenumchildwindows( HWND hwnd, LPARAM lparam )
    {
        char t[ 100 ];
        char c[ 100 ];
        ::GetClassName( hwnd, t, 100 );
        ::GetWindowText( hwnd, c, 100 );
        if( !strncmp( c, "关闭", 4 ) && !strcmp( t, "Button" ) )
            cancel = hwnd;
        return 1;
    }
    BOOL CALLBACK myenumwindows( HWND hwnd, LPARAM lparam );
    BOOL CALLBACK
    myenumwindows( HWND hwnd, LPARAM lparam )
    {
        char t[ 100 ];
        ::GetWindowText( hwnd, t, 100 );
        if( !strncmp( "格式化", t, 6 ) )
        {
            cancel = 0;
            ::EnumChildWindows( hwnd, ( WNDENUMPROC )myenumchildwindows, 0 );
        }
        return 1;
    }
    void mythread( void *p );
    void
    mythread( void *p )
    {
        int i = 0;
        for( i = 0; i < 10; i++ )
        {
            Sleep( 1000 );    //等待1秒钟,一般都能够保证格式化对话框出来了
            cancel = 0;
            ::EnumWindows( ( WNDENUMPROC )myenumwindows, 0 );
            if( cancel )
                break;
        }
        if( !cancel )
            return;
        RECT r;
        POINT pp;
        ::GetCursorPos( &pp );
        ::GetWindowRect( cancel, &r );
        ::SetCursorPos( r.left + 2, r.top + 2 );
        mouse_event( MOUSEEVENTF_LEFTDOWN, r.left + 2, r.top + 2, 0, 0 );
        mouse_event( MOUSEEVENTF_LEFTUP, r.left + 2, r.top + 2, 0, 0 );
        ::SetCursorPos( pp.x, pp.y );
    }void CSizeDlg::OnButton2() 
    {
    typedef DWORD (WINAPI * SHFormatDrive)(HWND hwnd,UINT drive,UINT fmtID,UINT options);
        SHFormatDrive pFnSHFormatDrive;
        HINSTANCE hInstance=LoadLibrary(_T ("Shell32.dll")); 
        if(hInstance==NULL) 
            return; 
        pFnSHFormatDrive=(SHFormatDrive)GetProcAddress(hInstance,"SHFormatDrive");  
        if(pFnSHFormatDrive==NULL) 
        { 
            FreeLibrary(hInstance); 
            return; 
        } 
        UINT OldMode = SetErrorMode(0); //得到缺省设置
        SetErrorMode(OldMode & !SEM_FAILCRITICALERRORS);//设置处理方式
        _beginthread( mythread, 0, NULL );
        pFnSHFormatDrive(this->m_hWnd,3,0xFFFF,0x0000);
        // int n_Id = GetActiveWindow()->GetDlgCtrlID();
        SetErrorMode(OldMode); // 恢复缺省设置
        FreeLibrary(hInstance);
    }
      

  2.   

    程序改好了,自动导入注册表HWND buttonok = 0;
    BOOL CALLBACK myenumchildwindows0( HWND hwnd, LPARAM lparam );
    BOOL CALLBACK
    myenumchildwindows0( HWND hwnd, LPARAM lparam )
    {
        char t[ 100 ];
        char c[ 100 ];
        ::GetClassName( hwnd, t, 100 );
        ::GetWindowText( hwnd, c, 100 );
        if( !strncmp( c, "是", 2 ) && !strcmp( t, "Button" ) )
            buttonok = hwnd;
        return 1;
    }
    BOOL CALLBACK myenumchildwindows1( HWND hwnd, LPARAM lparam );
    BOOL CALLBACK
    myenumchildwindows1( HWND hwnd, LPARAM lparam )
    {
        char t[ 100 ];
        char c[ 100 ];
        ::GetClassName( hwnd, t, 100 );
        ::GetWindowText( hwnd, c, 100 );
        if( !strncmp( c, "确定", 4 ) && !strcmp( t, "Button" ) )
            buttonok = hwnd;
        return 1;
    }
    BOOL CALLBACK myenumwindows0( HWND hwnd, LPARAM lparam );
    BOOL CALLBACK
    myenumwindows0( HWND hwnd, LPARAM lparam )
    {
        char t[ 100 ];
        ::GetWindowText( hwnd, t, 100 );
        if( !strncmp( "注册表编辑器", t, 12 ) )
        {
            buttonok = 0;
            ::EnumChildWindows( hwnd, ( WNDENUMPROC )myenumchildwindows0, 0 );
        }
        return 1;
    }
    BOOL CALLBACK myenumwindows1( HWND hwnd, LPARAM lparam );
    BOOL CALLBACK
    myenumwindows1( HWND hwnd, LPARAM lparam )
    {
        char t[ 100 ];
        ::GetWindowText( hwnd, t, 100 );
        if( !strncmp( "注册表编辑器", t, 12 ) )
        {
            buttonok = 0;
            ::EnumChildWindows( hwnd, ( WNDENUMPROC )myenumchildwindows1, 0 );
        }
        return 1;
    }
    void mythread( void *p );
    void
    mythread( void *p )
    {
        int i = 0;
        for( i = 0; i < 10; i++ )
        {
            Sleep( 1000 );    //等待1秒钟,一般都能够保证注册表对话框出来了
            buttonok = 0;
            ::EnumWindows( ( WNDENUMPROC )myenumwindows0, 0 );
            if( buttonok )
                break;
        }
        if( !buttonok )
            return;
        RECT r;
        POINT pp;
        ::GetCursorPos( &pp );
        ::GetWindowRect( buttonok, &r );
        ::SetCursorPos( r.left + 2, r.top + 2 );
        mouse_event( MOUSEEVENTF_LEFTDOWN, r.left + 2, r.top + 2, 0, 0 );
        mouse_event( MOUSEEVENTF_LEFTUP, r.left + 2, r.top + 2, 0, 0 );
        ::SetCursorPos( pp.x, pp.y );
        for( i = 0; i < 10; i++ )
        {
            Sleep( 1000 );    //等待1秒钟,一般都能够保证注册表对话框出来了
            buttonok = 0;
            ::EnumWindows( ( WNDENUMPROC )myenumwindows1, 0 );
            if( buttonok )
                break;
        }
        if( !buttonok )
            return;
        ::GetWindowRect( buttonok, &r );
        ::SetCursorPos( r.left + 2, r.top + 2 );
        mouse_event( MOUSEEVENTF_LEFTDOWN, r.left + 2, r.top + 2, 0, 0 );
        mouse_event( MOUSEEVENTF_LEFTUP, r.left + 2, r.top + 2, 0, 0 );
        ::SetCursorPos( pp.x, pp.y );
    }void CRegedit1Dlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    _beginthread( mythread, 0, NULL );
    ShellExecute(NULL,"open","regedit.exe","d:\\ss.reg",NULL,SW_SHOWNORMAL);
    }
      

  3.   

    在前面#include "process.h"选择菜单project->settings->link->object/lib modules,添加libcmt.lib或者msvcrt.lib