On Fri, 12 Mar 2021 11:38:08 GMT, Prasanta Sadhukhan <psadhuk...@openjdk.org> 
wrote:

>>> Is this only about addition/removal? What about printer name change?
>> 
>> You cannot change the name of a remote printer.
>> 
>> Opening *Printer Properties* dialog from the printer context menu on the 
>> local host and editing its name changes the name of the printer on the 
>> remote host which shares it. Windows warns, “This is a shared printer. If 
>> you rename a shared printer, existing connections to this printer from other 
>> computers will break and will have to be created again.”
>> 
>> Nothing has been updated on the local system after renaming the printer. As 
>> the warning said, the printer does not work any more because it refers to a 
>> printer that does not exist.
>> 
>> To fix this, one has to add a new remote printer which refers to the new 
>> name of the printer on the remote host.
>> 
>>> Shouldn't we get notified in that case as trying to print on printer with 
>>> old name will not find the printer!!
>> 
>> I'm afraid there's nothing Java can do to mitigate renaming the printer.
>> 
>>> If yes, in that regard I guess `REG_NOTIFY_CHANGE_LAST_SET` is the one to 
>>> go for as it states
>>> _"Notify the caller of changes to a value of the key. This can include 
>>> adding or deleting a value, or changing an existing value. "_
>> 
>> Since no values are created, removed, or changed when a remote printer is 
>> added or removed under `Connections` key, adding 
>> `REG_NOTIFY_CHANGE_LAST_SET` to `dwNotifyFilter` is not required. There are 
>> some values stored in the printer key but Java does not use them directly; 
>> if any value is changed there, getting notifications about such an event 
>> only creates noise.
>> 
>> So, as far as Java is concerned, getting notifications about new keys being 
>> created or removed under `Connections` is enough. This is what 
>> `REG_NOTIFY_CHANGE_NAME` filter does.
>
> I can understand that as a user, you cannot /shouldn't change the name of a 
> remote network printer but a network admin can change the name, so shouldn't 
> we get notification on that name change when this method gets called after 
> the name change? or would it be notified as a new printer in that case? Then 
> what will happen to the old stale printer in the registry?

You can't. Try it yourself. The printer connection is per-user, after all it's 
stored under HKCU.

Windows displays the name of remote printers as “Generic / Text Only on 
192.168.1.18”: _the name of the printer_ and _the remote host_.

If you open the *Printer Properties* dialog of a remote printer and edit its 
name, you change the name of the printer on the remote host which shares it. It 
changes *absolutely nothing* on the local system.

> shouldn't we get notification on that name change when this method gets 
> called after the name change?

Yes, we should. But we cannot.

For Windows, nothing has changed on the local system, it's the remote system 
that has been changed.

> or would it be notified as a new printer in that case?

No, it wouldn't _because nothing has changed on the local system_.

> Then what will happen to the old stale printer in the registry?

Nothing, again. It just stays there but Windows reports an error if you try to 
open its Printer Properties, Windows reports an error if you try to print to 
it. I tried printing with Java and Notepad: the behaviour is the same. The 
difference is that Notepad displays the error message whereas Java throws an 
exception (it depends on the Java app, I guess).

The behaviour aligns to the one seen when the printer is unreachable because 
of, let's say, network issues.

-------------

PR: https://git.openjdk.java.net/jdk/pull/2915

Reply via email to