combobox1.Items.Clear ;                   //1
  combobox1.Items.Assign(printer.Printers);  //2
  if combobox1.Items.CommaText='' then  //3这3句是检查当前是否安装了打印机。
  begin  //如果没有安装就调用打印机安装向导
    ShellExecute (0, 'open', 'rundll','shell32.dll,SHHelpShortcuts_RunDLL       AddPrinter', '', SW_SHOWNORMAL);
  end else  //否则显示当前打印机信息
     PrinterSetupDialog1.Execute ;
  end;可是    ShellExecute (0, 'open', 'rundll','shell32.dll,SHHelpShortcuts_RunDLL       AddPrinter', '', SW_SHOWNORMAL);并不能够使打印机安装向导显示出来啊?

解决方案 »

  1.   

    上述代码在WIN9X下,在WIN2000、NT下:
    var
      X:LongInt;
    begin
      X:=winexec('rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL AddPrinter',9);
    end;
      

  2.   

    procedure TTj_Form.SpeedButton5Click(Sender: TObject);
    begin
      Printer.Refresh ;
      Main_Form.ComboBox1.Items.Clear ;
      Main_Form.combobox1.Items.Assign(printer.Printers);
      if Main_Form.combobox1.Items.CommaText='' then
      begin
        MessageDlg('您的计算机没有安装打印机,请安装打印机器!',mtInformation, [mbYes], 0);
        ShellExecute(Handle, 'open', 'rundll32.exe','shell32.dll,SHHelpShortcuts_RunDLL AddPrinter', '', SW_SHOWNORMAL);
        printer.Refresh ;
      end ;
    end;多谢,我现在又遇到新问题,假如用户按打印时候,开始是没有装打印机的,我现在通过这个向导安装打印机了,用户如果这个时候不退出程序,在按这个按钮,又提示没有安装打印机,我试图刷新
    printer但好象没有用啊?
      

  3.   

    procedure TTj_Form.SpeedButton4Click(Sender: TObject);
    begin
      Main_Form.ComboBox1.Items.Clear ;
      Main_Form.combobox1.Items.Assign(printer.Printers);
      if Main_Form.combobox1.Items.CommaText='' then
      begin
        MessageDlg('您的计算机没有安装打印机,请安装打印机器!',mtInformation, [mbYes], 0);
        ShellExecute(Handle, 'open', 'rundll32.exe','shell32.dll,SHHelpShortcuts_RunDLL AddPrinter', '', SW_SHOWNORMAL);
      end ;
      showmessage('aaa');
    end;还有就是我想是先判断是否有打印机存在,如果没有就安装,安装完了后继续执行我要的操作比如
     showmessage('aaa');
    但是我实验了一下,好象这两个是一起弹出来的啊?怎么可以控制只有添加完后才执行后面的任务呢?