各位好~
想跟各位請教一件事情,我想用VBS取得使用者的名字(顯示名稱),不知道該怎麼處理,還請大家幫忙。
感謝!
objWMIService = GetObject("winmgmts:\" & strComputer & "\root\cimv2")
WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.UserName > 可以抓到登入帳號
WshNetwork.ComputerName > 可以抓到電腦名稱
試試:
'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)