|
-
Feb 8th, 2000, 07:00 AM
#1
trying to write a small program
that will change the default printer
at the command line..
eg: c:\dp LaserJet4
dp the name of my program
and LaserJet4 in the list
of my printers...
here is what i have but it
doesn't work...
any suggestions greatly appreciated.
Private Sub Form_Load()
Dim Prntr As Printer
Dim PrinterName As String
Dim CommandLine As String
Dim subc1 As String * 10
Dim subc2 As String * 10
Me.Hide
CommandLine = Command$
subc1 = InStr(1, CommandLine, subc2, vbTextCompare)
If subc1 <> 0 Then
PrinterName = subc1 'new default
For Each Prntr In Printers
If Prntr.DeviceName = PrinterName Then
Set Printer = Prntr
Exit For
End If
Next
Else
End If
Unload Me
End Sub
-
Feb 10th, 2000, 12:45 PM
#2
Sure. Try something like this:
Code:
Option Explicit
Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
Private Sub Form_Load()
Dim strCommand As String
Dim prn As Printer
Dim blnIsFound As Boolean
Dim strBuffer As String
strCommand = Command
If Len(strCommand) = 0 Then
MsgBox "You must specify the Printer Name."
End
End If
For Each prn In Printers
If UCase(strCommand) = UCase(prn.DeviceName) Then
strBuffer = strCommand & "," & prn.DriverName & "," & prn.Port
blnIsFound = True
Exit For
End If
Next
If blnIsFound Then
Call WriteProfileString("windows", "device", strBuffer)
MsgBox "Succesfully changed printer " & strCommand
End
End If
End Sub
Then you can call your program like this:
C:\DP HP DeskJet 680C
------------------
Serge
Senior Programmer Analyst
[email protected]
[email protected]
ICQ#: 51055819
[This message has been edited by Serge (edited 02-11-2000).]
-
Aug 2nd, 2000, 12:36 PM
#3
New Member
hello
Serge,
the above code worked great to SET the default printer, but
how to GET the windows default printer from the registry
regards
zdocteur
-
Aug 2nd, 2000, 01:20 PM
#4
New Member
hi
thanks Serge but i think i found the answer here:
http://support.microsoft.com/support...-US&SD=gn&FR=0
regards
zdocteur
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|