[UDF] Printer autolt


SUBMITTED BY: Guest

DATE: May 28, 2013, 6:32 a.m.

FORMAT: Text only

SIZE: 24.6 kB

HITS: 3002

  1. #CS
  2. UDF title : _printers.au3
  3. Available functions :
  4. _AddPrinter
  5. _AddWindowsPrinterConnection
  6. _AddPrinterDriver
  7. _AddTCPIPPrinterPort
  8. _EnumPrinterConfiguration
  9. _EnumPrinterDriver
  10. _EnumPrinterProperties
  11. _RemovePrinter
  12. _RemovePrinterDriver
  13. _RemoveTCPIPPrinterPort
  14. _SetDefaultPrinter
  15. #CE
  16. Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
  17. ; #FUNCTION# ======================================================================================
  18. ; Name...........: _AddPrinter
  19. ; Description ...: Adds a Windows printer.
  20. ; Syntax.........: _AddPrinter($sPrinterName, $sDriverName, $sPortName, $sLocation = '', $sComment = '')
  21. ; Parameters ....: $sPrinterName - Unique identifier of the printer on the system
  22. ; $sDriverName - Name of the Windows printer driver.
  23. ; $sPortName - Port that is used to transmit data to a printer
  24. ; $sLocation - Physical location of the printer (Example: Bldg. 38, Room 1164)
  25. ; $sComment - Comment for a print queue
  26. ; Return values .: Success - Returns 1
  27. ; Failure - Returns 0
  28. ; =================================================================================================
  29. Func _AddPrinter($sPrinterName, $sDriverName, $sPortName, $sLocation = '', $sComment = '')
  30. $strComputer = "."
  31. $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
  32. $objPrinter = $objWMIService.Get("Win32_Printer").SpawnInstance_
  33. If NOT IsObj($objPrinter) Then Return 0
  34. $objPrinter.DriverName = $sDriverName
  35. $objPrinter.PortName = $sPortName
  36. $objPrinter.DeviceID = $sPrinterName
  37. $objPrinter.Location = $sLocation
  38. $objPrinter.Comment = $sComment
  39. $objPrinter.Put_
  40. Return 1
  41. EndFunc
  42. ; #FUNCTION# ======================================================================================
  43. ; Name...........: _AddWindowsPrinterConnection
  44. ; Description ...: Provides a connection to an existing printer on the network, and adds it to the list of available printers.
  45. ; Syntax.........: _AddWindowsPrinterConnection($sPrinterPath)
  46. ; Parameters ....: $sPrinterPath - Path to the printer connection (must be aa UNC path)
  47. ; Return values .: Success - Returns 1
  48. ; Failure - Set @error
  49. ; @error : 5 - Access Denied
  50. ; 1801 - Invalid Printer Name
  51. ; 1930 - Incompatible Printer Driver
  52. ; =================================================================================================
  53. Func _AddWindowsPrinterConnection($sPrinterPath)
  54. $strComputer = "."
  55. $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
  56. $objPrinter = $objWMIService.Get("Win32_Printer")
  57. $errReturn = $objPrinter.AddPrinterConnection($sPrinterPath)
  58. If $errReturn = 0 Then Return 1
  59. Return SetError($errReturn)
  60. EndFunc
  61. ; #FUNCTION# ======================================================================================
  62. ; Name...........: _AddPrinterDriver
  63. ; Description ...: Adds a printer driver.
  64. ; Syntax.........: _AddPrinterDriver($sDriverName, $sDriverPlatform, $sDriverPath, $sDriverInfName, $sVersion)
  65. ; Parameters ....: $sDriverName - Driver name for this printer
  66. ; $sDriverPlatform - Operating environments that the driver is intended for (Example: "Windows NT x86")
  67. ; $sDriverPath - Path for this printer driver -Example: "C:\\drivers\\pscript.dll")
  68. ; $sDriverInfName - Name of the INF file being used
  69. ; $sVersion - Operating system version for the printer driver
  70. ; 0 = Win9x
  71. ; 1 = Win351
  72. ; 2 = NT40
  73. ; 3 = Win2k
  74. ; Return values .: Success - Returns 1
  75. ; Failure - Set @error
  76. ; @error : 5 - Access denied
  77. ; 1797 - Access The printer driver is unknown
  78. ; =================================================================================================
  79. Func _AddPrinterDriver($sDriverName, $sDriverPlatform, $sDriverPath, $sDriverInfName, $sVersion = "3")
  80. $strComputer = "."
  81. $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
  82. If NOT IsObj($objWMIService) Then Return 0
  83. If $sVersion <> "0" AND $sVersion <> "1" AND $sVersion <> "2" AND $sVersion <> "3" Then Return 0
  84. $objWMIService.Security_.Privileges.AddAsString ("SeLoadDriverPrivilege", True)
  85. $objDriver = $objWMIService.Get("Win32_PrinterDriver")
  86. If NOT IsObj($objDriver) Then Return 0
  87. $objDriver.Name = $sDriverName
  88. $objDriver.SupportedPlatform = $sDriverPlatform
  89. $objDriver.Version = $sVersion
  90. $objDriver.DriverPath = $sDriverPath
  91. $objDriver.Infname = $sDriverInfName
  92. $errReturn = $objDriver.AddPrinterDriver($objDriver)
  93. If $errReturn = 0 Then Return 1
  94. Return SetError($errReturn)
  95. EndFunc
  96. ; #FUNCTION# ======================================================================================
  97. ; Name...........: _AddTCPIPPrinterPort
  98. ; Description ...: Adds a TCP printer port.
  99. ; Syntax.........: _AddTCPIPPrinterPort($sPortName, $sPortIP, $sPortNunber)
  100. ; Parameters ....: $sPortName - Name of the port to create
  101. ; $sPortIP - IP Address of the port
  102. ; $sPortNunber - Port number
  103. ; Return values .: Success - Returns 1
  104. ; Failure - Returns 0
  105. ; =================================================================================================
  106. Func _AddTCPIPPrinterPort($sPortName, $sPortIP, $sPortNunber)
  107. $objWMIService = ObjGet("winmgmts:")
  108. $objNewPort = $objWMIService.Get ("Win32_TCPIPPrinterPort").SpawnInstance_
  109. If NOT IsObj($objNewPort) Then Return 0
  110. $objNewPort.Name = $sPortName
  111. $objNewPort.Protocol = 1
  112. $objNewPort.HostAddress = $sPortIP
  113. $objNewPort.PortNumber = $sPortNunber
  114. $objNewPort.SNMPEnabled = True
  115. $objNewPort.Put_
  116. Return 1
  117. EndFunc
  118. ; #FUNCTION# ======================================================================================
  119. ; Name...........: _EnumPrinterConfiguration
  120. ; Description ...: Enumerates the configuration of printers
  121. ; Syntax.........: _EnumPrinterConfiguration([$sPrinterName])
  122. ; Parameters ....: $sPrinterName - Name of the printer to retrieve configuration.
  123. ; Defaut "" returns configuration for all printers
  124. ; $sPrinterName can be a part of a printer name like "HP*"
  125. ; Return values .: Success - Returns an array containing the configuration (see $aResult[$i - 1][X] in the function)
  126. ; Failure - Returns 0
  127. ; =================================================================================================
  128. Func _EnumPrinterConfiguration($sPrinterName = "")
  129. Local $nbCols = 33
  130. Local $aResult[1][$nbCols]
  131. Local $wbemFlagReturnImmediately = 0x10
  132. Local $wbemFlagForwardOnly = 0x20
  133. Local $filter = ""
  134. If $sPrinterName <> "" Then $filter = " Where Name like '" & $sPrinterName & "'"
  135. $filter = StringReplace($filter, '*', '%')
  136. $strComputer = "."
  137. $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
  138. $colPrinters = $objWMIService.ExecQuery ("Select * from Win32_PrinterConfiguration" & $filter, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  139. If NOT IsObj($colPrinters) Then Return 0
  140. $i = 0
  141. For $objPrinter in $colPrinters
  142. $i += 1
  143. Redim $aResult[$i][$nbCols]
  144. $aResult[$i - 1][0] = $objPrinter.BitsPerPel
  145. $aResult[$i - 1][1] = $objPrinter.Caption
  146. $aResult[$i - 1][2] = $objPrinter.Collate
  147. $aResult[$i - 1][3] = $objPrinter.Color
  148. $aResult[$i - 1][4] = $objPrinter.Copies
  149. $aResult[$i - 1][5] = $objPrinter.Description
  150. $aResult[$i - 1][6] = $objPrinter.DeviceName
  151. $aResult[$i - 1][7] = $objPrinter.DisplayFlags
  152. $aResult[$i - 1][8] = $objPrinter.DisplayFrequency
  153. $aResult[$i - 1][9] = $objPrinter.DitherType
  154. $aResult[$i - 1][10] = $objPrinter.DriverVersion
  155. $aResult[$i - 1][11] = $objPrinter.Duplex
  156. $aResult[$i - 1][12] = $objPrinter.FormName
  157. $aResult[$i - 1][13] = $objPrinter.HorizontalResolution
  158. $aResult[$i - 1][14] = $objPrinter.ICMIntent
  159. $aResult[$i - 1][15] = $objPrinter.ICMMethod
  160. $aResult[$i - 1][16] = $objPrinter.LogPixels
  161. $aResult[$i - 1][17] = $objPrinter.MediaType
  162. $aResult[$i - 1][18] = $objPrinter.Name
  163. $aResult[$i - 1][19] = $objPrinter.Orientation
  164. $aResult[$i - 1][20] = $objPrinter.PaperLength
  165. $aResult[$i - 1][21] = $objPrinter.PaperSize
  166. $aResult[$i - 1][22] = $objPrinter.PaperWidth
  167. $aResult[$i - 1][23] = $objPrinter.PelsHeight
  168. $aResult[$i - 1][24] = $objPrinter.PelsWidth
  169. $aResult[$i - 1][25] = $objPrinter.PrintQuality
  170. $aResult[$i - 1][26] = $objPrinter.Scale
  171. $aResult[$i - 1][27] = $objPrinter.SettingID
  172. $aResult[$i - 1][28] = $objPrinter.SpecificationVersion
  173. $aResult[$i - 1][29] = $objPrinter.TTOption
  174. $aResult[$i - 1][30] = $objPrinter.VerticalResolution
  175. $aResult[$i - 1][31] = $objPrinter.XResolution
  176. $aResult[$i - 1][32] = $objPrinter.YResolution
  177. Next
  178. Return $aResult
  179. EndFunc
  180. ; #FUNCTION# ======================================================================================
  181. ; Name...........: _EnumPrinterDriver
  182. ; Description ...: Enumerates all installed printer drivers.
  183. ; Syntax.........: _EnumPrinterDriver([$sPrinterName])
  184. ; Parameters ....: $sPrinterName - Name of the printer to retrieve informations.
  185. ; Defaut "" returns informations for all printers
  186. ; $sPrinterName can be a part of a printer name like "HP*"
  187. ; Return values .: Success - Returns an array containing all informations (see $aResult[$i - 1][X] in the function)
  188. ; Failure - Returns 0
  189. ; =================================================================================================
  190. Func _EnumPrinterDriver($sPrinterName = "")
  191. Local $nbCols = 8
  192. Local $aResult[1][$nbCols]
  193. Local $wbemFlagReturnImmediately = 0x10
  194. Local $wbemFlagForwardOnly = 0x20
  195. Local $filter = ""
  196. If $sPrinterName <> "" Then $filter = " Where Name like '" & $sPrinterName & "'"
  197. $filter = StringReplace($filter, '*', '%')
  198. $strComputer = "."
  199. $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
  200. $colPrinters = $objWMIService.ExecQuery ("Select * from Win32_PrinterDriver" & $filter, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  201. If NOT IsObj($colPrinters) Then Return 0
  202. $i = 0
  203. For $objPrinter in $colPrinters
  204. $i += 1
  205. Redim $aResult[$i][$nbCols]
  206. $aResult[$i - 1][0] = $objPrinter.ConfigFile
  207. $aResult[$i - 1][1] = $objPrinter.DataFile
  208. $aResult[$i - 1][2] = $objPrinter.DriverPath
  209. $aResult[$i - 1][3] = _StringUnSplit ( $objPrinter.DependentFiles )
  210. $aResult[$i - 1][4] = $objPrinter.HelpFile
  211. $aResult[$i - 1][5] = $objPrinter.MonitorName
  212. $aResult[$i - 1][6] = $objPrinter.Name
  213. $aResult[$i - 1][7] = $objPrinter.SupportedPlatform
  214. Next
  215. Return $aResult
  216. EndFunc
  217. ; #FUNCTION# ======================================================================================
  218. ; Name...........: _EnumPrinterProperties
  219. ; Description ...: Enumerates all installed printers for the user executing the script.
  220. ; Syntax.........: _EnumPrinterProperties([$sPrinterName])
  221. ; Parameters ....: $sPrinterName - Name of the printer to retrieve informations.
  222. ; Defaut "" returns informations for all printers
  223. ; $sPrinterName can be a part of a printer name like "HP*"
  224. ; Return values .: Success - Returns an array containing all informations (see $aResult[$i - 1][X] in the function)
  225. ; Failure - Returns 0
  226. ; =================================================================================================
  227. Func _EnumPrinterProperties($sPrinterName = "")
  228. Local $nbCols = 86
  229. Local $aResult[1][$nbCols]
  230. Local $wbemFlagReturnImmediately = 0x10
  231. Local $wbemFlagForwardOnly = 0x20
  232. Local $filter = ""
  233. If $sPrinterName <> "" Then $filter = " Where DeviceID like '" & $sPrinterName & "'"
  234. $filter = StringReplace($filter, '*', '%')
  235. $strComputer = "."
  236. $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
  237. $colPrinters = $objWMIService.ExecQuery ("Select * from Win32_Printer" & $filter, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  238. If NOT IsObj($colPrinters) Then Return 0
  239. $i = 0
  240. For $objPrinter in $colPrinters
  241. $i += 1
  242. Redim $aResult[$i][$nbCols]
  243. $aResult[$i - 1][0] = $objPrinter.Attributes
  244. $aResult[$i - 1][1] = $objPrinter.Availability
  245. $aResult[$i - 1][2] = _StringUnSplit ($objPrinter.AvailableJobSheets )
  246. $aResult[$i - 1][3] = $objPrinter.AveragePagesPerMinute
  247. $aResult[$i - 1][4] = _StringUnSplit ($objPrinter.Capabilities)
  248. $aResult[$i - 1][5] = _StringUnSplit ($objPrinter.CapabilityDescriptions)
  249. $aResult[$i - 1][6] = $objPrinter.Caption
  250. $aResult[$i - 1][7] = _StringUnSplit ($objPrinter.CharSetsSupported)
  251. $aResult[$i - 1][8] = $objPrinter.Comment
  252. $aResult[$i - 1][9] = $objPrinter.ConfigManagerErrorCode
  253. $aResult[$i - 1][10] = $objPrinter.ConfigManagerUserConfig
  254. $aResult[$i - 1][11] = $objPrinter.CreationClassName
  255. $aResult[$i - 1][12] = _StringUnSplit ($objPrinter.CurrentCapabilities)
  256. $aResult[$i - 1][13] = $objPrinter.CurrentCharSet
  257. $aResult[$i - 1][14] = $objPrinter.CurrentLanguage
  258. $aResult[$i - 1][15] = $objPrinter.CurrentMimeType
  259. $aResult[$i - 1][16] = $objPrinter.CurrentNaturalLanguage
  260. $aResult[$i - 1][17] = $objPrinter.CurrentPaperType
  261. $aResult[$i - 1][18] = $objPrinter.Default
  262. $aResult[$i - 1][19] = _StringUnSplit ($objPrinter.DefaultCapabilities)
  263. $aResult[$i - 1][20] = $objPrinter.DefaultCopies
  264. $aResult[$i - 1][21] = $objPrinter.DefaultLanguage
  265. $aResult[$i - 1][22] = $objPrinter.DefaultMimeType
  266. $aResult[$i - 1][23] = $objPrinter.DefaultNumberUp
  267. $aResult[$i - 1][24] = $objPrinter.DefaultPaperType
  268. $aResult[$i - 1][25] = $objPrinter.DefaultPriority
  269. $aResult[$i - 1][26] = $objPrinter.Description
  270. $aResult[$i - 1][27] = $objPrinter.DetectedErrorState
  271. $aResult[$i - 1][28] = $objPrinter.DeviceID
  272. $aResult[$i - 1][29] = $objPrinter.Direct
  273. $aResult[$i - 1][30] = $objPrinter.DoCompleteFirst
  274. $aResult[$i - 1][31] = $objPrinter.DriverName
  275. $aResult[$i - 1][32] = $objPrinter.EnableBIDI
  276. $aResult[$i - 1][33] = $objPrinter.EnableDevQueryPrint
  277. $aResult[$i - 1][34] = $objPrinter.ErrorCleared
  278. $aResult[$i - 1][35] = $objPrinter.ErrorDescription
  279. $aResult[$i - 1][36] = _StringUnSplit ($objPrinter.ErrorInformation)
  280. $aResult[$i - 1][37] = $objPrinter.ExtendedDetectedErrorState
  281. $aResult[$i - 1][38] = $objPrinter.ExtendedPrinterStatus
  282. $aResult[$i - 1][39] = $objPrinter.Hidden
  283. $aResult[$i - 1][40] = $objPrinter.HorizontalResolution
  284. $aResult[$i - 1][41] = $objPrinter.InstallDate
  285. $aResult[$i - 1][42] = $objPrinter.JobCountSinceLastReset
  286. $aResult[$i - 1][43] = $objPrinter.KeepPrintedJobs
  287. $aResult[$i - 1][44] = _StringUnSplit ($objPrinter.LanguagesSupported)
  288. $aResult[$i - 1][45] = $objPrinter.LastErrorCode
  289. $aResult[$i - 1][46] = $objPrinter.Local
  290. $aResult[$i - 1][47] = $objPrinter.Location
  291. $aResult[$i - 1][48] = $objPrinter.MarkingTechnology
  292. $aResult[$i - 1][49] = $objPrinter.MaxCopies
  293. $aResult[$i - 1][50] = $objPrinter.MaxNumberUp
  294. $aResult[$i - 1][51] = $objPrinter.MaxSizeSupported
  295. $aResult[$i - 1][52] = _StringUnSplit ($objPrinter.MimeTypesSupported)
  296. $aResult[$i - 1][53] = $objPrinter.Name
  297. $aResult[$i - 1][54] = _StringUnSplit ($objPrinter.NaturalLanguagesSupported)
  298. $aResult[$i - 1][55] = $objPrinter.Network
  299. $aResult[$i - 1][56] = _StringUnSplit ($objPrinter.PaperSizesSupported)
  300. $aResult[$i - 1][57] = _StringUnSplit ($objPrinter.PaperTypesAvailable)
  301. $aResult[$i - 1][58] = $objPrinter.Parameters
  302. $aResult[$i - 1][59] = $objPrinter.PNPDeviceID
  303. $aResult[$i - 1][60] = $objPrinter.PortName
  304. $aResult[$i - 1][61] = _StringUnSplit ($objPrinter.PowerManagementCapabilities)
  305. $aResult[$i - 1][62] = $objPrinter.PowerManagementSupported
  306. $aResult[$i - 1][63] = _StringUnSplit ($objPrinter.PrinterPaperNames)
  307. $aResult[$i - 1][64] = $objPrinter.PrinterState
  308. $aResult[$i - 1][65] = $objPrinter.PrinterStatus
  309. $aResult[$i - 1][66] = $objPrinter.PrintJobDataType
  310. $aResult[$i - 1][67] = $objPrinter.PrintProcessor
  311. $aResult[$i - 1][68] = $objPrinter.Priority
  312. $aResult[$i - 1][69] = $objPrinter.Published
  313. $aResult[$i - 1][70] = $objPrinter.Queued
  314. $aResult[$i - 1][71] = $objPrinter.RawOnly
  315. $aResult[$i - 1][72] = $objPrinter.SeparatorFile
  316. $aResult[$i - 1][73] = $objPrinter.ServerName
  317. $aResult[$i - 1][74] = $objPrinter.Shared
  318. $aResult[$i - 1][75] = $objPrinter.ShareName
  319. $aResult[$i - 1][76] = $objPrinter.SpoolEnabled
  320. $aResult[$i - 1][77] = $objPrinter.StartTime
  321. $aResult[$i - 1][78] = $objPrinter.Status
  322. $aResult[$i - 1][79] = $objPrinter.StatusInfo
  323. $aResult[$i - 1][80] = $objPrinter.SystemCreationClassName
  324. $aResult[$i - 1][81] = $objPrinter.SystemName
  325. $aResult[$i - 1][82] = $objPrinter.TimeOfLastReset
  326. $aResult[$i - 1][83] = $objPrinter.UntilTime
  327. $aResult[$i - 1][84] = $objPrinter.VerticalResolution
  328. $aResult[$i - 1][85] = $objPrinter.WorkOffline
  329. Next
  330. Return $aResult
  331. EndFunc
  332. ; #FUNCTION# ======================================================================================
  333. ; Name...........: _RemovePrinter
  334. ; Description ...: Removes a printer.
  335. ; Syntax.........: _RemovePrinter($sPrinterName)
  336. ; Parameters ....: $sPrinterName - Name of the printer to remove (use \\server\printerShare for shared printers)
  337. ; Return values .: Success - Returns 1
  338. ; Failure - Returns 0
  339. ; =================================================================================================
  340. Func _RemovePrinter($sPrinterName)
  341. $strComputer = "."
  342. $sPrinterName = StringReplace($sPrinterName, "\", "\\")
  343. $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
  344. $colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_Printer where DeviceID = '" & $sPrinterName & "'")
  345. If NOT IsObj($colInstalledPrinters) Then Return 0
  346. For $objPrinter in $colInstalledPrinters
  347. $objPrinter.Delete_
  348. Next
  349. Return 1
  350. Endfunc
  351. ; #FUNCTION# ======================================================================================
  352. ; Name...........: _RemovePrinterDriver
  353. ; Description ...: Removes a printer driver.
  354. ; Syntax.........: _RemovePrinterDriver($sDriverName)
  355. ; Parameters ....: $sDriverName - Name of the printer driver
  356. ; Return values .: Success - Returns 1
  357. ; Failure - Returns 0
  358. ; =================================================================================================
  359. Func _RemovePrinterDriver($sDriverName)
  360. $strComputer = "."
  361. $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
  362. $colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_PrinterDriver Where Name like '" & $sDriverName & ",%'")
  363. If NOT IsObj($colInstalledPrinters) Then Return 0
  364. For $objPrinter in $colInstalledPrinters
  365. $objPrinter.Delete_
  366. Next
  367. Return 1
  368. EndFunc
  369. ; #FUNCTION# ======================================================================================
  370. ; Name...........: _RemoveTCPIPPrinterPort
  371. ; Description ...: Removes a TCP printer port.
  372. ; Syntax.........: _RemoveTCPIPPrinterPort($sPortName)
  373. ; Parameters ....: $sPortName - Name of the port to remove
  374. ; Return values .: Success - Returns 1
  375. ; Failure - Returns 0
  376. ; =================================================================================================
  377. Func _RemoveTCPIPPrinterPort($sPortName)
  378. $strComputer = "."
  379. $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
  380. $colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_TCPIPPrinterPort where Name = '" & $sPortName & "'")
  381. If NOT IsObj($colInstalledPrinters) Then Return 0
  382. For $objPrinter in $colInstalledPrinters
  383. $objPrinter.Delete_
  384. Next
  385. Return 1
  386. Endfunc
  387. ; #FUNCTION# ======================================================================================
  388. ; Name...........: _SetDefaultPrinter
  389. ; Description ...: Sets the default system printer
  390. ; Syntax.........: _SetDefaultPrinter($sPrinterName)
  391. ; Parameters ....: $sPrinterName - Name of the printer
  392. ; Return values .: Success - Returns 1
  393. ; Failure - Returns 0
  394. ; =================================================================================================
  395. Func _SetDefaultPrinter($sPrinterName)
  396. $strComputer = "."
  397. $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
  398. $colPrinter = $objWMIService.ExecQuery ("Select * from Win32_Printer where DeviceID = '" & $sPrinterName & "'")
  399. If NOT IsObj($colPrinter) Then Return 0
  400. For $objPrinter in $colPrinter
  401. $objPrinter.SetDefaultPrinter
  402. Next
  403. Return 1
  404. EndFunc
  405. Func _ErrFunc($oError)
  406. Local $txt = "Error number : " & $oError.number & @CRLF & _
  407. "WinDescription:" & @TAB & $oError.windescription & @CRLF & _
  408. "Description : " & @TAB & $oError.description & @CRLF & _
  409. "Source : " & @TAB & $oError.source
  410. MsgBox(16, "Error", $txt)
  411. EndFunc ;==>_ErrFunc
  412. Func _StringUnSplit($aVal, $sSep = ";")
  413. If NOT IsArray($aVal) Then Return 0
  414. Local $sReturn = ""
  415. For $i = 0 To UBound($aVal) - 1
  416. If $i = 0 Then
  417. $sReturn = $aVal[$i]
  418. Else
  419. $sReturn &= $sSep & $aVal[$i]
  420. EndIf
  421. Next
  422. Return $sReturn
  423. EndFunc

comments powered by Disqus