This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Setting default printer in startup scripts

On Wed, 21 May 2003, Corinna Vinschen wrote:

> On Wed, May 21, 2003 at 10:00:01AM +0100, David Kilroy wrote:
> > # Define default printer
> > if [ $OS = Windows_NT ]; then
> >   PRINTER=`regtool get '\user\Software\Microsoft\Windows
> > NT\CurrentVersion\Windows\Device'|sed 's?\([^,]*\),.*?\1?g'`
> > else
> >   PRINTER=`regtool get
> > '\config\System\CurrentControlSet\Control\Print\Printers\Default'`
> > fi
> >
> > Note: I haven't tested the above much. It works on my NT box with a network
> > printer, and I've verified an ME box has the appropriate registry entry.
> The backslashes are somewhat dangerous since they get evaluated as
> special characters.  Why not use forward slashes instead?  regtool
> supports them as registry key separator.
> Corinna


The backslashes are dangerous unless quoted.  They seem to be properly
quoted in the above.  So, either way is fine.  The *result* of regtool,
however, may contain all kinds of characters (including spaces), and it's
*not* quoted.  I'm also a bit wary of using OS-specific variables, such
as, well, "$OS".  So, how about the following:

# Define default printer
OUR_OS="`uname -s`"
case "$OUR_OS" in
      PRINTER="`regtool get '\user\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device'|sed 's/,.*$//'`"
      PRINTER="`regtool get '\config\System\CurrentControlSet\Control\Print\Printers\Default'`"

I can also confirm that the first key exists (and works) on Win2k, and the
second key exists (and works) on Win98.

FWIW, I'd like to see this in the base-files package.  John?
      |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"I have since come to realize that being between your mentor and his route
to the bathroom is a major career booster."  -- Patrick Naughton

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]