Hi All this is my first forum message, I've noticed that there are often great answers on this site. So Here I go.
I have an infopath 2007 form that we are using to get info from users regarding their current machine. One of the sections of the form gets a list of all their network and local printers and displays the default printer in a separate text box using vb.net code to get the details.
My problem is this, the code I have written by and large works, however when I run the form on a Vista Machine with an account with no local admin rights, it doesn't pick up the default printer, however it does pick up all the rest.
When I log on as myself and run the form on the same vista machine I get all the printers including the default printer. Now it gets tricky, it appears that if the account has local admin right before the code is run the first time, the default printer is picked up. However
if the account does not have Local Admin and the form is run, then for ever after that it refuses to pick up the default printer, even if I add the account to the local admins. Any ideas would be welcomed at this point, it is a little on the frustrating side at the moment.
Here is my Code... (I put it here because the forum says if not sure, put it here and the moderators will move it appropriately, thanks in advance).
Sub GetPrinters()
Dim nav As XPathNavigator = MainDataSource.CreateNavigator()
Dim printlist As String = ""
Dim defaultPrinter As String = ""
Dim CurrentUser As String
Dim frmUser As String
'If the form user field has not been filled in ie first time used get the printers and default printer.
frmUser = nav.SelectSingleNode("//my:Username", NamespaceManager).Value
If frmUser = "" Then
'Test each Printer, don't add the one's to the list that we know about. CutePDF etc...
For Each printer As String In System.Drawing.Printing.PrinterSettings.InstalledPrinters
Dim p As New System.Drawing.Printing.PrinterSettings()
p.PrinterName = printer
If p.IsDefaultPrinter Then
defaultPrinter = printer
'msgbox for testing only...
'MsgBox(defaultPrinter)
Else
Select Case printer
Case "Microsoft XPS Document Writer"
'Do Nothing...
Case "CutePDF Writer"
'Do Nothing...
Case "Adobe PDF"
'Do Nothing...
Case "Fax"
'Do Nothing
Case "Microsoft Office Document Image Writer"
'Do Nothing
Case "HP Officejet Pro K850 Series"
'Do Nothing
Case Else
'Add the printer to the variable'
printlist = printlist & printer & vbCrLf
End Select
End If
Next printer
'Add the Final Result to the Text boxes in the form.
nav.SelectSingleNode("//my:DefaultPrinter", NamespaceManager).SetValue(defaultPrinter)
nav.SelectSingleNode("//my:PrinterList", NamespaceManager).SetValue(printlist)
End If
End Sub