新建一个项目,添加一个button
procedure TForm1.Button1Click(Sender: TObject);
var
hw,h1,h2,h3,h4,h5:HWND;
begin
        hw:=0;
        h1 :=0;
        h2 :=0;
        h3 :=0;
        winExeC(PChar('control userpasswords2'),SW_SHOW );
        hw :=findwindow(nil, '用户帐户');
        if hw=0 then
                exit;
        h1 :=FindWindowEX(hw,0,'SysTabControl32',nil);
        if h1=0 then
                exit;
        //sleep(1000);
        SendMessage(h1,$1330, 1, 0);
        h2 :=FindWindowEX(hw,0,'#32770','高级');
        if h2=0 then
                exit;
        h3 :=FindWindowEX(h2,0,'Button','管理密码(&M)');
        if h3=0 then
                exit;
        SendMessage(h3,BM_CLICK, 1, 0);
        hw:=0;
        h1 :=0;
        h2 :=0;
        h3 :=0;
        hw :=findwindow(nil, '存储用户名和密码');
        if hw=0 then
                showmessage('error1');
        h1 :=FindWindowEX(hw,0,'Button','添加(&A)');
        if h1=0 then
                showmessage('error2');
        SendMessage(h1,BM_CLICK, 1, 0);
        //sleep(100);
        //hw :=0;
        h2 :=FindWindowEX(hw,0,'#32770','登录信息属性');
        //hw :=findwindow(nil, '登录信息属性');
        if h2=0 then
                showmessage('error3');
end;

解决方案 »

  1.   

    如果用手动打开对话框然后执行这样的代码就可以找到,为什么呢?procedure   TForm1.Button1Click(Sender:   TObject); 
    var 
    hw,h1,h2,h3,h4,h5:HWND; 
    begin 
                    hw:=0;
                    hw   :=findwindow(nil,   '登录信息属性'); 
                    if   hw=0   then 
                                    showmessage('error3'); 
    end;
      

  2.   

    我发现只要是用sendmessage点击“添加”出来的对话框就不行,用手动点出来的就可以改成下面的代码,在sendmessage点出来的对话框后马上关掉,并再手动点“添加”打开对话框procedure TForm1.Button1Click(Sender: TObject);
    var
    hw,h1,h2,h3,h4,h5:HWND;
    begin
                    hw:=0;
                    h1   :=0;
                    h2   :=0;
                    h3   :=0; 
                    winExeC(PChar('control   userpasswords2'),SW_SHOW   ); 
                    hw   :=findwindow(nil,   '用户帐户');
                    if   hw=0   then 
                                    exit; 
                    h1   :=FindWindowEX(hw,0,'SysTabControl32',nil);
                    if   h1=0   then
                                    exit;
                    SendMessage(h1,$1330,   1,   0);
                    h2   :=FindWindowEX(hw,0,'#32770','高级');
                    if   h2=0   then 
                                    exit;
                    h3   :=FindWindowEX(h2,0,'Button','管理密码(&M)'); 
                    if   h3=0   then
                                    exit;
                    SendMessage(h3,BM_CLICK,   1,   0);
                    hw:=0; 
                    h1   :=0;
                    h2   :=0;
                    h3   :=0;
                    hw   :=findwindow(nil,   '存储用户名和密码');
                    if   hw=0   then
                                    showmessage('error1');
                    h1   :=FindWindowEX(hw,0,'Button','添加(&A)');
                    if   h1=0   then
                                    showmessage('error2');
                    SendMessage(h1,BM_CLICK,   1,   0);
                    sleep(5000);              //留5秒时间关掉sendmessage点开的对话框并自己手动点击打开新的对话框                hw   :=0;
                    hw   :=findwindow(nil,   'Form1');
                    if   hw=0   then
                        showmessage('error3');
                    h2   :=findwindow(nil,'登录信息属性');
                    if   h2=0   then
                        showmessage('error4')
                    else
                        showmessage(inttostr(h2));end;
      

  3.   

    望了说了,control   userpasswords2调出来的用户帐户XP Home版没有管理网络密码的功能,win2000也没有,只有XP Professional和win2003应该都有
      

  4.   

    解决了,把最后一个sendmessage改成postmessage就行了
      

  5.   

    改用postmessage试试,因为sendmessage会阻塞