Another Citrix question


Posted by Jim on December 04, 2001 12:58 PM

Is it possible to grab the network user's login name and plug it into a specific cell? (Excel 97) Generic name from File | Properties won't work here.

Posted by Colo on December 05, 2001 10:18 PM

Hi Jim!
Can WHS be used with the computer?
If so, please try this.

Sub test()
MsgBox "ComputerName " & ComputerName & ":" & _
"UserName" & ":" & UserName
End Sub
Function UserName() As String
Dim objWSH As Object
Set objWSH = CreateObject("WScript.Network")
UserName = objWSH.UserName
Set objWSH = Nothing
End Function

Function ComputerName() As String
Dim objWSH As Object
Set objWSH = CreateObject("WScript.Network")
ComputerName = objWSH.ComputerName
Set objWSH = Nothing
End Function



Posted by Jim on December 06, 2001 6:14 AM

Not sure about WHS but I did get what I wanted with the following code:

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" ( _
ByVal lpBuffer As String, nSize As Long) As Long
Function UserLoggedIn() As String
Dim MyString As String
Dim StringLen As Long

MyString = String(255, Chr(0))
StringLen = Len(MyString) - 1

GetUserName MyString, StringLen
UserLoggedIn = Trim(MyString)
End Function