Announcement

Collapse
No announcement yet.

returning the computer name and user name

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • returning the computer name and user name



    Hi there
    could u pls reemind me of what is this?
    Application.CommandBars("ply").Enabled = False

    --------------------------------------------------------
    Could u pls tell me how to use this code ?
    i tried them, but............

    Function for returning the computer name

    'The function below will return the computer name for the
    ' machine running the code, works in both Windows NT and Windows95/98.

    Code:
    Private Declare Function GetComputerName Lib "kernel32" _
        Alias "GetComputerNameA" _
        (ByVal lpBuffer As String, nSize As Long) As Long
    
    
    Function ReturnComputerName() As String
    Dim rString As String * 255, sLen As Long, tString As String
        tString = ""
        On Error Resume Next
        sLen = GetComputerName(rString, 255)
        sLen = InStr(1, rString, Chr(0))
        If sLen > 0 Then
            tString = Left(rString, sLen - 1)
        Else
            tString = rString
        End If
        On Error GoTo 0
        ReturnComputerName = UCase(Trim(tString))
    End Function

    and this code as well:

    Function for returning the user name

    'The function below will return the user name for the logged on user,
    'works in both Windows NT and Windows95/98.

    Code:
    Public Declare Function GetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    Function ReturnUserName() As String
    ' returns the NT Domain User Name
    Dim rString As String * 255, sLen As Long, tString As String
        tString = ""
        On Error Resume Next
        sLen = GetUserName(rString, 255)
        sLen = InStr(1, rString, Chr(0))
        If sLen > 0 Then
            tString = Left(rString, sLen - 1)
        Else
            tString = rString
        End If
        On Error GoTo 0
        ReturnUserName = UCase(Trim(tString))
    End Function
    
    'If you don't want to return the network user name, but want to return the 
    'user name that the user has registered with the application you can do this:
    
    ActiveUserName = Application.UserName
    ******************
    Yours
    h

    Your Help Is Highly Appreciated

  • #2
    Re: returning the computer name and user name

    A) This will disable a CommandBar called "ply"

    B) See code:


    Sub doit()

    MsgBox ReturnComputerName()

    End Sub


    Not really sure what your questions are!

    TJ
    Oh dear I need a beer
    Online Motorsport Game

    Comment


    • #3


      Re: returning the computer name and user name

      Hi h,

      The Ply commandbar is one of the right-click menubars (the sheet tab one). That line is disabling it - give it a try!

      The functions just return string values for your use:
      Private Declare Function GetComputerName Lib "kernel32" _
      Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

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

      Function ReturnComputerName() As String
      Dim rString As String * 255, sLen As Long, tString As String
      tString = ""
      On Error Resume Next
      sLen = GetComputerName(rString, 255)
      sLen = InStr(1, rString, Chr(0))
      If sLen > 0 Then
      tString = Left(rString, sLen - 1)
      Else
      tString = rString
      End If
      On Error GoTo 0
      ReturnComputerName = UCase(Trim(tString))
      End Function

      Function ReturnUserName() As String
      ' returns the NT Domain User Name
      Dim rString As String * 255, sLen As Long, tString As String
      tString = ""
      On Error Resume Next
      sLen = GetUserName(rString, 255)
      sLen = InStr(1, rString, Chr(0))
      If sLen > 0 Then
      tString = Left(rString, sLen - 1)
      Else
      tString = rString
      End If
      On Error GoTo 0
      ReturnUserName = UCase(Trim(tString))
      End Function

      Sub Testem()
      MsgBox "Computername : " & ReturnComputerName & vbNewLine & _
      "Username : " & ReturnUserName
      End Sub


      HTH
      Cross-poster? Read this: Cross-posters
      Struggling to use tags (including Code tags)? : Forum tags

      Comment

      Working...
      X