Hello,
Is it possible to detect the login userid from a computer?
I would like to find this userid and find the corresponding username in an
excel file.
Thank you.
Jean-Guy Marcil - 13 Sep 2006 15:06 GMT
DeCock was telling us:
DeCock nous racontait que :
> Hello,
> Is it possible to detect the login userid from a computer?
> I would like to find this userid and find the corresponding username
> in an excel file.
Would this help:
http://www.mvps.org/word/FAQs/MacrosVBA/GetCurUserName.htm
?

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Helmut Weber - 13 Sep 2006 15:20 GMT
Hi DeCock,
not that I understand all of this, but it seems to work.
Declare Function GetUserName Lib _
"advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
' ----------------------------------------------------
Private Function WhoAmI() As String
Dim Buffer As String ' Puffer fuer den Benutzernamen
Dim BuffSize As Long ' Groesse des Puffers
GetUserName Buffer, BuffSize
Buffer = Space$(BuffSize) ' Speicherplatz reservieren
GetUserName Buffer, BuffSize
WhoAmI = LCase$(Left$(Buffer, BuffSize - 1)) ' '\0' entfernen
End Function
Sub Test0001()
MsgBox WhoAmI
End Sub

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Jonathan West - 13 Sep 2006 15:22 GMT
> Hello,
> Is it possible to detect the login userid from a computer?
> I would like to find this userid and find the corresponding username in an
> excel file.
>
> Thank you.
How to get the username of the current user
http://www.word.mvps.org/FAQs/MacrosVBA/GetCurUserName.htm

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
Steve Yandl - 13 Sep 2006 18:28 GMT
This should get you what you want.
Sub FindUserName()
Set objNetwork = CreateObject("WScript.Network")
strUser = objNetwork.UserName
MsgBox strUser
End Sub
Steve
> Hello,
> Is it possible to detect the login userid from a computer?
> I would like to find this userid and find the corresponding username in an
> excel file.
>
> Thank you.
Russ - 02 Oct 2006 09:14 GMT
The Windows Environmental Variables are available too:
strDrive = Environ("HOMEDRIVE") 'hard drive letter the system is running on.
strPathDocs = strDrive & Environ("HOMEPATH") & "\My Documents"'current
user's place.
'current user's temp directory, if needed, to temporarily save files.
strPathTemp = Environ("TEMP")
> This should get you what you want.
>
[quoted text clipped - 12 lines]
>>
>> Thank you.

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID