Jump to content

Refresh Printers and Faxes


Recommended Posts

I've got some vbs code that I kick off via an AutoIt script that watches for any changes to a USB device. What I'm doing is checking for a USB printer being turned on, turned off, plugged in or unplugged. If the printer is turned on or plugged in, I have VBS code that makes sure the printer is set to default and removes any additional printer installations. Long story short...

The vbs code stops the print spooler, does the admin work, restarts the print spooler and sets the default printer. When I go check the Printers and Faxes window, it looks like no changes were made except for the setting of the default printer. Additional copies of printer installation exist and sometimes the default printer show offline when it is online.

If you hit F5 with the window open, everything shows as it's supposed to. There's the rub...I don't want to have to open Printers and Faxes and do a sendkey to refresh the printer listing. I would like to make this a passive as possible to the user.

I've found the following code within the AutoIt Forums:

CODE
#include <Constants.au3>

Dim Const $SHCNE_ASSOCCHANGED = 0x8000000

Dim Const $SHCNF_IDLIST = 6

Dim Const $NULL = 0

DllCall("shell32.dll", "none", "SHChangeNotify", "long", $SHCNE_ASSOCCHANGED, "int", $SHCNF_IDLIST, "ptr", 0, "ptr", 0)

I found that $SHCNF_IDLIST=6 is for PRINTERW and $SHCNF_IDLIST=2 is for PRINTERA. In testing, I've gotten better results with $SHCNF_IDLIST=6 but not 100%. I get abouta 40% success rate with it and am wondering if anybody sees something wrong with the code.

Longwinded? I apologize, but do appreciate any help offered.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...