枚举特定终端服务器会话的打印机

发布于 2024-07-16 03:34:33 字数 330 浏览 7 评论 0原文

我正在寻找一种方法来查看特定用户已将哪些打印机映射到他或她的 TS 会话中。

如何使用 WMI(通过 PowerShell)或 VB 脚本实现此目的? 有没有我不知道的内置方法?

编辑:在我们的构造中,RDP 客户端对本地打印机的映射被禁用。 用户可以在登录期间通过 VBS 脚本创建打印机,并在注销时删除打印机。

因此,我们的 TS 服务器上没有直接安装打印机,并且查询 Win32_Printers WMI 类不会返回任何内容。 打印机安装在专用打印服务器上。 查询该服务器上的打印机将返回所有打印机,而不是为单个用户映射的打印机。

I am looking for a way to see what printers a specific user has mapped into his or her TS session.

How can I achieve this with WMI (via PowerShell) or VB-Script? Is there a built-in way I'm not aware of?

EDIT: In our construct mapping of local printers by the RDP-Client is disabled. Users get their printers created during login via VBS-Script and deleted during logoff.

So there's no printers installed directly on our TS server and querying the Win32_Printers WMI class returns nothing. The printers are installed on a dedicated print server. Querying the printers on that server returns ALL printers and not the one mapped for a single user.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

表情可笑 2024-07-23 03:34:34

从这里: http://www.microsoft.com/technet /scriptcenter/guide/sas_prn_tart.mspx?mfr=true

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_Printer")
For Each objPrinter in colInstalledPrinters
 Wscript.Echo "Name: " & objPrinter.Name
 Wscript.Echo "Location: " & objPrinter.Location
Next

From here: http://www.microsoft.com/technet/scriptcenter/guide/sas_prn_tart.mspx?mfr=true

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_Printer")
For Each objPrinter in colInstalledPrinters
 Wscript.Echo "Name: " & objPrinter.Name
 Wscript.Echo "Location: " & objPrinter.Location
Next
丢了幸福的猪 2024-07-23 03:34:34

也许您需要基于 CUPS 的技术? 对于任何 Unix 上的 cups 来说这都是简单的任务,但我不确定 Windows 上是否如此。

May be You need CUPS based tecnology? It's simple task for cups on any unix but I'm not sure about Windows.

铁轨上的流浪者 2024-07-23 03:34:34

这对我来说是成功的,unlick seanyboy 答案返回本地打印机,此脚本返回用户连接到的网络打印机,在终端服务器 \ Citrix 会话上运行良好

http://www.geekshangout.com/vbs-script-to-list- the-network-printers-a-user-is-connected-to/

This did the trick for me unlick seanyboy answer which returns the local printers this script return the network printers a users is connected to, works fine on a Terminal Server \ Citrix session

http://www.geekshangout.com/vbs-script-to-list-the-network-printers-a-user-is-connected-to/

柠栀 2024-07-23 03:34:34

据我了解,您可以阅读注册表中的某些字段。

PS:我更喜欢使用 Linux 进行终端服务;)

As far as I understand You can read some field in Registry.

PS: I prefer to use Linux for terminal service ;)

晚风撩人 2024-07-23 03:34:33

感谢雷姆科的评论,我被引导到了正确的方向,并最终制作了一个满足我需要的脚本。

基本上,该脚本确定用户的 SID,并在用户的注册表配置单元 (HKEY_USERS\$sid\Printers\Connections) 中查找已创建的打印机。

这是快速但肮脏的 powershell 脚本:

$server = 'servername'
$userName = 'username'

$regHKLM = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $server)
$regProfileList = $regHKLM.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")

foreach ($sid in $regProfileList.GetSubKeyNames())
{
    $profileImagePath = $regProfileList.OpenSubKey($sid).GetValue("ProfileImagePath")
    if ($profileImagePath.EndsWith("\$userName"))
    {
        $regHKU = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("Users", $server)
        $regUser = $regHKU.OpenSubKey("$sid\Printers\Connections")
        foreach ($printer in $regUser.GetSubKeyNames())
        {
            $printer.Replace(",", "\")  # backslashes are replaced with commas, revert that
        }
    }
}

Thanks to Remko's comment I was put into the right direction and finally made a script that did what I needed.

Basically the script determines the SID of the user and looks in the user's registry hive (HKEY_USERS\$sid\Printers\Connections) for the created printers.

Here's the quick and dirty powershell script:

$server = 'servername'
$userName = 'username'

$regHKLM = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $server)
$regProfileList = $regHKLM.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")

foreach ($sid in $regProfileList.GetSubKeyNames())
{
    $profileImagePath = $regProfileList.OpenSubKey($sid).GetValue("ProfileImagePath")
    if ($profileImagePath.EndsWith("\$userName"))
    {
        $regHKU = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("Users", $server)
        $regUser = $regHKU.OpenSubKey("$sid\Printers\Connections")
        foreach ($printer in $regUser.GetSubKeyNames())
        {
            $printer.Replace(",", "\")  # backslashes are replaced with commas, revert that
        }
    }
}
魂归处 2024-07-23 03:34:33

我现在无法签入 TS 会话,但这通常在 powershell 中执行:

Get-WMIObject Win32_Printer

I can't check in a TS session right now, but this does it normally in powershell:

Get-WMIObject Win32_Printer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文