-
July 19th, 2002, 09:39 AM
#1
Can I get user from windows ?
Does anyone know ? Can I get the logged in user name from windows/windows NT , or smtg in VB ? directly with code (for use in MS Access forms / VB) ?
-
July 19th, 2002, 10:09 AM
#2
Code:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Load()
Dim strUserName As String
strUserName = String(100, Chr$(0))
GetUserName strUserName, 100
strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
MsgBox "Hello " + strUserName
End Sub
TimCottee
I know a little about a lot of things and a lot about very little.
Brainbench MVP For Visual Basic
http://www.brainbench.com
MCP, MCSD, MCDBA, CPIM
-
July 19th, 2002, 10:13 AM
#3
There is an API function (see Platform SDK)
The function is:
GetUserName
Also there is an example provided.
I am not sure about MS Access but using VB but you shoud have no problems using it from VB.
-
July 19th, 2002, 10:30 AM
#4
user the function environ
the fonction environ give lot of thing
by example:
for i=0 to 30
msgbox environ(i)
next i
what your asking: environ("username")
Hope this help.
Fardoche
-
April 4th, 2005, 01:07 PM
#5
Re: Can I get user from windows ?
Let's keep it simple. In this little routine you can return the Username, Operating System, Path and the Computer Name.
==========================================================
Private Sub cmdGetInfo_Click()
Dim strPath As String
Dim strUserName As String
Dim strCompName As String
Dim strOpSystem As String
lblPath.WordWrap = True
strPath = Environ("Path")
strUserName = Environ("UserName")
strCompName = Environ("ComputerName")
strOpSystem = Environ("OS")
lblPath = strPath
lblUserName = strUserName & " ---- " & strCompName
lblOpSystem = strOpSystem
End Sub
==========================================================
NetWiz
-
April 5th, 2005, 05:41 AM
#6
Re: Can I get user from windows ?
type SET at a command line, and you will see all the things you can ask environ for..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|