home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / ProjectX1_562922192002.psc / ModulesCode / modCodeX2.bas < prev    next >
Encoding:
BASIC Source File  |  1997-02-19  |  1.6 KB  |  52 lines

  1. Attribute VB_Name = "modCodeX2"
  2. '-----------------------------------
  3. '-
  4. '- Get/Set computer name and get Username
  5. '-
  6. '-     By T-Virus Creations
  7. '- http://www.tvirusonline.be
  8. '- email: tvirus4ever@yahoo.co.uk
  9. '-
  10. '-----------------------------------
  11. Const MAX_COMPUTERNAME_LENGTH As Long = 31
  12. Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  13. Declare Function SetComputerName Lib "kernel32" Alias "SetComputerNameA" (ByVal lpComputerName As String) As Long
  14. Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  15.  
  16.  
  17. Public Function TvGetUserName() As String
  18. Dim X As String
  19. X = String(100, Chr$(0)) ' Create Buffer
  20. GetUserName X, 100
  21. TvGetUserName = X
  22. End Function
  23. Public Sub TvSetComputerName(Name As String)
  24.     Dim sNewName As String
  25.     sNewName = Name
  26.     
  27.     If sNewName = "" Then
  28.     sNewName = InputBox("Please enter a new computer name.", "Please input new computername!", "")
  29.  
  30.     End If
  31.  
  32.     'Ask for a new computer name
  33.     
  34.     If sNewName = "" Then Exit Sub
  35.     'Set the new computer name
  36.     SetComputerName sNewName
  37. End Sub
  38.  
  39.  
  40. Public Function TvGetComputerName() As String
  41.     Dim dwLen As Long
  42.     Dim strString As String
  43.     'Create a buffer
  44.     dwLen = MAX_COMPUTERNAME_LENGTH + 1
  45.     strString = String(dwLen, "X")
  46.     'Get the computer name
  47.     GetComputerName strString, dwLen
  48.     'get only the actual data
  49.     strString = Left(strString, dwLen)
  50.     TvGetComputerName = strString
  51. End Function
  52.