So the Windows Script Host Object Model is a great COM library scriptable in VBA with plenty of features worth blogging. First up we can show the Network object. This can give a user's computer name and also help query if the user is logged onto an enterprise network (which may influence licensing).
Sub Illustrating_WshNetwork()
'* Tools->References Windows Script Host Object Model (C:\Windows\SysWOW64\wshom.ocx)
Dim oNetwork As New IWshRuntimeLibrary.WshNetwork
Dim sOrganization As String, sSite As String, sUserProfile As String
sOrganization = "#N/A"
sSite = "#N/A"
sUserProfile = "#N/A"
SafeGetNetworkOrganizationSiteUserProfile oNetwork, sOrganization, sSite, sUserProfile
Debug.Print "ComputerName:" & oNetwork.ComputerName
Debug.Print "UserName:" & oNetwork.UserName
Debug.Print "UserDomain:" & oNetwork.UserDomain
Debug.Print "Site:" & sSite
Debug.Print "Organization:" & sOrganization
Debug.Print "UserProfile:" & sUserProfile
Stop
End Sub
Sub SafeGetNetworkOrganizationSiteUserProfile(ByVal oNetwork As WshNetwork, _
ByRef psOrganization As String, ByRef psSite As String, ByRef psUserProfile As String)
On Error Resume Next
psOrganization = oNetwork.Organization
psSite = oNetwork.Site
psUserProfile = oNetwork.UserProfile
End Sub
No comments:
Post a Comment