Hi Guys !!
Is there any way we can extract the Windows ID & Username associated with it using VBA?
For example, if my Windows ID is "kumar1" and I have a Username "yaaara" associated with it, what is the way to extract both? I am able to extract the ID but not the username..
Any Ideas please?
Thanks !
8 6527
If you can get the Windows ID, then see this thread about getting the username: http://bytes.com/forum/thread191309.html
The code below credited to rsmith@cta.org, explains how to use a UDF in an ms access module to obtain the username from Windows 2000:
If not already done so, create a new module in the Modules section.
Paste this statement into the General Declarations section of the module: - Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
-
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Paste this code: -
Function fWin2KUserName() As String
-
Dim lngLength As Long, lngX As Long
-
Dim strUserName As String
-
strUserName = String$(254, 0)
-
lngLength = 255
-
lngX = apiGetUserName(strUserName, lngLength)
-
If lngX <> 0 Then
-
fWin2KUserName = Left$(strUserName, lngLength - 1)
-
Else
-
fWin2KUserName = "unknown"
-
End If
-
End Function
You can run this function (fWin2KUserName) from anywhere within your application. The best way is to set some variable to be equal to the function: - Dim strUser as String
-
strUser = fWin2KUserName
I just found out that there is an even easier way to get the username....use the Environ() function.
MsgBox "Network Name = " & Environ("username")
MsgBox "Computer Name = " & Environ("computername")
See this link for further details: http://office.microsoft.com/en-us/ac...288311033.aspx
With this concept, is there a way to extract the email address from Outlook associated with the username?
With this concept, is there a way to extract the email address from Outlook associated with the username?
I am not aware of any publically available code to extract the email address for a given username. There is code on the MSDN public forum to extract email addresses from an email folder at this link: http://forums.microsoft.com/msdn/Sho...70080&SiteID=1
I am sure there are third party add-ins that extract email addresses based on the username.
Thanks for your replies guys.. However, using both the methods as advised returns the same result i.e. the windows ID and not the Name associated with that ID.
Let me try to explain the problem again.
In a domain based environment (Office Network), one gets a user ID and their names are associated with the IDs
If I press Ctrl+Alt+Del after logging in, I get a screen that tells me <yaaara> is logged in as <Domain Name>\kumar1
Also I get the logon date and options to logoff etc.
Using the above mentioned methods, I get "kumar1" but I am looking to extract "yaaara"
I hope I was able to explain properly.
Thanks.
You described everything clearly, but did not identify the enviromental variable name that you are looking for. Is it one of the environmental variables listed below? I have already tried with username and computername....and you said neither of them give you what you want.
List of common environment variables.
ALLUSERSPROFILE
APPDATA
AVENGINE
CLIENTNAME
CommonProgramFiles
COMPUTERNAME
ComSpec
FP_NO_HOST_CHECK
HOMEDRIVE
HOMEPATH
INCLUDE
INOCULAN
LIB
LOGONSERVER
NUMBER_OF_PROCESSORS
OS
Path
PATHEXT
PROCESSOR_ARCHITECTURE
PROCESSOR_IDENTIFIER
PROCESSOR_LEVEL
PROCESSOR_REVISION
ProgramFiles
SESSIONNAME
SystemDrive
SystemRoot
TEMP
TMP
USERDOMAIN
USERNAME
USERPROFILE
VS71COMNTOOLS
WecVersionForRosebud.FF0
windir
Courtesy of Rob Cooper, MS
Custom environment variables could also be created and vary by system. You can write a loop to enumerate them as shown below:
Code:
-------------------------------------------------------------------------------- - Sub test()
-
Dim i As Integer
-
Dim stEnviron As String
-
For i = 1 To 50 ' get the environment variable
-
stEnviron = Environ(i) ' see if there is a variable set
-
If Len(stEnviron) > 0 Then
-
Debug.Print i, Environ(i)
-
Else
-
Exit For
-
End If
-
Next
-
End Sub
Unfortunately, none of these environment variables gives me the desired output.. several of these point towards the lan ID but none of these point to the associated name..
Not sure how else to describe the problem in more clarity :(
Unfortunately, none of these environment variables gives me the desired output.. several of these point towards the lan ID but none of these point to the associated name..
Not sure how else to describe the problem in more clarity :(
I understand what you want, but I don't know what the variable name is called. In your first post you stated that the variable you were looking for was the username, but you say Environs("username") doesn't give it to you. So if it isn't username, what is the name of the variable that you are looking for?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Philip D Heady |
last post by:
Hi, I'm validating a simple form for input via post ($PHP_SELF). Near the
end I check for username and password. I'm using simple if, elseif, else
statements.
I require them to enter password...
|
by: hangaround |
last post by:
I have read some codes like following:
///////////////////////////////////////////
SqlConnection* conn =
new SqlConnection(S"Server=localhost;"
S"Database=Northwind;"
S"Integrated...
|
by: Patrick.O.Ige |
last post by:
I have a code below.(It validates against a SQL DB(login page).thats is
giving me an error!
When i try to use :- Session = dr.ToString();
To catch the username so as to redirect the user logged in...
|
by: Jeremy |
last post by:
I am relativly new to ASP.NET, and my question is this:
Is it better to create a wrapper class that contains all the running
settings for the application and then load that into the app state, or...
|
by: Ike |
last post by:
I'm absolutely stuck, hoping someone can illuminate my sitatuation. I have a
string (a query) where I need to dynamically be able to change one part of
the the string (the part where .username...
|
by: TokyoJ |
last post by:
I use a popup / prompt requesting the visitor to enter a USERNAME so after the user clicks SUBMIT on the prompt all the pages in the site should greet the user with Hi, USERNAME.
But there are two...
|
by: mfunkmann |
last post by:
Hi,
I recently got an error and I don't know how to fix it:
Error 1 'System.Data.DataColumn' does not contain a definition for
'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO
I...
|
by: George Lft |
last post by:
ok, first of all, i built my register page using dreamweaver tool which the codes haven been out of control. Now i'm thinking that turning over everything - by using this another set of codes. And...
|
by: tpeczek |
last post by:
Hi
I'm writing windows service which is suppose to acces IIS metabase using DirectoryServices. I'm accesing IIS using the code below:
DirectoryEntry iisEntry = new DirectoryEntry(@"IIS://" +...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |