On Error GoTo error
Dim sUsername As String
Dim objNetwork As Object
sUsername = Environ$("username")
If sUsername = "" Then
Set objNetwork = CreateObject("WScript.Network")
sUsername = objNetwork.username
Set objNetwork = Nothing
End If
GetWindowsUser = sUsername
Exit Function
error:
Debug.Print Err.Description
GetWindowsUser = ""
End Function
Public Function GetComputerName() As String
On Error GoTo error
Dim sComputerName As String
Dim objNetwork As Object
sComputerName = Environ$("ComputerName")
If sComputerName = "" Then
Set objNetwork = CreateObject("WScript.Network")
sComputerName = objNetwork.ComputerName
Set objNetwork = Nothing
End If
GetComputerName = sComputerName
Exit Function
error:
Debug.Print Err.Description
GetComputerName = ""
End Function
No hay comentarios:
Publicar un comentario