打印控制
Changing Print Job Start Time
Uses ADSI to change the start time for all print jobs larger than 400K to 2 AM.
Set objPrinter = GetObject("WinNT://atl-dc-02/ArtDepartmentPrinter,printqueue")
For each objPrintQueue in objPrinter.PrintJobs
If objPrintQueue.Size > 400000 Then
objPrintQueue.Put "StartTime" , TimeValue("2:00:00 AM")
objPrintQueue.SetInfo
End If
Next
Changing Print Job Priority
Uses ADSI to change the priority of current print jobs based on the size of those print jobs.
Set objPrinter = GetObject("WinNT://atl-dc-02/ArtDepartmentPrinter, printqueue")
For each objPrintJob in objPrinter.PrintJobs
If objPrintJob.Size > 400000 Then
objPrintJob.Put "Priority" , 2
objPrintJob.SetInfo
Else
objPrintJob.Put "Priority" , 3
objPrintJob.SetInfo
End If
Next
Configuring Printer Availability
Configures a printer so that documents can only be printed between 8 AM and 6 PM.
dtmStartTime= "********080000.000000+000"
dtmEndTime= "********180000.000000+000"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where DeviceID = 'ArtDepartmentPrinter' ")
For Each objPrinter in colPrinters
objPrinter.StartTime = dtmStartTime
objPrinter.UntilTime = dtmEndTime
objPrinter.Put_
Next
Configuring Printer Locations
Uses ADSI to configure the location attribute for all printers in a specified OU.
Set objOU = GetObject("LDAP://OU = Finance, DC = fabrikam, DC = com")
objOU.Filter = Array("printqueue")
For Each objPrintQueue In objOU
objPrintQueue.Put "Location" , "USA/Redmond/Finance Building"
objPrintQueue.SetInfo
Next
Configuring Printer Priority
Sets the priority for a printer to 2.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer where DeviceID = 'ArtDepartmentPrinter' ")
For Each objPrinter in colPrinters
objPrinter.Priority = 2
objPrinter.Put_
Next
Deleting All Printers on a Print Server
Deletes all the printers from a print server.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
Deleting Print Jobs
Deletes all print jobs larger than 1 megabyte.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs = objWMIService.ExecQuery _
("Select * from Win32_PrintJob Where Size > 1000000")
For Each objPrintJob in colPrintJobs
objPrintJob.Delete_
Next
Deleting Specific Printers
Deletes all HP QuietJet printers installed on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where DriverName = 'HP QuietJet'")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
Enumerating All Published Printers
Returns a list of all the printers published in Active Directory.
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName from " _
& " 'LDAP://DC=fabrikam,DC=com' where objectClass='printQueue'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo "Printer Name: " & objRecordSet.Fields("printerName").Value
Wscript.Echo "Server Name: " & objRecordSet.Fields("serverName").Value
objRecordSet.MoveNext
Loop
Enumerating Printer Capabilities
Lists properties and capabilities for all the printers installed on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_PrinterConfiguration")
For Each objPrinter in colInstalledPrinters
Wscript.Echo "Name: " & objPrinter.Name
Wscript.Echo "Collate: " & objPrinter.Collate
Wscript.Echo "Copies: " & objPrinter.Copies
Wscript.Echo "Driver Version: " & objPrinter.DriverVersion
Wscript.Echo "Duplex: " & objPrinter.Duplex
Wscript.Echo "Horizontal Resolution: " & _
objPrinter.HorizontalResolution
If objPrinter.Orientation = 1 Then
strOrientation = "Portrait"
Else
strOrientation = "Landscape"
End If
Wscript.Echo "Orientation : " & strOrientation
Wscript.Echo "Paper Length: " & objPrinter.PaperLength / 254
Wscript.Echo "Paper Width: " & objPrinter.PaperWidth / 254
Wscript.Echo "Print Quality: " & objPrinter.PrintQuality
Wscript.Echo "Scale: " & objPrinter.Scale
Wscript.Echo "Specification Version: " & _
objPrinter.SpecificationVersion
If objPrinter.TTOption = 1 Then
strTTOption = "Print TrueType fonts as graphics."
Elseif objPrinter.TTOption = 2 Then
strTTOption = "Download TrueType fonts as soft fonts."
Else
strTTOption = "Substitute device fonts for TrueType fonts."
End If
Wscript.Echo "True Type Option: " & strTTOption
Wscript.Echo "Vertical Resolution: " & objPrinter.VerticalResolution
Next
Installing Multiple Printers for One Print Device
Installs two logical network printers (with different printer priorities) for the same physical print device.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = "HP LaserJet 4000 Series PS"
objPrinter.PortName = "IP_169.254.110.160"
objPrinter.DeviceID = "PublicPrinter"
objPrinter.Location = "USA/Redmond/Building 37/Room 114"
objPrinter.Network = True
objPrinter.Shared = True
objPrinter.ShareName = "PublicPrinter"
objPrinter.Put_
objPrinter.DriverName = "HP LaserJet 4000 Series PS"
objPrinter.PortName = "IP_169.254.110.160"
objPrinter.DeviceID = "PrivatePrinter"
objPrinter.Location = "USA/Redmond/Building 37/Room 114"
objPrinter.Priority = 2
objPrinter.Network = True
objPrinter.Shared = True
objPrinter.Hidden = True
objPrinter.ShareName = "PrivatePrinter"
objPrinter.Put_
Installing a Printer
Installs a logical network printer on a print server.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = "HP LaserJet 4000 Series PS"
objPrinter.PortName = "IP_169.254.110.160"
objPrinter.DeviceID = "ScriptedPrinter"
objPrinter.Location = "USA/Redmond/Building 37/Room 114"
objPrinter.Network = True
objPrinter.Shared = True
objPrinter.ShareName = "ScriptedPrinter"
objPrinter.Put_
Monitoring Printer Status
Displays current status for all printers on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
Wscript.Echo "Name: " & objPrinter.Name
Wscript.Echo "Location: " & objPrinter.Location
Select Case objPrinter.PrinterStatus
Case 1
strPrinterStatus = "Other"
Case 2
strPrinterStatus = "Unknown"
Case 3
strPrinterStatus = "Idle"
Case 4
strPrinterStatus = "Printing"
Case 5
strPrinterStatus = "Warmup"
End Select
Wscript.Echo "Printer Status: " & strPrinterStatus
Wscript.Echo "Server Name: " & objPrinter.ServerName
Wscript.Echo "Share Name: " & objPrinter.ShareName
Wscript.Echo
Next
Monitoring Printers with a Temporary Event Subscription
Uses a temporary event consumer to issues alerts any time a printer changes status.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService. _
ExecNotificationQuery("Select * from __instancemodificationevent " _
& "within 30 where TargetInstance isa 'Win32_Printer'")
i = 0
Do While i = 0
Set objPrinter = colPrinters.NextEvent
If objPrinter.TargetInstance.PrinterStatus <> _
objPrinter.PreviousInstance.PrinterStatus Then
Select Case objPrinter.TargetInstance.PrinterStatus
Case 1 strCurrentState = "Other"
Case 2 strCurrentState = "Unknown"
Case 3 strCurrentState = "Idle"
Case 4 strCurrentState = "Printing"
Case 5 strCurrentState = "Warming Up"
End Select
Select Case objPrinter.PreviousInstance.PrinterStatus
Case 1 strPreviousState = "Other"
Case 2 strPreviousState = "Unknown"
Case 3 strPreviousState = "Idle"
Case 4 strPreviousState = "Printing"
Case 5 strPreviousState = "Warming Up"
End Select
Wscript.Echo objPrinter.TargetInstance.Name _
& " is " & strCurrentState _
& ". The printer previously was " & strPreviousState & "."
End If
Loop
Monitoring Print Job Status
Returns the job ID, user name, and total pages for each print job on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs = objWMIService.ExecQuery _
("Select * from Win32_PrintJob")
Wscript.Echo "Print Queue, Job ID, Owner, Total Pages"
For Each objPrintJob in colPrintJobs
strPrinter = Split(objPrintJob.Name,",",-1,1)
Wscript.Echo strPrinter(0) & ", " & _
objPrintJob.JobID & ", " & objPrintJob.Owner & ", " _
& objPrintJob.TotalPages
Next
Monitoring Print Queues
Uses cooked performance counters to return the number of jobs currently in each print queue on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintQueues = objWMIService.ExecQuery _
("Select * from Win32_PerfFormattedData_Spooler_PrintQueue Where " & _
"Name <> '_Total'")
For Each objPrintQueue in colPrintQueues
Wscript.Echo "Name: " & objPrintQueue.Name
Wscript.Echo "Current jobs: " & objPrintQueue.Jobs
Next
Monitoring Print Queue Times
Identifies any print jobs that have been in the print queue for more than 15 minutes.
Const USE_LOCAL_TIME = True
Set DateTime = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_PrintJob")
Wscript.Echo "Print Queue, Job ID, TimeSubmitted, Total Pages"
For Each objPrinter in colInstalledPrinters
DateTime.Value = objPrinter.TimeSubmitted
dtmActualTime = DateTime.GetVarDate(USE_LOCAL_TIME)
TimeinQueue = DateDiff("n", actualTime, Now)
If TimeinQueue > 15 Then
strPrinterName = Split(objPrinter.Name,",",-1,1)
Wscript.Echo strPrinterName(0) & ", " _
& objPrinter.JobID & ", " & dtmActualTime & ", " & _
objPrinter.TotalPages
End If
Next
Monitoring the Print Service
Returns the status of the Spooler service (running, stopped, paused, etc.).
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = 'Spooler'")
For Each objService in colRunningServices
Wscript.Echo objService.DisplayName & VbTab & objService.State
Next
Pausing a Printer
Pauses a printer named ArtDepartmentPrinter.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name = 'ArtDepartmentPrinter'")
For Each objPrinter in colInstalledPrinters
ObjPrinter.Pause()
Next
Pausing Printers with Empty Print Queues
Pauses any printers that have no pending print jobs.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
Set colPrintJobs = objWMIService.ExecQuery _
("Select * from Win32_PerfFormattedData_Spooler_PrintQueue " _
& "Where Name = '" & objPrinter.Name & "'")
For Each objPrintQueue in colPrintJobs
If objPrintQueue.Jobs = 0 and objPrintQueue.Name <> "_Total" Then
objPrinter.Pause()
End If
Next
Next
Pausing Print Jobs
Pauses all the print jobs on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs = objWMIService.ExecQuery _
("Select * from Win32_PrintJob")
For Each objPrintJob in colPrintJobs
objPrintJob.Pause
Next
Purging a Print Queue
Deletes all the print jobs for a printer named HP QuietJet.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name = 'HP QuietJet'")
For Each objPrinter in colInstalledPrinters
objPrinter.CancelAllJobs()
Next
Receiving Notification When a Printer Stops
Checks the status for each printer on a computer, and issues an alert if any of these printers have stopped.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where PrinterStatus = '1' " _
& "or PrinterStatus = '2'")
If colInstalledPrinters.Count = 0 Then
Wscript.Echo "All printers are functioning correctly."
Else
For Each objPrinter in colInstalledPrinters
Wscript.Echo "Printer " & objprinter.Name & " is not responding."
Next
End If
Renaming a Printer Published in Active Directory
Uses the MoveHere method to rename a published printer in an OU.
Set objOU = GetObject("LDAP://ou=HR,dc=NA,dc=fabrikam,dc=com")
objOU.MoveHere _
"LDAP://cn=Printer1,ou=HR,dc=NA,dc=fabrikam,dc=com", "cn=HRPrn1"
Reporting Print Queue Statistics
Returns total number of jobs, total number of pages, and largest job for all print queues on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs = objWMIService.ExecQuery _
("Select * from Win32_PrintJob")
For Each objPrintJob in colPrintJobs
intTotalJobs = intTotalJobs + 1
intTotalPages = intTotalPages + objPrintJob.TotalPages
If objPrintJob.TotalPages > intMaxPrintJob Then
intMaxPrintJob = objPrintJob.TotalPages
End If
Next
Wscript.Echo "Total print jobs in queue: " & intTotalJobs
Wscript.Echo "Total pages in queue: " & intTotalPages
Wscript.Echo "Largest print job in queue: " & intMaxPrintJob
Resuming All Paused Printers
Resumes all the paused printers on a print server.
Const PRINTER_IS_PAUSED = 8
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer where ExtendedPrinterStatus = 8")
For Each objPrinter in colInstalledPrinters
ObjPrinter.Resume()
Next
Resuming a Paused Printer
Resumes a paused printer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name = 'ArtDepartmentPrinter'")
For Each objPrinter in colInstalledPrinters
ObjPrinter.Resume()
Next
Resuming Print Jobs
Resumes all the print jobs on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs = objWMIService.ExecQuery _
("Select * from Win32_PrintJob")
For Each objPrintJob in colPrintJobs
objPrintJob.Resume
Next
Retrieving Print Queue Statistics
Uses cooked performance counters to retrieve data such as total number of jobs printed and total number of printing errors for each print queue on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintQueues = objWMIService.ExecQuery _
("Select * from Win32_PerfFormattedData_Spooler_PrintQueue Where " & _
"Name <> '_Total'")
For Each objPrintQueue in colPrintQueues
Wscript.Echo "Name: " & objPrintQueue.Name
Wscript.Echo "Jobs: " & objPrintQueue.Jobs
Wscript.Echo "Current jobs spooling: " & objPrintQueue.JobsSpooling
Wscript.Echo "Maximum jobs spooling: " & objPrintQueue.MaxJobsSpooling
Wscript.Echo "Total jobs printed: " & objPrintQueue.TotalJobsPrinted
Wscript.Echo "NamJob errors: " & objPrintQueue.JobErrors
Wscript.Echo "Not ready errors: " & objPrintQueue.NotReadyErrors
Wscript.Echo "Out of paper errors: " & objPrintQueue.OutOfPaperErrors
Next
Searching for Specific Printers
Searches Active Directory for all printers with a priority of 2.
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName from " _
& "'LDAP://DC=fabrikam,DC=com' where objectClass='printQueue' and " _
& " Priority = 2 "
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo "Printer Name: " & objRecordSet.Fields("printerName").Value
Wscript.Echo "Server Name: " & objRecordSet.Fields("serverName").Value
objRecordSet.MoveNext
Loop
Transfering Print Jobs to a Different Print Queue
Changes the TCP/IP printer port for a logical printer, which has the net effect of transferring existing print jobs to the new printer port, and thus to a different printer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objPrinter = objWMIService.Get _
("Win32_Printer.DeviceID='ArtDepartmentPrinter'")
objPrinter.PortName = "IP_192.168.1.10"
objPrinter.Put_
Updating Printer Locations
Uses ADSI to update the location attribute for all printers in a specified OU.
Set objOU = GetObject("LDAP://OU=Finance, DC=fabrikam, DC=com")
objOU.Filter = Array("printqueue")
For Each objPrintQueue In objOU
strNewLocation = "Redmond/" & objPrintQueue.Location
objPrintQueue.Put "Location" , strNewLocation
objPrintQueue.SetInfo
Next
solution code in VB
Raj Cool... replied to Kim S at 2008年9月12日 2:11
Hi,
Please use following code which will work fine for you. It will have properti and command button. You need to select property and click to perform the task.
1. Start a new project in Visual Basic. Form1 is created by default.
2. Add a CommandButton and a ListBox to the Form.
3. Paste the following code into the Form's module:
Option Explicit
Private Declare Function PrinterProperties Lib "winspool.drv" _
(ByVal hwnd As Long, ByVal hPrinter As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" _
Alias "OpenPrinterA" (ByVal pPrinterName As String, _
phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Type PRINTER_DEFAULTS
pDatatype As Long ' String
pDevMode As Long
pDesiredAccess As Long
End Type
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const PRINTER_ACCESS_ADMINISTER = &H4
Private Const PRINTER_ACCESS_USE = &H8
Private Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
Private Sub Form_Load()
Dim I As Integer
' List all available printers
For I = 0 To Printers.Count - 1
List1.AddItem Printers(I).DeviceName
If Printers(I).DeviceName = Printer.DeviceName Then
List1.Selected(I) = True ' Select current default printer
End If
Next I
End Sub
Private Sub List1_Click()
Dim Prt As Printer
' Find and use the printer just selected in the ListBox
For Each Prt In Printers
If Prt.DeviceName = List1.Text Then
Set Printer = Prt
Exit For
End If
Next
End Sub
Private Sub Command1_Click()
Dim RetVal As Long, hPrinter As Long
Dim PD As PRINTER_DEFAULTS
PD.pDatatype = 0
' Note that you cannot request more rights than you have as a user
PD.pDesiredAccess = STANDARD_RIGHTS_REQUIRED Or PRINTER_ACCESS_USE
PD.pDevMode = 0
RetVal = OpenPrinter(Printer.DeviceName, hPrinter, PD)
If RetVal = 0 Then
MsgBox "OpenPrinter Failed!"
Else
RetVal = PrinterProperties(Me.hwnd, hPrinter)
RetVal = ClosePrinter(hPrinter)
End If
End Sub
4. Run the project and click on Command1. The Properties dialog will open for the currently selected printer. Note that some tabs may be missing from what you see when bringing up these properties by hand.
-Paresh
VBA macro to automate "print on both sides" for Word only
mv ark replied to Kim S at 2008年9月12日 2:14
Use this VBA macro from this link - http://wordtips.vitalnews.com/Pages/T001418_Printing_On_Both_Sides_of_the_Paper.html
It first prints the odd pages in a document, prompts you to turn the paper over, and then prints the even pages.
Sub PrintBothSides()
Dim iTemp As Integer
ActiveDocument.PrintOut Copies:=1, PageType:=wdPrintOddPagesOnly
iTemp = MsgBox("Switch paper to continue", vbOKCancel, "PrintBothSides")
If iTemp = vbOK Then
ActiveDocument.PrintOut Copies:=1, PageType:=wdPrintEvenPagesOnly
End If
End Sub
The printer feature that allows printing on both sides of a piece of paper is called duplexing.
using WMI Script
sundar k replied to Kim S at 2008年9月12日 2:31
You can use WMI script to change the printer settings of any printer installed in your machine. The below code set the duplex (print on both sides) property to true for the printers installed in your machine. Set duplex to false if you dont want to print on both sides.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_PrinterConfiguration ")
For Each objPrinter In colInstalledPrinters
objPrinter.Duplex = True
Next
print web page using printer's default font
usha sheokand replied to sundar k at 2009年6月3日 1:24
Hi,
Is thr any way to print a HTML page using printer's default font instead of its own font?
any vbscript or javascript?
Other specifications are:
1 No dialogue box shud appear (achieved thru vbscript)
2 printer name is not kown but the web page is printed via default printer.
Thanx in advance