iT邦幫忙

0

VBS抓取登入者名稱問題

vbs
Ryan 2019-09-16 16:11:271751 瀏覽
  • 分享至 

  • xImage

各位好~

想跟各位請教一件事情,我想用VBS取得使用者的名字(顯示名稱),不知道該怎麼處理,還請大家幫忙。

感謝!

objWMIService = GetObject("winmgmts:\" & strComputer & "\root\cimv2")
WshNetwork = WScript.CreateObject("WScript.Network")

WshNetwork.UserName > 可以抓到登入帳號
WshNetwork.ComputerName > 可以抓到電腦名稱

ccutmis iT邦高手 2 級 ‧ 2019-09-16 16:29:07 檢舉
https://stackoverflow.com/questions/20626863/can-you-get-the-pc-user-name-in-vbs
Ryan iT邦新手 1 級 ‧ 2019-09-16 17:02:00 檢舉
感謝回覆,這個好像只是登入帳號,不是"顯示名稱"。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
Jason Cheng (節省哥)
iT邦研究生 3 級 ‧ 2019-09-16 17:28:38
最佳解答

試試:

'Define Target Computer
strComputer = "."

'Set object values
Set oShell = CreateObject("WScript.Shell")
Set oNetwork = CreateObject("Wscript.Network")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

'Define ASCII Characters
chrSpace = Chr(32)
chrSingleQuote = Chr(39)
chrDoubleQuote = Chr(34)

'Gather Information from WMI

'Query # 1 - Gather the display name of the currently logged in user
Set oDisplayNames = oWMI.ExecQuery("SELECT * FROM Win32_NetworkLoginProfile Where Name = " & chrSingleQuote & oNetwork.ComputerName & "\\" & oNetwork.UserName & chrSingleQuote)
	For Each oDisplayName In oDisplayNames
		strFullName = oDisplayName.FullName
Next

WScript.Echo(strFullName)

來源:
https://community.spiceworks.com/topic/441320-need-wmi-script-to-display-user-s-display-name-in-bginfo

Ryan iT邦新手 1 級 ‧ 2019-09-16 17:31:07 檢舉

感謝!

我要發表回答

立即登入回答