Getting the name of the default printer 
Author Message
 Getting the name of the default printer

Does anyone know how to return a string containing the printer
currently being used (default?) in Windows, and how to change
printers *without* user intervention.

Any help greatly appreciated.  Please email any solutions...

Mark
----------------------------------------------------------------



Tue, 12 May 1998 03:00:00 GMT  
 Getting the name of the default printer

Quote:

>Does anyone know how to return a string containing the printer
>currently being used (default?) in Windows, and how to change
>printers *without* user intervention.

Get pprtr47.zip from a big ftp site. It contains sample source and
function for printer control.

Jens
--
* Everything I said are the opinions of someone else.   *
* I just cut-and-pasted.                                *

Jens Balchen jr.

P.O.Box 6052
N-4602 Kristiansand



Tue, 12 May 1998 03:00:00 GMT  
 Getting the name of the default printer
hello mark,

the default-printer is described in the win.ini-file in the
windows-directory - look at section [windows]  entry device=....

you must
1. find the windows-dir
2.read the ini-file
3. write the ini-file
down I copied source code from the VB tips and Tricks (from FTP-servers)
It use API-Functions to make this kind of actions

Good luck
Martin

'****************************************************
'* INIFILES.BAS Version 2.0 Date: 02/01/95          *
'* VB Tips & Tricks                                 *
'* 8430-D Summerdale Road San Diego CA 92126-5415   *
'* Compuserve: 74227,1557                           *
'* America On-Line: DPMCS                           *

'****************************************************
Option Explicit

Declare Function WritePrivateProfileString Lib "Kernel" (ByVal AppName As
String, ByVal KeyName As String, ByVal NewString As String, ByVal
filename As String) As Integer
Declare Function GetPrivateProfileString Lib "Kernel" (ByVal AppName As
String, ByVal KeyName As String, ByVal default As String, ByVal
ReturnedString As String, ByVal MAXSIZE As Integer, ByVal filename As
String) As Integer
Declare Function GetProfileInt Lib "Kernel" (ByVal lpAppName$, ByVal
lpKeyName$, ByVal nDefault%) As Integer
Declare Function GetProfileString Lib "Kernel" (ByVal lpAppName$, ByVal
lpKeyName$, ByVal lpDefault$, ByVal lpReturnedString$, ByVal nSize%) As
Integer
Declare Function WriteProfileString Lib "Kernel" (ByVal lpAppName$, ByVal
lpKeyName$, ByVal lpString$) As Integer
Declare Function GetPrivateProfileInt Lib "Kernel" (ByVal lpAppName$,
ByVal lpKeyName$, ByVal nDefault%, ByVal lpFileName$) As Integer

'*******************************************************
'* Procedure Name: iReadINI                            *
'*-----------------------------------------------------*
'* Created:  9/1/95   By: David McCarter               *
'* Modified:          By:                              *
'*=====================================================*
'*Returns a integer from an INI file. To use, call the *
'*functions and pass it the AppName, KeyName and INI   *
'*File Name, and a default value                       *
'*******************************************************
Function iReadINI (AppName, KeyName, filename As String, iDefault As
Integer) As Integer

    iReadINI = GetPrivateProfileInt(AppName, ByVal KeyName, iDefault,
filename)

End Function

'*******************************************************
'* Procedure Name: sReadINI                            *
'*-----------------------------------------------------*
'* Created:           By: Daniel Bowen                 *
'* Modified: 3/24/94  By: David McCarter               *
'*=====================================================*
'*Returns a string from an INI file. To use, call the  *
'*functions and pass it the AppName, KeyName and INI   *
'*File Name, [sReg=ssReadINI(App1,Key1,INIFile)]. If U *
'*need the returned value to be a integer then use the *
'*val command.                                         *
'*******************************************************
Function sReadINI (AppName, KeyName, filename As String) As String
Dim sRet As String

    sRet = String(255, Chr(0))

    sReadINI = Left(sRet, GetPrivateProfileString(AppName, ByVal KeyName,
"", sRet, Len(sRet), filename))

End Function

'*******************************************************
'* Procedure Name: WriteINI                            *
Hello Mark,
the default printer is described in your win.ini in the
windows-directory. Look at the section [windows] - you
see  device=...

you must
1.get the windows-directory
2. read the ini
3. perhaps write the ini

'****************************************************
'* INIFILES.BAS Version 2.0 Date: 02/01/95          *
'* VB Tips & Tricks                                 *
'* 8430-D Summerdale Road San Diego CA 92126-5415   *
'* Compuserve: 74227,1557                           *
'* America On-Line: DPMCS                           *

'****************************************************
Option Explicit

Declare Function WritePrivateProfileString Lib "Kernel" (ByVal AppName As
String, ByVal KeyName As String, ByVal NewString As String, ByVal
filename As String) As Integer

Declare Function GetPrivateProfileString Lib "Kernel" (ByVal AppName As
String, ByVal KeyName As String, ByVal default As String, ByVal
ReturnedString As String, ByVal MAXSIZE As Integer, ByVal filename As
String) As Integer

Declare Function GetProfileInt Lib "Kernel" (ByVal lpAppName$, ByVal
lpKeyName$, ByVal nDefault%) As Integer

