Help GetUserName return null 
Author Message
 Help GetUserName return null

I have been tring to get the user name of the logged in user(my machine is
setup  for multiple users).

In the general section I have defined:
Private Declare Function getusername Lib "Advapi32.dll" _
       Alias "GetUserNameA" (ByVal User As String, cnt As Double) As Long

    er1 = getusername(User, cnt)
    Form1.Text1.Text = Form1.Text1.Text + ">" + User + "<>" + Str(er1) +"<"
  "><>1<"
The above returns a null string and er1 = 1 indicating that the length of
the username is 1

Does any see my error?


Thank You.



Wed, 22 Nov 2000 03:00:00 GMT  
 Help GetUserName return null

Quote:

> I have been tring to get the user name of the logged in user(my machine is
> setup  for multiple users).

> In the general section I have defined:
> Private Declare Function getusername Lib "Advapi32.dll" _
>        Alias "GetUserNameA" (ByVal User As String, cnt As Double) As Long

>     er1 = getusername(User, cnt)
>     Form1.Text1.Text = Form1.Text1.Text + ">" + User + "<>" + Str(er1) +"<"
>   "><>1<"
> The above returns a null string and er1 = 1 indicating that the length of
> the username is 1

> Does any see my error?


> Thank You.

Greetings Robert,

I'm not a VB programmer, but my offhand guess is that your field "USER"
which is to hold the returned user name has not been pre-allocated.
Based on your snippet above, you are passing an undefined variable to
the API.  You may just need to add the line

        User = SPACE$(128)

to your code prior to making the function call.

Take this for what it's worth.

Paul



Wed, 22 Nov 2000 03:00:00 GMT  
 Help GetUserName return null

Quote:
> I have been tring to get the user name of the logged in user(my machine is
> setup  for multiple users).

A less tidy, but simpler way than all that is to run the command "net
config >info.txt", then open info.txt for input, take the second line
which will be "USER       Fred Bloggs", then kill info.txt. (Win95)

Simon.



Thu, 23 Nov 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. GetUserName returns 1245

2. Help- No Recordsource returned when using NULL

3. Null Null Null!!!!!!!!!

4. Null, Null, Null!

5. Help: Getting GetUserName from a client-sided script?

6. double null question [2 * Null = Null] !!!

7. GetUserName stopped working, please help!

8. Date returns Null in Form code

9. Return Null instead of 0 from numeric function?

10. vb.net NetUserEnum returning Null object reference

11. ADODB.Command Output Params return null for GUID types

12. How to test for a NULL return value from FindByValue in vb.net

 

 
Powered by phpBB® Forum Software