WMI & LotusScript

In LotusScript, to create WMI Object, then setting default print and getting printer size.

Dim objWMIService As Variant
Dim colInstalledPrinters As Variant
Dim objInstances As Variant
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
n = 0
Forall objPrinter In colInstalledPrinters
Redim Preserve pArray(n) As String
pArray(n) = objPrinter.Name
n = n + 1
End Forall

PrinterPath = ws.Prompt(4,"請選擇印表機","請從下列清單選擇所要使用的印表機:","",pArray)
If Cstr(PrinterPath)="" Then Exit Sub

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name =" & "'" & PrinterPath & "'")
Forall objPrinter In colInstalledPrinters
Call objPrinter.SetDefaultPrinter()
End Forall
Set objInstances = objWMIService.InstancesOf("Win32_PrinterConfiguration",48)
Forall objInstance In objInstances
If objInstance.name = PrinterPath Then
Msgbox objInstance.Orientation
Msgbox objInstance.PaperSize
End If
End Forall

WMI is very Powerful, even control your PC.

Microsoft: WMI Reference

February 2012

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      

Archives

Powered by Movable Type 4.34-en

About this Entry

This page contains a single entry by philipz published on June 26, 2007 6:22 PM.

iSCSI Server on Linux 安裝步驟 was the previous entry in this blog.

Send Shell & Console Commands from LotusScript is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.