Declare Function GetProfileString Lib "Kernel" (ByVal lpAppName$, ByVal
lpKeyName$, ByVal lpDefault$, ByVal lpReturnedString$, ByVal nSize%) As
Integer

Declare Function WriteProfileString Lib "Kernel" (ByVal lpAppName$, ByVal
lpKeyName$, ByVal lpString$) As Integer

Declare Function GetPrivateProfileInt Lib "Kernel" (ByVal lpAppName$,
ByVal lpKeyName$, ByVal nDefault%, ByVal lpFileName$) As Integer

Declare Function GetWindowsDirectory Lib "Kernel" (ByVal lpBuffer As
String, ByVal nSize As Integer) As Integer
'*******************************************************
'* Procedure Name: iReadINI                            *
'*-----------------------------------------------------*
'* Created:  9/1/95   By: David McCarter               *
'* Modified:          By:                              *
'*=====================================================*
'*Returns a integer from an INI file. To use, call the *
'*functions and pass it the AppName, KeyName and INI   *
'*File Name, and a default value                       *
'*******************************************************
Function iReadINI (AppName, KeyName, filename As String, iDefault As
Integer) As Integer

    iReadINI = GetPrivateProfileInt(AppName, ByVal KeyName, iDefault,
filename)

End Function

'*******************************************************
'* Procedure Name: sReadINI                            *
'*-----------------------------------------------------*
'* Created:           By: Daniel Bowen                 *
'* Modified: 3/24/94  By: David McCarter               *
'*=====================================================*
'*Returns a string from an INI file. To use, call the  *
'*functions and pass it the AppName, KeyName and INI   *
'*File Name, [sReg=ssReadINI(App1,Key1,INIFile)]. If U *
'*need the returned value to be a integer then use the *
'*val command.                                         *
'*******************************************************
Function sReadINI (AppName, KeyName, filename As String) As String
Dim sRet As String

    sRet = String(255, Chr(0))

    sReadINI = Left(sRet, GetPrivateProfileString(AppName, ByVal KeyName,
"", sRet, Len(sRet), filename))

End Function

'*******************************************************
'* Procedure Name: WriteINI                            *
'*-----------------------------------------------------*
'* Created: 2/10/94   By: David McCarter               *
'* Modified:          By:                              *
'*=====================================================*
'*Writes a string to an INI file. To use, call the     *
'*function and pass it the sAppname, sKeyName, the New *
'*String and the INI File Name,                        *
'*[R=WriteINI(App1,Key1,sReg,INIFile)]. Returns a 1 if *
'*there were no errors and a 0 if there were errors.   *
'*******************************************************
Sub WriteINI (sAppname, sKeyName, sNewString, sFileName As String)
Dim R As Integer

    R = WritePrivateProfileString(sAppname, sKeyName, sNewString,
sFileName)

End Sub

'*******************************************************
'* Procedure Name: sGetWinDir                          *
'*-----------------------------------------------------*
'* Created: 8/29/94   By: David McCarter               *
'* Modified:          By:                              *
'*=====================================================*
'*This function will return the Windows directory as a *
'*string.                                              *
'*******************************************************
Function sgetwindir () As String
Dim sPath As String

    sPath = String(255, Chr$(0))

    sgetwindir = sFixDirStr(Left$(sPath, GetWindowsDirectory(sPath,
Len(sPath))))

End Function

--
Martin A. Sonntag
LE Ackerbau und Informatik im Pflanzenbau
TUM-Weihenstephan,D-85350 Freising
Fax: +49-(0)8161-714419
Tel: +49-(0)8161-714480



Tue, 12 May 1998 03:00:00 GMT  
 Getting the name of the default printer

Quote:

>Does anyone know how to return a string containing the printer
>currently being used (default?) in Windows, and how to change
>printers *without* user intervention.

check out pprtr47.zip in cica, garbo or simtel mirrors
(pprtr4.zip on CIS or AOL), e.g. in /simtel/win3/dll
on oak.oakland.edu (or ftp.coast.net, their latest, fastest
mirror) ...

  Windows DLL providing higher-level language access via
  functions to retrieve and chane all printer attributes
  (orientation, pagesize, bin, etc).  Also list available
  printers, get/change default printer, get port, get
  printer capabilities. V4.7 adds W95 & NT compatibility +
  functions for printable area/margins, print to supplied
  file names, use printer's setup dialog; more samples.
  Shareware $10. SWREG #1462. Upl by author. Mentioned in
  the April 95 VBPJ Q&A section.

---------------------
"Programming is the art of debugging a blank sheet of
paper"
Paul F Poellinger    2019 Round Lake Drive
Silent O Software    Houston, TX  77077


        http://rampages.onramp.net/~pelican



Fri, 15 May 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Getting default printer name from Printers Collection

2. Macro to change default printer and then restore original default printer settin

3. printer default to non-default printer

4. Getting system default printer...

5. Getting Printers and setting default

6. problem getting default printer hdc in NT4

7. Getting Default Printer Dimensions using API

8. Getting default MAPI session name

9. Capture Name of Default Window's Printer

10. Setting Printer Defaults based on Computer Name

11. script to change the name of the default printer

12. Howto get the default printer device name???

 

 
Powered by phpBB® Forum Software