Jay

This is my code to do the same. It works in MapInfo 6.0, 7.0 and 7.5 on
Windows NT, 2K and XP.

Good luck

Matt


Declare Function GetUserName Lib "advapi32" Alias GetUserNameA(lpBuffer As
String, nSize As Integer) As Integer
Declare Function GetUserID(strUserID as string) as Logical

function GetUserID(strUserId as string) as logical

  Dim strBuffer As String
  Dim intBufferLen As Integer

  OnError goto Err_Handler

  intBufferLen = 100
  strBuffer = Space$(intBufferLen)

  if GetUserName(strBuffer, intBufferLen) then
    strUserID = Left$(strBuffer, intBufferLen - 1)
    GetUserId = True
  end if

  Exit Function

Err_handler:
  print Error$
  GetUserId = False

End Function

-----Original Message-----
From: Jay C Russell [mailto:[EMAIL PROTECTED]
Sent: 14 July 2004 15:39
To: [EMAIL PROTECTED]
Subject: MI-L GetUserName Api Problem


>From a previous post by Jacques Paris,  I created a program to return the
current user name logged into Windows.
I am running Windows 2k with Mapinfo 7.0.   When I test the function the
slength returned is of the correct length, but the username
value is blank.  Help appreciated as always!  Source code included below.

Thanks,
Jay Russell



Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal
lpBuffer As String, nSize As Integer) As Integer

Sub FindUser

Dim username As String ' receives name of the user


Dim slength As Integer ' length of the string


Dim retval As Integer ' 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.)


Print "The name of the current user is "+ username


End Sub 'FindUser


---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 12607



--------------------------------------------------------------------------------------
1. This message and any files or other attachments transmitted with it is intended for 
the addressee only. They are private and confidential and are for the sole use of the 
intended recipient. Copyright in this message and any accompanying document created by 
us is owned by us. If you are not the intended recipient of this e-mail or any part of 
it please telephone Head Office at the number shown below or notify us by e-mail at: 
[EMAIL PROTECTED] You should not use or disclose to any other person the contents of 
this message or its attachments or files (if any), nor take copies.

2. We have taken every reasonable precaution to ensure that any attachment to this 
e-mail has been swept for viruses, but we cannot accept any liability for any loss or 
damage sustained as a result of software viruses and would advise that you carry out 
your own virus checks before opening any attachment or file. Please note as well that 
e-mails can be falsified: in circumstances where the content of this e-mail is 
important you should not rely on its integrity without checking it by telephone or fax.

3. This message and any files or attachments have been sent to you with the sender's 
knowledge that the contents may be intercepted, monitored and regulated by us in the 
course of transmission and in compliance with the Regulation of Investigatory Powers 
Act 2000. If you reply to this message and/or send a message to us in any other way 
you accept that the contents, including attachments or files, of that message may be 
intercepted, monitored and regulated by us in the course of transmission and in 
compliance with the Regulation of Investigatory Powers Act 2000. If for any reason you 
do not wish to consent to the above please contact us on the number below.

GEOGRAPHERS' A-Z MAP COMPANY LIMITED
Fairfield Road
Borough Green
Sevenoaks
Kent
TN15 8PP
Telephone: 01732 781000
Fax: 01732 780677

--------------------------------------------------------------------------------------

---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 12610

Reply via email to