代码之家  ›  专栏  ›  技术社区  ›  VVS

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

  •  2
  • VVS  · 技术社区  · 17 年前

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

    我如何使用WMI(通过PowerShell)或VB脚本来实现这一点?有没有一种我不知道的内在方式?

    编辑

    6 回复  |  直到 16 年前
        1
  •  2
  •   VVS    15 年前

    多亏了雷姆科的评论,我找到了正确的方向,最终制作了一个符合我需要的剧本。

    基本上,脚本确定用户的SID,并查看用户的注册表配置单元( HKEY_USERS\$sid\打印机\连接 )对于创建的打印机。

    $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
            }
        }
    }
    
        2
  •  1
  •   EBGreen    17 年前

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

    获取WMIObjectWin32_Printer

        3
  •  0
  •   seanyboy    16 年前

    从这里: 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
    
        4
  •  0
  •   vitaly.v.ch    16 年前

    也许你需要基于CUPS的技术?对于任何unix上的cups来说,这都是一项简单的任务,但我对Windows不太确定。

        5
  •  0
  •   Phil Eddies    9 年前

    这为我完成了解锁seanyboy答案的任务,该答案返回本地打印机。此脚本返回用户连接的网络打印机,在终端服务器\Citrix会话上运行良好

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

        6
  •  -1
  •   vitaly.v.ch    17 年前

    据我所知,您可以阅读注册表中的一些字段。

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