Lock Method

Summary
Locks the specified printer to prevent applications from directly printing to it.
Syntax
C#
C++/CLI
public void Lock( 
   string password 
) 
public: 
void Lock(  
   String^ password 
)  

Parameters

password
Printer administration password.

Remarks

The lock password must be the same as the password that was used when the specified printer was installed.

To unlock the specified printer and enable applications to print directly to it, use the UnLock method.

To check whether applications were prevented from directly printing to the specified printer, use the IsPrinterLocked method.

Only printers that were originally created with a password can be locked.

Example
C#
using Leadtools.Printer; 
using Leadtools; 
 
 
public void PrinterDriverExamples() 
{ 
   InstallPrinter(); 
 
   printer = new Printer("Test LEADTOOLS Printer "); 
 
   if (printer.IsPrinterLocked()) 
   { 
      printer.UnLock("Test Password"); 
   } 
   else 
   { 
      printer.Lock("Test Password"); 
   } 
 
   int iPAPER_USER = 256; 
   PrinterSpecifications myPrinterSpecifications = new PrinterSpecifications(); 
   myPrinterSpecifications.PaperID = iPAPER_USER + 200; 
   myPrinterSpecifications.PaperSizeName = "Custom Paper Name"; 
   myPrinterSpecifications.PaperHeight = 11; 
   myPrinterSpecifications.PaperWidth = 8; 
   myPrinterSpecifications.DimensionsInInches = true; 
   myPrinterSpecifications.PortraitOrient = true; 
   myPrinterSpecifications.MarginsPrinter = "Margins Printer Name"; 
   myPrinterSpecifications.PrintQuality = 300; 
   myPrinterSpecifications.YResolution = 300; 
 
   printer.Specifications = myPrinterSpecifications; 
   printer.UserDefaultSpecifications = myPrinterSpecifications; 
 
   printer.EmfEvent += new EventHandler<EmfEventArgs>(printer_EmfEvent); 
   printer.JobEvent += new EventHandler<JobEventArgs>(printer_JobEvent); 
} 
 
Printer printer; 
 
public void InstallPrinter() 
{ 
   try 
   { 
      string printerName = "Test LEADTOOLS Printer"; 
      string printerPassword = "Test Password"; 
      if (Printer.IsLeadtoolsPrinter(printerName)) 
      { 
         PrinterInfo tmpPrinterInfo = new PrinterInfo(); 
         tmpPrinterInfo.PrinterName = printerName; 
         Printer.UnInstall(tmpPrinterInfo); 
      } 
 
      string documentPrinterRegPath = "SOFTWARE\\LEAD Technologies, Inc.\\22\\Printer\\"; 
      PrinterInfo printerInfo = new PrinterInfo(); 
      printerInfo.MonitorName = printerName; 
      printerInfo.PortName = printerName; 
      printerInfo.ProductName = printerName; 
      printerInfo.PrinterName = printerName; 
      printerInfo.Password = printerPassword; 
      printerInfo.RegistryKey = documentPrinterRegPath + printerName; 
      printerInfo.RootDir = @"C:\LEADTOOLS22\Bin\Common\PrinterDriver"; 
      printerInfo.Url = "https://www.leadtools.com"; 
      printerInfo.PrinterExe = Application.ExecutablePath; 
      printerInfo.AboutString = "LEADTOOLS Printer"; 
      printerInfo.AboutIcon = Path.Combine(LEAD_VARS.ImagesDir, "RasterPro.ico"); 
 
      Printer.Install(printerInfo); 
 
      string strMsg = string.Format("Installation {0} Completed Successfully", printerName); 
      MessageBox.Show(strMsg, "LEADTOOLS Printer Demo", MessageBoxButtons.OK, MessageBoxIcon.Information); 
   } 
   catch (PrinterDriverException ex) 
   { 
      MessageBox.Show(string.Format("Other error: Message:{0}", ex.Message)); 
   } 
} 
 
void printer_EmfEvent(object sender, EmfEventArgs e) 
{ 
   System.IO.File.WriteAllBytes(Path.Combine(LEAD_VARS.ImagesDir, @"LEADTOOLS_IMAGE1.emf"), e.Stream.ToArray()); 
   Metafile metaFile = new Metafile(e.Stream); 
 
   Image emfImage = metaFile.GetThumbnailImage(metaFile.Width, metaFile.Height, null, IntPtr.Zero); 
   emfImage.Save(Path.Combine(LEAD_VARS.ImagesDir, @"LEADTOOLS_IMAGE2.emf")); 
} 
 
void printer_JobEvent(object sender, JobEventArgs e) 
{ 
   string printerName = e.PrinterName; 
   int jobID = e.JobID; 
 
   if (e.JobEventState == EventState.JobStart) 
   { 
      MessageBox.Show(string.Format("Job {0} was started with printer {1}", jobID, printerName)); 
   } 
   else if (e.JobEventState == EventState.JobEnd) 
   { 
      MessageBox.Show(string.Format("Job {0} was ended with printer {1}", jobID, printerName)); 
   } 
   else 
   { 
      printer.CancelPrintedJob(jobID); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

See Also

Reference

Printer Class

Printer Members

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Printer Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.