current user ID

  • Thread starter Thread starter Karen
  • Start date Start date
K

Karen

How to get the current user ID? e.g. "jsmith"

I just know that the following code can get the name of user, e.g. "John
Smith"
Set MyNameSpace = Application.GetNameSpace("MAPI")
MsgBox MyNameSpace.CurrentUser

Thanks very much!
 
MyNameSpace.CurrentUser.Address
BTW, MyNameSpace.CurrentUser is an object, not a string. If you use it like
that, it will returns its default property, which happens to be the Name
property.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
In versions previous to Outlook 2003, you'd run into the security guard. Another way would be to use the Windows Shell Scripting to do it:

Set Wshshell = WScript.CreateObject("WScript.Shell")
strDeskPath = Wshshell.SpecialFolders("Desktop")

myArray = Split(strDeskPath, "\", -1, 1)

strUserName = myArray(2)

John
 
Which of course in many cases will return a sting such as "Dell Preferred
Customer"... <g>




John Riddle said:
In versions previous to Outlook 2003, you'd run into the security guard.
Another way would be to use the Windows Shell Scripting to do it:
 
Really? I've never had that happen. For me and my users this always returns the user profile logged into under Documents and Settings. Such as: "username.userdomain" or just plain "username" or "username.userdomain.000", but I've never seen "Dell Preferred User" (or anything like that). Under what scenario would it return such a string?

John
 
In a non-networked setup where the user never bothered to enter a Windows
user name you see things like that all the time. This occurs more often with
home setups especially where no Windows logon or profiles are used. It also
can depend on the Windows version.

If you are writing code for a defined set of users, such as in a business
environment or Exchange environment you can restrict what you do because you
can define your environment. When coding for assorted possible users where
different setups, Windows and Outlook versions might be used you have to
expect Murphy's Law to take effect.




John Riddle said:
Really? I've never had that happen. For me and my users this always
returns the user profile logged into under Documents and Settings. Such as:
"username.userdomain" or just plain "username" or "username.userdomain.000",
but I've never seen "Dell Preferred User" (or anything like that). Under
what scenario would it return such a string?
 
Yeah, I just have business users here. They all have logins. If I were creating and add-in or something, I'd probably test for various purposes, but my job here is pretty easy in that respect. I keep them all on the same OS/Office Version/Server, etc.

Thanks.

John
 
Back
Top