Renaming Printer Live Using API
Hey, Im trying to write a program that will change a printer's display name without making the user reboot. The easy way is to do it using the registry, but I am trying to use the getPrinter() and setPrinter() api functions to set the printer info, but I keep getting memory errors and such, and VB randomly closing. Maybe Im trying to do something too far out of my league, or maybe its not possible in vb (but as far im concerned everything is possible). So if someone can give me some pointers (no pun intended) :D
Code:
Public Function RenamePrinter(fromName As String, toName As String)
On Error GoTo printerr
Dim pHandle As Long
Dim pBuffSize, pBuffSize2 As Long
Dim r1, r2 As Long
Dim pInfo As PRINTER_INFO_2
Dim pDef As PRINTER_DEFAULTS
r1 = OpenPrinter(fromName, pHandle, pDef)
Call GetPrinter(pHandle, 2&, 0&, 0&, pBuffSize)
'ReDim bPrint(1 To pBuffSize) As Byte
Call GetPrinter(pHandle, 2&, pInfo, pBuffSize, pBuffSize2)
'Call CopyMemory(pInfo, bPrint(1), Len(pInfo))
MsgBox pInfo.pPrinterName
printerr:
MsgBox ("Error")
cleanup:
Call ClosePrinter(pHandle)
I've tried to do this a number of ways and thats why there me some unassigned variables and such. Right now, vb doesn't evene rror, it just closes on me and says nothing. :mad: