Results 1 to 10 of 10

Thread: Need Some Sugestions - Very Easy

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    149

    Question

    Hi,

    I am wanting to know how to get some information from a computer and save it to a text file. I know how to save it to a text file, but I am not sure how to get the information I am after.

    Some of the things that I want to know about the computer is

    1) User Logged in
    2) IP Address
    3) Host Name
    4) How Long they have been logged in
    5) How long windows has been running

    and anything else that people can think of.
    I want to include as much information as possible in the text file.

    Just so that you know what it is for, I am a network admin for a school and would like to be able to find out who logged in when and how long for and any other relevant information that you can think of.

    Also if you are going to post a sugestion please include some source code if possible, If you do not know the source please post tue sugestion anyway cause someone else (or maybe even me) might know how to.



    Thanks

    Hurgh

  2. #2
    Guest
    1:

    Code:
    Private Declare Function GetUserName Lib "advapi32.dll" _
                Alias "GetUserNameA" (ByVal lpBuffer As String, _
                nSize As Long) As Long
    
    Public Function UserName() As String
        Dim llReturn As Long
        Dim lsUserName As String
        Dim lsBuffer As String
        
        lsUserName = ""
        lsBuffer = Space$(255)
        llReturn = GetUserName(lsBuffer, 255)
       
        If llReturn Then
           lsUserName = Left$(lsBuffer, InStr(lsBuffer, Chr(0)) - 1)
        End If
        
        UserName = lsUserName
    End Function
    
    Usage:
    
    Msgbox UserName

    2/3:

    Code:
    Option Explicit
    
    Public Const MAX_WSADescription = 256
    Public Const MAX_WSASYSStatus = 128
    Public Const ERROR_SUCCESS       As Long = 0
    Public Const WS_VERSION_REQD     As Long = &H101
    Public Const WS_VERSION_MAJOR    As Long = WS_VERSION_REQD \ & H100  And &HFF&
    Public Const WS_VERSION_MINOR    As Long = WS_VERSION_REQD And &HFF&
    Public Const MIN_SOCKETS_REQD    As Long = 1
    Public Const SOCKET_ERROR        As Long = -1
    
    Public Type HOSTENT
       hName      As Long
       hAliases   As Long
       hAddrType  As Integer
       hLen       As Integer
       hAddrList  As Long
    End Type
    
    Public Type WSADATA
       wVersion      As Integer
       wHighVersion  As Integer
       szDescription(0 To MAX_WSADescription)   As Byte
       szSystemStatus(0 To MAX_WSASYSStatus)    As Byte
       wMaxSockets   As Integer
       wMaxUDPDG     As Integer
       dwVendorInfo  As Long
    End Type
    
    Public Declare Function WSAGetLastError _
    Lib "WSOCK32.DLL" () As Long
    
    Public Declare Function WSAStartup Lib _
    "WSOCK32.DLL" (ByVal wVersionRequired As Long, _
    lpWSADATA As WSADATA) As Long
       
    Public Declare Function WSACleanup Lib _
    "WSOCK32.DLL" () As Long
    
    Public Declare Function gethostname Lib _
    "WSOCK32.DLL" (ByVal szHost As String, _
    ByVal dwHostLen As Long) As Long
       
    Public Declare Function gethostbyname Lib "WSOCK32.DLL" _
       (ByVal szHost As String) As Long
       
    Public Declare Sub CopyMemory Lib "kernel32" _
    Alias "RtlMoveMemory" (hpvDest As Any, ByVal _
    hpvSource As Long, ByVal cbCopy As Long)
    
    Public Function GetIPAddress() As String
    
       Dim sHostName    As String * 256
       Dim lpHost    As Long
       Dim HOST      As HOSTENT
       Dim dwIPAddr  As Long
       Dim tmpIPAddr() As Byte
       Dim i         As Integer
       Dim sIPAddr  As String
       
       If Not SocketsInitialize() Then
          GetIPAddress = ""
          Exit Function
       End If
        
       If gethostname(sHostName, 256) = SOCKET_ERROR Then
          GetIPAddress = ""
          MsgBox "Windows Sockets error " & Str$(WSAGetLastError()) & _
                  " has occurred. Unable to successfully get Host Name."
          SocketsCleanup
          Exit Function
       End If
        
       sHostName = Trim$(sHostName)
       lpHost = gethostbyname(sHostName)
        
       If lpHost = 0 Then
          GetIPAddress = ""
          MsgBox "Windows Sockets are not responding. " & _
                  "Unable to successfully get Host Name."
          SocketsCleanup
          Exit Function
       End If
        
       CopyMemory HOST, lpHost, Len(HOST)
       CopyMemory dwIPAddr, HOST.hAddrList, 4
       
       ReDim tmpIPAddr(1 To HOST.hLen)
       CopyMemory tmpIPAddr(1), dwIPAddr, HOST.hLen
       
         For i = 1 To HOST.hLen
          sIPAddr = sIPAddr & tmpIPAddr(i) & "."
       Next
      
         GetIPAddress = Mid$(sIPAddr, 1, Len(sIPAddr) - 1)
       
       SocketsCleanup
        
    End Function
    
    Public Function GetIPHostName() As String
    
        Dim sHostName As String * 256
        
        If Not SocketsInitialize() Then
            GetIPHostName = ""
            Exit Function
        End If
        
        If gethostname(sHostName, 256) = SOCKET_ERROR Then
            GetIPHostName = ""
            MsgBox "Windows Sockets error " & Str$(WSAGetLastError()) & _
                    " has occurred.  Unable to successfully get Host Name."
            SocketsCleanup
            Exit Function
        End If
        
        GetIPHostName = Left$(sHostName, InStr(sHostName, Chr(0)) - 1)
        SocketsCleanup
    
    End Function
    
    
    Public Function HiByte(ByVal wParam As Integer)
    
        HiByte = wParam \ & H100  And &HFF&   
    
    End Function
    
    Public Function LoByte(ByVal wParam As Integer)
    
        LoByte = wParam And &HFF&    
    
    End Function
    
    Public Sub SocketsCleanup()
    
        If WSACleanup()<> ERROR_SUCCESS Then
            MsgBox "Socket error occurred in Cleanup."
        End If
        
    End Sub
    
    Public Function SocketsInitialize() As Boolean
    
       Dim WSAD As WSADATA
       Dim sLoByte As String
       Dim sHiByte As String
       
       If WSAStartup(WS_VERSION_REQD, WSAD)<> ERROR_SUCCESS Then
          MsgBox "The 32-bit Windows Socket is not responding."
          SocketsInitialize = False
          Exit Function
       End If
       
       
       If WSAD.wMaxSockets < MIN_SOCKETS_REQD Then
            MsgBox "This application requires a minimum of " & _
                    CStr(MIN_SOCKETS_REQD) & " supported sockets."
            
            SocketsInitialize = False
            Exit Function
        End If
       
       
       If LoByte(WSAD.wVersion) < WS_VERSION_MAJOR Or _
         (LoByte(WSAD.wVersion) = WS_VERSION_MAJOR And _
          HiByte(WSAD.wVersion) < WS_VERSION_MINOR) Then
          
          sHiByte = CStr(HiByte(WSAD.wVersion))
          sLoByte = CStr(LoByte(WSAD.wVersion))
          
          MsgBox "Sockets version " & sLoByte & "." & sHiByte & _
                 " is not supported by 32-bit Windows Sockets."
          
          SocketsInitialize = False
          Exit Function
          
       End If
    
      'must be OK, so lets do it
       SocketsInitialize = True
            
    End Function
    
    Usage:
    
    Text1 = GetIPHostName() 
    Text2 = GetIPAddress()

    4/5:

    Code:
    Declare Function GetTickCount Lib "kernel32" () As Long
    
    Private Sub Command1_Click()
    Dim lngCount As Long
    Dim lngHours As Long
    Dim lngMinutes As Long
    lngCount = GetTickCount
    lngHours = ((lngCount / 1000) / 60) / 60
    lngMinutes = ((lngCount / 1000) / 60) Mod 60
    MsgBox "System has been running for - " & lngHours & " hour(s) and " & lngMinutes & " minute(s).", vbInformation
    End Sub

  3. #3
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    I have developed a similar application.

    To get the user name, look at the GetUserName Function, see code at http://www.vbapi.com

    to get the time user has been logged in, put you function in either the registry, or the startup menu so that it gets started every time a login occurs, then just mark the time, at count it up. For the time windows has been running, use GetTickCount again, see http://www.vbapi.com

    For the ip, i don't know.

    for the host name, if you mean machine name, use the
    GetComputerName, again, see http://www.vbapi.com. You can monitor almost anything, including printer ussuage, programs run, and web url's visited. Even use
    Code:
    Shell "netstat > myfile.txt" for tcp/ip stats.
    You then parse the textfile into your file. Hope this works for you!!
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  4. #4
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    sorry mathew, posted at same time!!
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  5. #5
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    same time? his says 10:06 yours says 10:13
    NXSupport - Your one-stop source for computer help

  6. #6
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    did you have the reply window open for 12 minutes gw-?

  7. #7
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    take a look at this post
    http://209.207.250.147/showthread.php?threadid=30290

    covers ip stuff which i wrote

  8. #8
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    yea, i was decifering the info he gave and answering for 12 min.
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  9. #9
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    oh, ok

  10. #10
    Guest
    Don't worry about it gwdash. ALL Answers are better than NONE. I've done that before, hit Post Reply and 15 minutes has gone by and someone has answered with the same thing. But the good thing is, sometimes you don't know the answer and if you look for it and find it, you learn something new too .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width