我正在嘗試編寫一個腳本來檢查我們網絡上的哪些打印服務器用戶正在連接到。爲此,我試圖檢查Printer \ Connections下列出的註冊表值。在我的本地機器下面兩種方法都工作:使用Powershell遠程驗證註冊表項
1)
GET-ChildItem HKCU:\打印機\連接
輸出:
Hive: HKEY_CURRENT_USER\Printers\Connections
Name Property
----- --------
,,printServer,printerName GuidPrinter : {guid}
Server : \\printserver.domain
Provider : win32spl.dll
LocalConnection : 1
2)
>> Get-ChildItem HKCU:\Printers\Connections | ForEach-Object {Get-ItemProperty $_.pspath}
而且該命令的輸出是:
GuidPrinter : {guid}
Server : \\printServer.domain
Provider : win32spl.dll
LocalConnection : 1
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Printers\Connections\,,printServerName,printerName
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Printers\Connections
PSChildName : ,,printServerName, printerName
PSProvider : Microsoft.PowerShell.Core\Registry
通過本身,無論這些實現的被容易地應用到遠程機器。我最近試圖從遠程機器上獲取上面顯示的相同信息是:
$machine = 'computerName';
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('CurrentUser',$machine);
$regKey = $reg.OpenSubKey("Printers\Connections");
$regKey.GetValueName()
# I also tried the following which I didn't think
# would work, but I was grasping at straws:
# Get-ChildItem $regKey;
上面的代碼不返回任何內容。它不會引發錯誤,但是regKey會返回一個空字符串。
有誰知道一種替代解決方案來獲取我正在查找的信息或在上面的實現中看到錯誤嗎?
謝謝。
好的,這是一個好主意。這樣我就可以使用我在第一篇文章中提到的前兩行中的任意一行,然後實現一種方法將結果發回給我。我現在不在我的電腦,但是我會在我回來後再測試一下。謝謝回覆。 – wrigley06
沒問題,讓我們知道你是否需要幫助,不要忘了標記答案,以幫助其他人誰有這個相同的問題 – Luke
@ Luke雖然是真的,使用HKCU不會給你的結果還需要其他方法來遠程獲取這些信息。它在很大程度上取決於環境,你可以用.net和wmi做到這一點。 – Matt