-
After searching through the site I can't find anywhere any code that will let me set the default printer for an NT4 Workstation using VB5!
I want something along the lines of
If machinename = "Rm10-17" then
setdefaultprinter = "Room 10 printer"
EndIF
Any ideas?
Simon
-
Try something like this:
Code:
Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
Private Sub Command1_Click()
Dim prn As Printer
Dim blnIsFound As Boolean
Dim strBuffer As String
If machinename = "Rm10-17" Then
strBuffer = "Room 10 printer"
'Check if the printer exists
For Each prn In Printers
If UCase(strBuffer) = UCase(prn.DeviceName) Then
strBuffer = strBuffer & "," & prn.DriverName & "," & prn.Port
blnIsFound = True
Exit For
End If
Next
'If printer exists, then change it to be default
If blnIsFound Then
Call WriteProfileString("windows", "device", strBuffer)
MsgBox "Succesfully changed printer " & strCommand
End
End If
End If
End Sub
Assuming that the "Room 10 printer" is a valid printer.
-
Thanks Serge! I look forward to trying it on Monday morning :)
Simon