Results 1 to 4 of 4

Thread: Windows Service & Event Logs

  1. #1

    Thread Starter
    Member Canibus's Avatar
    Join Date
    Jun 2003
    Location
    South Africa
    Posts
    61

    Windows Service & Event Logs

    hey!

    I'm trying to capture the user that has logged on my PC by using windows services. The problem is that they dont send the info to me dB. what is wrong with the code below??


    Protected Overrides Sub Onstart
    Dim myNewLog As New EventLog
    myNewLog.Log = "Security"

    username = entry.UserName.ToString.Split("\\")(1).Trim()
    logCode = entry.EventID
    timeLog = entry.TimeWritten.ToShortTimeString().Split(" ")(0).Trim()
    dateLog = entry.TimeWritten.ToShortDateString()
    If (logCode = 528) Then
    strSQL = " INSERT INTO tableName" _
    & " VALUES ('" & username & "','" & timeLog & "','" & dateLog & "')"

    'insert into table
    Call ADDInfo(strSQL.ToString)
    End If
    End Sub


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

    Protected Overrides Sub OnStop
    Dim myNewLog As New EventLog
    myNewLog.Log = "Security"

    Dim cnn As SqlConnection = New SqlConnection(cnnString.ToString)
    Dim cmd As SqlCommand = New SqlCommand

    username = entry.UserName.ToString.Split("\\")(1).Trim()
    logCode = entry.EventID
    timeLog = entry.TimeWritten.ToShortTimeString().Split(" ")(0).Trim()
    dateLog = entry.TimeWritten.ToShortDateString()
    If logCode = 538 Then
    strSQL = " INSERT INTO TableName " _
    & " VALUES ('" & username & "','" & timeLog & "','" & dateLog & "')"
    Call ADDInfo(strSQL.ToString)
    End If
    End Sub


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

    i even have the installers that are fine. but it just doesnt want to store the info.

    Please Help

    Canibus Signs out!!

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036
    Hi

    Well maybe ADDInfo is not doing ExecuteNonQuery?

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    Member Canibus's Avatar
    Join Date
    Jun 2003
    Location
    South Africa
    Posts
    61
    well, my AddInfo looks like this.


    Private Sub ADDInfo(ByVal tmpstrSQL As String)
    Dim cnn As SqlConnection = New SqlConnection(cnnString.ToString)
    Dim cmd As SqlCommand = New SqlCommand

    cmd.Connection = cnn
    cmd.CommandType = CommandType.Text
    cmd.CommandText = tmpstrSQL

    If (cnn.State = ConnectionState.Closed) Then
    cnn.Open()
    Else
    cnn.Close()
    cnn.Open()
    End If
    cmd.ExecuteNonQuery()
    cnn.Close()

    End Sub
    Canibus Signs out!!

  4. #4
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036
    Hi

    Well maybe logcode is never 528 when start your service?

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

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