Detect installed printer?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • newengland
    Indigo Rose Customer
    • Sep 2005
    • 16

    Detect installed printer?

    Can I / how can I detect whether a particular printer has been installed? I know the exact name of the printer.

    Any help would be greatly appreciated - thanks.
  • Eliminator
    Forum Member
    • Nov 2005
    • 135

    #2
    I don't know if it will work on non-NT system but I think that you can try this:

    result = Registry.GetKeyNames(HKEY_LOCAL_MACHINE, "\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers");
    result = Dialog.Message("Notice", result[1], MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

    It will enumerate all printers on your computer (my example only show the first)

    Eliminator

    Comment

    • Adam
      Indigo Rose Staff Member
      • May 2000
      • 2149

      #3
      Good one Eliminator.

      We do not have a direct action to do this. I'll bet that there is a key somewhere on non NT machines in the registry.

      Adam.

      Comment

      • newengland
        Indigo Rose Customer
        • Sep 2005
        • 16

        #4
        Thanks for your help.

        In XP and 2000, the registry location is different:

        HKEY_CURRENT_USER\Software\Microsoft\Windows NT\Current Version\Devices

        We decided to instead go with a script that uses the Windows FileOpen function. See http://msdn2.microsoft.com/en-us/library/ms536027.aspx

        Comment

        • Eliminator
          Forum Member
          • Nov 2005
          • 135

          #5
          Sorry, I didn't check on other but you can use a System.GetOSName and for each os use a different key.

          Sorry for my mistake
          Eliminator

          Comment

          • boku
            Indigo Rose Customer
            • Mar 2009
            • 283

            #6
            How would I handle the error if no printer is installed?

            Getting quite frustrated, can I even suppress the error?

            Any help please... All i need to do is detect whether or not a printer is installed, but I get "a nil value" if no printer is found.
            - BoKu -

            Comment

            • .:AMS NUB:.
              Forum Member
              • Nov 2008
              • 39

              #7
              FOR NT

              Code:
              result = Registry.GetKeyNames(HKEY_LOCAL_MACHINE, "\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers");
              if result == "" then
              ~SETUP YOUR ACTION FOR NO PRINTER HERE
              else
              ~SETUP YOUR ACTION FOR YES PRINTER HERE
              end
              FOR NON NT

              Code:
              result = Registry.GetKeyNames(HKEY_CURRENT_USER "\Software\Microsoft\Windows NT\Current Version\Devices\\Printers");
              if result == "" then
              ~SETUP YOUR ACTION FOR NO PRINTER HERE
              else
              ~SETUP YOUR ACTION FOR YES PRINTER HERE
              end

              or something similar

              Comment

              Working...
              X