New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8263311: Watch registry changes for remote printers update instead of polling #2915
Closed
+49
−176
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RegNotifyChangeKeyValue
notifies the caller about changes to the attributes or contents of a specified registry key.•
hKey
: A handle toHKEY_CURRENT_USER\Printers\Connections
key which is opened above.•
bWatchSubtree = TRUE
: The function reports changes in the specified key and its subkeys.•
dwNotifyFilter = REG_NOTIFY_CHANGE_NAME
: Notify the caller if a subkey is added or deleted.•
hEvent = NULL
: IffAsynchronous
is FALSE,hEvent
is ignored.•
fAsynchronous = FALSE
: The function does not return until a change has occurred.When a new remote printer is added, a new key is created under
HKCU\Printers\Connections
; when an existing remote printer is removed, the key belowConnections
is removed; no values are added or removed inConnections
key, thusREG_NOTIFY_CHANGE_LAST_SET
filter is not needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this only about addition/removal? What about printer name change? Shouldn't we get notified in that case as trying to print on printer with old name will not find 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. "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
I'm afraid there's nothing Java can do to mitigate renaming the printer.
Since no values are created, removed, or changed when a remote printer is added or removed under
Connections
key, addingREG_NOTIFY_CHANGE_LAST_SET
todwNotifyFilter
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 whatREG_NOTIFY_CHANGE_NAME
filter does.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Yes, we should. But we cannot.
For Windows, nothing has changed on the local system, it's the remote system that has been changed.
No, it wouldn't because nothing has changed on the local system.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.