Get user nameOp dinsdag 16 oktober 2001 14:28 schreef koely het volgende:
ik moet de username uit windows NT halen, het liefst ook de Novell context, weet iemand hoe dat moet?
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As LongDeclare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Trying to establish voice contact... please yell into keyboard.
dat ga ik even proberen, ik ben het namenlijk nog een beetje aan het leren, ik kan wel programmeren in C++, PHP en pascal, maar dit moet ik nog even onder de knie krijgen
Trying to establish voice contact... please yell into keyboard.
Van http://www.vbapi.com/ref/g/getusername.html
Edit: 2min te laat
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long ' Display the name of the user currently logged on. Dim username As String ' receives name of the user Dim slength As Long ' length of the string Dim retval As Long ' return value ' Create room in the buffer to receive the returned string. username = Space(255) ' room for 255 characters slength = 255 ' initialize the size of the string ' Get the user's name and display it. retval = GetUserName(username, slength) ' slength is now the length of the returned string username = Left(username, slength - 1) ' extract the returned info from the buffer ' (We subtracted one because we don't want the null character in the trimmed string.) Debug.Print "The name of the current user is "; username |
Edit: 2min te laat
ik heb het zo ingevoerd:
en toch krijk ik errors, wat doe ik verkeerd?Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Dim username As String ' receives name of the user
Dim slength As Long ' length of the string
Dim retval As Long ' return value
Private Sub Form_Load()
' Create room in the buffer to receive the returned string.
username = Space(255) ' room for 255 characters
slength = 255 ' initialize the size of the string
' Get the user's name and display it.
retval = GetUserName(username, slength) ' slength is now the length of the returned string
username = Left(username, slength - 1) ' extract the returned info from the buffer
' (We subtracted one because we don't want the null character in the trimmed string.)
Debug.Print "The name of the current user is "; username
End Sub
edit:
sorry wou nog wat verbeteren tijdens het Versturen dus ramde ik op de ESC knop en later bleek dat die al was gestuurd
sorry wou nog wat verbeteren tijdens het Versturen dus ramde ik op de ESC knop en later bleek dat die al was gestuurd
dan doe ik dit:
compile error, only comments may appear after end sub, end function, or end property, ik weet echt niet hoe ik dat voor elkaar moet krijgen
en dan krijg ik nog een error:Dim username As String ' receives name of the user
Dim slength As Long ' length of the string
Dim retval As Long ' return value
Private Sub Form_Load()
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
' Create room in the buffer to receive the returned string.
username = Space(255) ' room for 255 characters
slength = 255 ' initialize the size of the string
' Get the user's name and display it.
retval = GetUserName(username, slength) ' slength is now the length of the returned string
username = Left(username, slength - 1) ' extract the returned info from the buffer
' (We subtracted one because we don't want the null character in the trimmed string.)
Debug.Print "The name of the current user is "; username
End Sub
compile error, only comments may appear after end sub, end function, or end property, ik weet echt niet hoe ik dat voor elkaar moet krijgen
Nee, zo dus:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Sub Form_Load() Dim username As String ' receives name of the user Dim slength As Long ' length of the string Dim retval As Long ' return value ' Create room in the buffer to receive the returned string. username = Space(255) ' room for 255 characters slength = 255 ' initialize the size of the string ' Get the user's name and display it. retval = GetUserName(username, slength) ' slength is now the length of the returned string username = Left(username, slength - 1) ' extract the returned info from the buffer ' (We subtracted one because we don't want the null character in the trimmed string.) Debug.Print "The name of the current user is "; username End Sub |
Pagina: 1