473,414 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Windows ID & Username

77
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 !
Nov 2 '08 #1
8 6527
puppydogbuddy
1,923 Expert 1GB
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:
Expand|Select|Wrap|Line Numbers
  1. Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
  2.     "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Paste this code:
Expand|Select|Wrap|Line Numbers
  1. Function fWin2KUserName() As String
  2.     Dim lngLength As Long, lngX As Long
  3.     Dim strUserName As String
  4.     strUserName = String$(254, 0)
  5.     lngLength = 255
  6.     lngX = apiGetUserName(strUserName, lngLength)
  7.     If lngX <> 0 Then
  8.         fWin2KUserName = Left$(strUserName, lngLength - 1)
  9.     Else
  10.         fWin2KUserName = "unknown"
  11.     End If
  12. 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:
Expand|Select|Wrap|Line Numbers
  1.     Dim strUser as String
  2.     strUser = fWin2KUserName
Nov 2 '08 #2
puppydogbuddy
1,923 Expert 1GB
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
Nov 2 '08 #3
risk32
98
With this concept, is there a way to extract the email address from Outlook associated with the username?
Nov 3 '08 #4
puppydogbuddy
1,923 Expert 1GB
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.
Nov 3 '08 #5
yaaara
77
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.
Nov 4 '08 #6
puppydogbuddy
1,923 Expert 1GB
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:
--------------------------------------------------------------------------------

Expand|Select|Wrap|Line Numbers
  1. Sub test()    
  2. Dim i As Integer    
  3. Dim stEnviron As String    
  4. For i = 1 To 50        ' get the environment variable        
  5.     stEnviron = Environ(i)        ' see if there is a variable set        
  6.     If Len(stEnviron) > 0 Then            
  7.           Debug.Print i, Environ(i)        
  8.    Else            
  9.           Exit For        
  10.    End If    
  11. Next
  12. End Sub
Nov 4 '08 #7
yaaara
77
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 :(
Nov 5 '08 #8
puppydogbuddy
1,923 Expert 1GB
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?
Nov 5 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
1
by: hangaround | last post by:
I have read some codes like following: /////////////////////////////////////////// SqlConnection* conn = new SqlConnection(S"Server=localhost;" S"Database=Northwind;" S"Integrated...
4
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...
3
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...
1
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...
1
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...
1
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...
1
George Lft
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...
0
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://" +...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
isladogs
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.