Username not working on NT workstation 
Author Message
 Username not working on NT workstation

Hi friends,

The code below retreives Novell user name from Win95 but doesn't
retreive it from NT workstation. Anybody has an idea why? Should I build
a different function for NT stations?

-----------Code begins here-------------

   Public Function NTDomainUserName() As String
   Dim strBuffer As String * 9
   Dim lngBufferLength As Long
   Dim lngRet As Long
   Dim strTemp As String

    lngBufferLength = 9
    lngRet = GetUserName(strBuffer, lngBufferLength)
    strTemp = UCase(Trim$(strBuffer))
    NTDomainUserName = Left(strTemp, InStr(strTemp, Chr(0)) - 1)

   End Function

-----------Code ends here-------------
--
T h e m i n h  D i e p
Programmer-analyst / Programmeur-analyste

National Research Council Canada / Conseil national de recherches Canada

Biothechnology Research Institute / Institut de recherche en
biotechnologie





Fri, 14 Jul 2000 03:00:00 GMT  
 Username not working on NT workstation

sure...
try this...

    Dim lResult As Long
    Dim lSize As Long
    Dim szName As String

    szName = Space(254)
    lSize = Len(szName) + 1
    lResult = GetUserName(szName, lSize)
    If lResult = 0 Then
        Msgbox  "Function failed!"
        Else
        Msgbox  szName
        End If

The reason I use 254, is basically because many API's require a
maximum size of anything, which like directories can be quite large.
Although you only need to set it to 16 (15 is the max user name, +1
for the Null terminator), this works very well nonetheless.



Quote:
>Hi friends,

>The code below retreives Novell user name from Win95 but doesn't
>retreive it from NT workstation. Anybody has an idea why? Should I build
>a different function for NT stations?

>-----------Code begins here-------------

>   Public Function NTDomainUserName() As String
>   Dim strBuffer As String * 9
>   Dim lngBufferLength As Long
>   Dim lngRet As Long
>   Dim strTemp As String

>    lngBufferLength = 9
>    lngRet = GetUserName(strBuffer, lngBufferLength)
>    strTemp = UCase(Trim$(strBuffer))
>    NTDomainUserName = Left(strTemp, InStr(strTemp, Chr(0)) - 1)

>   End Function

>-----------Code ends here-------------
>--
>T h e m i n h  D i e p
>Programmer-analyst / Programmeur-analyste

>National Research Council Canada / Conseil national de recherches Canada

>Biothechnology Research Institute / Institut de recherche en
>biotechnologie






Tue, 18 Jul 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Username not working on NT workstation

2. Which Web Servers work with NT Workstation ?

3. Application Crashes on Windows 95 - Works Fine on Windows NT Workstation

4. Doesn't work under NT workstation

5. RegOpenKeyEx doesn't work in Windows NT workstation

6. VB4 does not install on NT workstation

7. P&D installation problem on NT Workstation: MSADO25.TBL could not registered

8. SHGetDataFromIDList not in shell32.dll on NT Workstation??

9. RegOpenKeyEx, Not Working on Win95 (but working on win98 and NT)

10. How do I differentiate between NT Workstation and NT Server

11. How to connect to a NT domain from an NT/W2k workstation

12. workstation username/authentication

 

 
Powered by phpBB® Forum Software