Completed

Reset default printer when closing VB6 app

I read the default printer at program startup. Inside the app, the user may change the printer. On program shutdown, I want to restore the printer to the default. Here's my code:

'do this a program startup

Set Printer = GetDefaultPrinter()

DefaultPrinterAtProgramStartup$ = [url removed, login to view]

'do this a program shutdown. this does not seem to work at assigning the printer back

If DefaultPrinterAtProgramStartup$ <> "" Then

For i% = 0 To [url removed, login to view] - 1

If Printers(i%).DeviceName = DefaultPrinterAtProgramStartup$ Then

Set Printer = Printers(i%)

DoEvents

Exit For

End If

Next i%

End If

'---------------------------------------------------------------

' Retreive the vb object "printer" corresponding to the window's

' default printer.

'---------------------------------------------------------------

Public Function GetDefaultPrinter() As Printer

Dim strBuffer As String * 254

Dim iRetValue As Long

Dim strDefaultPrinterInfo As String

Dim tblDefaultPrinterInfo() As String

Dim objPrinter As Printer

' Retreive current default printer information

iRetValue = GetProfileString("windows", "device", ",,,", strBuffer, 254)

strDefaultPrinterInfo = Left(strBuffer, InStr(strBuffer, Chr(0)) - 1)

tblDefaultPrinterInfo = Split(strDefaultPrinterInfo, ",")

For Each objPrinter In Printers

If [url removed, login to view] = tblDefaultPrinterInfo(0) Then

' Default printer found !

Exit For

End If

Next

' If not found, return nothing

If [url removed, login to view] <> tblDefaultPrinterInfo(0) Then

Set objPrinter = Nothing

End If

Set GetDefaultPrinter = objPrinter

End Function

Skills: Software Architecture, Visual Basic

See more: how long does it take a web designer to code website, retrieve system default printer net windows app, default printer web app net, excel vba change windows default printer, vb6 set default printer, excel vba change active printer, vb6 print to specific printer, vb6 get default printer, vba set default printer, excel vba print to default printer, setdefaultprinter api, visual basic, windows api, change default printer app, find default printer windows application, running vb6 app vista, convert vb6 app net2008, different default printer application, allow users change default printer windows 2008, windows api default printer

About the Employer:
( 100 reviews ) Livonia, United States

Project ID: #16114132

Awarded to:

vano101

Hello I am little wondering, is not it possible to use GetDefaultPrinter/SetDefaultPrinter Windows API functions? I have much experience with using Windows API with VB6. PS. It would work only if user closes program More

$28 USD in 2 days
(960 Reviews)
7.2

6 freelancers are bidding on average $37 for this job

huongth

Hi. I am an expert in VBA, VBScript, Visual Basic, C#, F#, C, C++, ASM, Delphi, Java, iMacros, Flash, ASP, ASP.NET, Access, MySQL, MSSQL, QuickBooks, Oracle. I can create auto scripts to scrape websites, auto click, fo More

$100 USD in 3 days
(17 Reviews)
4.0
FiveStars5

I am here to help you for the project of .after discussing the complete details i will give you best budget and fastest deadline to complete the project.

$25 USD in 1 day
(0 Reviews)
0.0
$20 USD in 1 day
(0 Reviews)
0.0
cheekwan

A proposal has not yet been provided

$25 USD in 1 day
(0 Reviews)
0.0
kvodivyalakshmi

I have quite good knowledge on Printer domain. So I can easily work on this project and fix the issue as soon as possible with little coding.

$25 USD in 1 day
(0 Reviews)
0.0