|
-
May 11th, 2006, 03:09 AM
#1
Thread Starter
Hyperactive Member
[02/03] Add a Printer
Hello guys, I'm trying to add a new printer (printers/faxes).
I'm using the following:
VB Code:
Module Module1
Public Declare Auto Function OpenPrinter Lib "winspool.drv" _
(ByVal pPrinterName As String, _
ByRef phPrinter As IntPtr, _
ByVal pDefault As PrinterDefaults) As Int32
Public Declare Function DeletePrinter Lib "winspool.drv" _
(ByVal hPrinter As IntPtr) As Int32
Public Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As IntPtr) As Int32
Private Declare Function AddPrinter Lib "winspool.drv" _
Alias "AddPrinterA" _
(ByVal pServerName As String, _
ByVal Level As Int32, _
ByVal pPrinter As PRINTER_INFO_2) As Int32
Structure PRINTER_INFO_2
Public pServerName As String
Public pPrinterName As String
Public pShareName As String
Public pPortName As String
Public pDriverName As String
Public pComment As String
Public pLocation As String
Public pDevMode As Int32 'DEVMODE
Public pSepFile As String
Public pPrintProcessor As String
Public pDatatype As String
Public pParameters As String
Public pSecurityDescriptor As Int32 'SECURITY_DESCRIPTOR
Public Attributes As Int32
Public Priority As Int32
Public DefaultPriority As Int32
Public StartTime As Int32
Public UntilTime As Int32
Public Status As Int32
Public cJobs As Int32
Public AveragePPM As Int32
End Structure
Structure PrinterDefaults
Public pDataType As String
Public pDevMode As Int32
Public permissions As Int32
End Structure
Public Const PRINTER_ACCESS_ADMINISTER As Int32 = &H4
Public Const STANDARD_RIGHTS_REQUIRED As Int32 = &HF0000
Public Const PRINTER_ACCESS_USE As Int32 = &H8
Public Const PRINTER_ALL_ACCESS As Int32 = _
STANDARD_RIGHTS_REQUIRED Or _
PRINTER_ACCESS_USE Or _
PRINTER_ACCESS_ADMINISTER
Sub RemovePrinter(ByVal PrinterName As String)
Dim hPrinter As IntPtr
Dim PrinterDefs As New PrinterDefaults
Dim rtn As Int32
PrinterDefs.permissions = PRINTER_ALL_ACCESS
rtn = OpenPrinter(PrinterName, hPrinter, PrinterDefs)
rtn = DeletePrinter(hPrinter)
rtn = ClosePrinter(hPrinter)
End Sub
Sub addprinter1(ByVal PrinterName As String)
Dim pi2 As PRINTER_INFO_2
With pi2
.pPrinterName = PrinterName
.pPortName = "RPT2:"
.pDriverName = "Apple LaserWriter 12/640 PS"
.pPrintProcessor = "WinPrint" '?
End With
Dim rtn As Int32
rtn = AddPrinter("", 2, pi2)
End Sub
Sub Main()
'addprinter1("test1")
RemovePrinter("test")
End Sub
But nothing happens!
What else must I do?
-
May 11th, 2006, 03:16 AM
#2
Re: [02/03] Add a Printer
Is this a local printer or a network printer?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 11th, 2006, 03:57 AM
#3
Thread Starter
Hyperactive Member
Re: [02/03] Add a Printer
Hello, Thanx for the reply!.
it's just a Local Printer.
It's one of those "default" printers listed in the list in Printers / faxes
-
May 11th, 2006, 04:40 AM
#4
Re: [02/03] Add a Printer
Well my code works for public network printers but maybe you can try it on your local printer?
http://www.vbforums.com/showthread.php?t=308544
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 11th, 2006, 05:14 AM
#5
Thread Starter
Hyperactive Member
Re: [02/03] Add a Printer
Hi!
I've tried it like this:
VB Code:
Shell("Rundll32 printui.dll,PrintUIEntry /ga /c\\Grimm \'Lexmark 3200 Color Jetprinter'", vbNormalFocus)
So, I didn't include the servername parameter in there.
But, it said that the operation cannot be completed because the connection to the server was lost
Have I done something wrong?
-
May 11th, 2006, 05:31 AM
#6
Re: [02/03] Add a Printer
I take it that your printer name is "Grimm 'Lexmark 3200 Color Jetprinter'" with the single quotes?
You need your local computer name or try local and see if that works.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 11th, 2006, 05:37 AM
#7
Thread Starter
Hyperactive Member
Re: [02/03] Add a Printer
 Originally Posted by RobDog888
I take it that your printer name is "Grimm 'Lexmark 3200 Color Jetprinter'" with the single quotes?
You need your local computer name or try local and see if that works.
The computer's name is Grimm, and the printer is Lexmark 3200 Color JetPrinter.
So I've done something wrong?
-
May 11th, 2006, 06:32 AM
#8
Re: [02/03] Add a Printer
Just a little bit.
You need it in this format and see if it works.
Dont forget to do the netstart and stop to refresh as explained in my comments in my codebank thread. 
VB Code:
Shell "Rundll32 printui.dll,PrintUIEntry /ga /c\\Grimm/n\\Grimm\Lexmark 3200 Color JetPrinter", vbNormalFocus
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 11th, 2006, 07:16 AM
#9
Thread Starter
Hyperactive Member
Re: [02/03] Add a Printer
Hello again!
Thanx for all your effort
OK, it doesn't throw any errors, but I see nothing in Printers / Faxes
I have Stopped and started the spooler after I executed the shell command, any other problems?
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
|