
Username not working on NT workstation
sure...
try this...
Dim lResult As Long
Dim lSize As Long
Dim szName As String
szName = Space(254)
lSize = Len(szName) + 1
lResult = GetUserName(szName, lSize)
If lResult = 0 Then
Msgbox "Function failed!"
Else
Msgbox szName
End If
The reason I use 254, is basically because many API's require a
maximum size of anything, which like directories can be quite large.
Although you only need to set it to 16 (15 is the max user name, +1
for the Null terminator), this works very well nonetheless.
Quote:
>Hi friends,
>The code below retreives Novell user name from Win95 but doesn't
>retreive it from NT workstation. Anybody has an idea why? Should I build
>a different function for NT stations?
>-----------Code begins here-------------
> Public Function NTDomainUserName() As String
> Dim strBuffer As String * 9
> Dim lngBufferLength As Long
> Dim lngRet As Long
> Dim strTemp As String
> lngBufferLength = 9
> lngRet = GetUserName(strBuffer, lngBufferLength)
> strTemp = UCase(Trim$(strBuffer))
> NTDomainUserName = Left(strTemp, InStr(strTemp, Chr(0)) - 1)
> End Function
>-----------Code ends here-------------
>--
>T h e m i n h D i e p
>Programmer-analyst / Programmeur-analyste
>National Research Council Canada / Conseil national de recherches Canada
>Biothechnology Research Institute / Institut de recherche en
>biotechnologie