PowerBuilder Function Set Default Printer gf_set_default_printer
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | //Function Name : gf_set_default_printer //Argument Name : as_printername, Arg Type : String, Pass By : Value //Return Type : Integer Integer li_rc, li_i, li_rtn, li_nbPrinters String ls_PrinterName[], ls_PrinterName1[], ls_PrinterName2[] Boolean lb_PrinterName n_cst_string lnv_string oleobject ole_wsh ole_wsh = Create oleobject li_rc = ole_wsh.ConnectToNewObject("WScript.Network") If li_rc = 0 Then li_rtn = RegistryKeys("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers", ls_PrinterName1) If li_rtn = -1 Then Destroy ole_wsh MessageBox("Information", "Error Registry Keys : HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers", Information!) Return -1 End If For li_i = 1 To UpperBound(ls_PrinterName1) ls_PrinterName1[li_i] = lnv_string.of_GlobalReplace(ls_PrinterName1[li_i], ",", "\") ls_PrinterName[UpperBound(ls_PrinterName) + 1] = ls_PrinterName1[li_i] Next li_rtn = RegistryKeys("HKEY_CURRENT_USER\Printers\Connections", ls_PrinterName2) If li_rtn = -1 Then Destroy ole_wsh MessageBox("Information", "Error Registry Keys : HKEY_CURRENT_USER\Printers\Connections", Information!) Return -1 End If For li_i = 1 To UpperBound(ls_PrinterName2) ls_PrinterName2[li_i] = lnv_string.of_GlobalReplace(ls_PrinterName2[li_i], ",", "\") ls_PrinterName[UpperBound(ls_PrinterName) + 1] = ls_PrinterName2[li_i] Next li_nbPrinters = UpperBound(ls_PrinterName) For li_i = 1 To li_nbPrinters If ls_PrinterName[li_i] = as_PrinterName Then lb_PrinterName = True Exit End If Next If lb_PrinterName Then ole_wsh.SetDefaultPrinter(as_PrinterName) Else Destroy ole_wsh Return -1 End If End If Destroy ole_wsh Return 1 |
Good Luck!