如何在程序中安装打印机驱动(已有inf文件)(100分)

  • 主题发起人 主题发起人 sxf@Delphi
  • 开始时间 开始时间
S

sxf@Delphi

Unregistered / Unconfirmed
GUEST, unregistred user!
已完成打印机驱动程序(模拟打印机),用手工在添加打印机->添加可以出现打印机设备,如何在程序中自动添加呢?
typedef struct _PRINTER_INFO_2 { // pri2
LPTSTR pServerName;
LPTSTR pPrinterName;
LPTSTR pShareName;
LPTSTR pPortName;
LPTSTR pDriverName;
LPTSTR pComment;
LPTSTR pLocation;
LPDEVMODE pDevMode;
LPTSTR pSepFile;
LPTSTR pPrintProcessor;
LPTSTR pDatatype;
LPTSTR pParameters;
PSECURITY_DESCRIPTOR pSecurityDescriptor;
DWORD Attributes;
DWORD Priority;

DWORD DefaultPriority;
DWORD StartTime;
DWORD UntilTime;
DWORD Status;
DWORD cJobs;
DWORD AveragePPM;
} PRINTER_INFO_2;
这些参数如何设置!
 
pPrintProcessor;pDriverName;这俩个参数困难啊
还有怎么安装打印驱动程序啊
AddPrinterDriver?
 
怎么在程序中安装一个模拟打印机驱动,驱动已提供!
大家看看下面的代码是否正确?
program PrjPrintSetup;
uses
SysUtils,
WinSpool,
Windows,
ShellApi;
function AddAPrinter(PrinterName, PortName, DriverName, PrintProcessor: string): boolean;
var
pName: PChar;
Level: DWORD;
pPrinter: PPrinterInfo2;
begin
pName := nil;
Level := 2;
New(pPrinter);
pPrinter^.pServerName := nil;
pPrinter^.pShareName := nil;
pPrinter^.pComment := nil;
pPrinter^.pLocation := nil;
pPrinter^.pDevMode := nil;
pPrinter^.pSepFile := nil;
pPrinter^.pDatatype := nil;
pPrinter^.pParameters := nil;
pPrinter^.pSecurityDescriptor := nil;
pPrinter^.Attributes := 0;
pPrinter^.Priority := 0;
pPrinter^.DefaultPriority := 0;
pPrinter^.StartTime := 0;
pPrinter^.UntilTime := 0;
pPrinter^.Status := 0;
pPrinter^.cJobs := 0;
pPrinter^.AveragePPM :=0;
pPrinter^.pPrinterName := PCHAR(PrinterName);
pPrinter^.pPortName := PCHAR(PortName);
pPrinter^.pDriverName := PCHAR(DriverName);
pPrinter^.pPrintProcessor := PCHAR(PrintProcessor);
if AddPrinter(pName, Level, pPrinter) <> 0 then
Result := true
else
Result := false;
end;

var
pchPath,pchPort: PChar;
strRundll,strInf: string;
begin
GetMem(pchPath,255);
GetMem(pchPort,255);
GetSystemDirectory(pchPath,255);
//ShowMessage(pchPath);
strRundll := pchPath + '/rundll32.exe';
strInf := 'setupapi.dll,InstallHinfSection DefaultInstall 132 ' + ExtractFilePath(ParamStr(0)) + 'VPRINTER.INF';
//ShowMessage(strInf);
Shellexecute(0,nil,Pchar(strRundll),Pchar(strInf),nil,SW_HIDE);
//Handle取为0就提示安装不成功了
//if not AddPort(nil,handle,pchPort) then
ShowMessage('OK');
AddAPrinter('传真打印机','LPT1:','传真打印机 For Windows 2000','vprproc');
FreeMem(pchPath);
FreeMem(pchPort);
end.
 
怎么在程序中安装一个模拟打印机驱动,驱动已提供!
大家看看下面的代码是否正确?
program PrjPrintSetup;
uses
SysUtils,
WinSpool,
Windows,
ShellApi;
function AddAPrinter(PrinterName, PortName, DriverName, PrintProcessor: string): boolean;
var
pName: PChar;
Level: DWORD;
pPrinter: PPrinterInfo2;
begin
pName := nil;
Level := 2;
New(pPrinter);
pPrinter^.pServerName := nil;
pPrinter^.pShareName := nil;
pPrinter^.pComment := nil;
pPrinter^.pLocation := nil;
pPrinter^.pDevMode := nil;
pPrinter^.pSepFile := nil;
pPrinter^.pDatatype := nil;
pPrinter^.pParameters := nil;
pPrinter^.pSecurityDescriptor := nil;
pPrinter^.Attributes := 0;
pPrinter^.Priority := 0;
pPrinter^.DefaultPriority := 0;
pPrinter^.StartTime := 0;
pPrinter^.UntilTime := 0;
pPrinter^.Status := 0;
pPrinter^.cJobs := 0;
pPrinter^.AveragePPM :=0;
pPrinter^.pPrinterName := PCHAR(PrinterName);
pPrinter^.pPortName := PCHAR(PortName);
pPrinter^.pDriverName := PCHAR(DriverName);
pPrinter^.pPrintProcessor := PCHAR(PrintProcessor);
if AddPrinter(pName, Level, pPrinter) <> 0 then
Result := true
else
Result := false;
end;

var
pchPath,pchPort: PChar;
strRundll,strInf: string;
begin
GetMem(pchPath,255);
GetMem(pchPort,255);
GetSystemDirectory(pchPath,255);
//ShowMessage(pchPath);
strRundll := pchPath + '/rundll32.exe';
strInf := 'setupapi.dll,InstallHinfSection DefaultInstall 132 ' + ExtractFilePath(ParamStr(0)) + 'VPRINTER.INF';
//ShowMessage(strInf);
Shellexecute(0,nil,Pchar(strRundll),Pchar(strInf),nil,SW_HIDE);
//Handle取为0就提示安装不成功了
//if not AddPort(nil,handle,pchPort) then
ShowMessage('OK');
AddAPrinter('传真打印机','LPT1:','传真打印机 For Windows 2000','vprproc');
FreeMem(pchPath);
FreeMem(pchPort);
end.
 
使用addprint函数可以添加上该系统曾经安装过的打印机,但是对于从未安装类型的打印机,该函数无法自动为系统添加打印机。盼高手回答~~~
 
后退
顶部