Jump to content
Sign in to follow this  
buckRogers

Refresh Printers and Faxes

Recommended Posts

buckRogers

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.

Share this post


Link to post
Share on other sites
KaFu
buckRogers

Thanks for the tip KaFu but it didn't work. Well, it works if the Printers and Faxes window is open but not when it's just the desktop.

Share this post


Link to post
Share on other sites
somdcomputerguy

Close the window, make changes, open window? Or don't open window at all until changes are made?


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.