Environ function

G

Grodon

Does anyone know if the Visual Basic function Environ
("username") works with Windows 98? Maybe I'm specifying
the wrong environment variable string name. I'm trying to
get the currently logged on user.

Thanks in adv.
Grodon
 
C

Chip Pearson

Grodon,

I don't know about environment variables in Windows 98, but the
following code will work in all versions.

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

Sub AAA()
Dim UName As String
Dim L As Long
Dim Res As Long
L = 255
UName = String(L, " ")
Res = GetUserName(UName, L)
UName = Left(UName, L - 1)
Debug.Print UName
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Top