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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top