variable declaration
DIM PrinterCheckflag AS Boolean
dim mvarGlobalErrorMsg as string
'Retrieves current default Printer
Dim currentDefault As String
currentDefault = p.PrinterSettings.PrinterName
msgbox(currentdefault)
Dim pkInstalledPrinters As String
' Find all printers installed
For Each pkInstalledPrinters In _
PrinterSettings.InstalledPrinters
cboInstalledPrinters.Items.Add(pkInstalledPrinters)
Next pkInstalledPrinters
' Set the combo to the first printer in the list
If cboInstalledPrinters.Items.Count > 0 Then
cboInstalledPrinters.SelectedIndex = 0
End If
Private Function SetDefaultPrinter(ByVal Printername As String) ' Set the default printer
Dim DefaultPrinter As String
Dim regKey As RegistryKey
Dim Sys_var As String
Dim index As Integer
Try
regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion\Windows", True)
Sys_var = regKey.GetValue("Device")
DefaultPrinter = Sys_var
index = Sys_var.IndexOf(",")
Sys_var = Sys_var.Remove(0, index)
Sys_var = Printername & Sys_var
regKey.SetValue("Device", Sys_var)
'Sys_var = regKey.GetValue("Device")
'regKey.Close()
PrinterCheckflag = True ' Success in setting default printer
Catch ex As Exception
regKey.SetValue("Device", DefaultPrinter)
PrinterCheckflag = False ' Error in Setting Default printer
mvarGlobalErrorMsg = Printername & " : Failed to set as default Printer."
Finally
regKey.Close()
Sys_var = String.Empty
index = Nothing
End Try
End Function
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment