Skip to main content

Refreshing session printers from the command line

ScrewDrivers Printers, the desktop app users open to pick and manage their printers, has a Refresh button on its Settings tab that tears down and rebuilds the printers in the current session. The same executable accepts command-line switches that do that rebuild silently, with no window and no prompt, and then exit. That makes it easy to refresh printers from a logon script, a scheduled task that fires when a laptop joins a network, or a remote command a help desk technician runs into a user's session.

Before you start

The switches work on any ScrewDrivers Pro or Enterprise session host running v7, whether that's a remote session host or a desktop whose applications run locally. The executable installs with the session host components at:

C:\Program Files\Tricerat\ScrewDrivers\Common\ScrewDrivers Printers.exe

Refreshing your own session needs no special rights. Refreshing another session, or every session on the host, needs to run with administrative rights on that host.

The switches​

Pass exactly one switch as the first argument. Each one accepts three spellings: bare, with a leading dash, or with a leading slash (rp, -rp, /rp), and none of them are case-sensitive.

SwitchShort formWhat it rebuilds
-refreshprinters-rpThe printers in the session you run it from
-refreshallprinters-rapThe printers in every active session on the host
-refreshuserprinters <sessionId>-rup <sessionId>The printers in one specific session, identified by its Windows session ID
-refreshuserservicebasedprinters-rsbpOnly the shared virtual printers, if you've enabled Use one shared virtual printer for each print server printer

For -rup you'll need the numeric session ID, which query session (or qwinsta) prints on the session host. Anything that isn't a valid number is logged as an error and nothing is refreshed.

Examples​

Refresh the printers in your own session from a Command Prompt or a logon script:

"C:\Program Files\Tricerat\ScrewDrivers\Common\ScrewDrivers Printers.exe" -rp

The same thing from PowerShell:

& 'C:\Program Files\Tricerat\ScrewDrivers\Common\ScrewDrivers Printers.exe' -rp

Rebuild the printers in session 3 from an elevated prompt, as a technician might after changing that user's assignments:

"C:\Program Files\Tricerat\ScrewDrivers\Common\ScrewDrivers Printers.exe" -rup 3

Rebuild printers for everyone currently logged on to the host, for example after changing a Print Server object:

"C:\Program Files\Tricerat\ScrewDrivers\Common\ScrewDrivers Printers.exe" -rap

Refreshing when a laptop changes networks​

Users whose printers are assigned by IP address or subnet get the most out of this. A scheduled task that runs -rp as the logged-on user whenever Windows reports a new network connection keeps their printers matched to wherever they've docked. Trigger the task on the Windows event log entry Microsoft-Windows-NetworkProfile/Operational, event ID 10000 (network connected), and set it to run only when the user is logged on. If those users lock rather than disconnect when they move, Rebuilding printers when users lock and unlock covers the same ground with a single registry value and no scheduled task.

How the refresh works​

The switch doesn't rebuild printers itself. It asks the ScrewDrivers Notification Service to process a disconnect followed immediately by a reconnect for the target session, which is exactly what happens when a user disconnects and reconnects their remote session. Printers are removed, assignments are evaluated again against the user's current groups, client, and network address, and the printers are built fresh. Any change you've made in ScrewDrivers Administration since the user logged on is picked up along the way.

Because the refresh rides on the disconnect and reconnect path, it depends on the session setting Delete printers on session disconnect; add on reconnect, which is on by default. With that setting turned off there's nothing to rebuild. See Print Server session settings.

The executable writes a log named for ScrewDrivers Printers under C:\ProgramData\Tricerat\Logs. If a switch appears to do nothing, that log shows which argument was parsed and whether the request reached the Notification Service.