Jump to content

VB.NET program produces a bluescreen

- - - - -

  • Please log in to reply
4 replies to this topic

#1
J4keVC

J4keVC

    Newbie

  • Members
  • PipPip
  • 10 posts
Hello,

I have written a program in VB.NET, but when I debug it i get a bluescreen. It's a little confusing, because when I run my program on another computer it runs without problems and even better ( some feautures which didn't work on my computer work on other computers ).

I have a laptop with win 7 64-bit i7 2630QM 4Gb RAM nvidea 540m vidcard

My code:


Imports System.Net

Imports System.Net.Sockets


Public Class frmPcToolkit


    Dim host As String

    Public Function scanPorts(ByVal port As Integer, Optional ByVal sleepTime As Integer = 500) As Boolean

        Dim client As New Net.Sockets.TcpClient

        host = txtHost.Text


        If pingToHost(host) = True Then

            Try

                client.BeginConnect(host, port, Nothing, Nothing)

                For i = 0 To sleepTime

                    Threading.Thread.Sleep(1)

                    If client.Connected = True Then

                        Return True

                    End If

                Next

                client.Close()

                Return False

            Catch ex As Exception

                client.Close()

                Return False

            End Try

        Else

            Call errorHandler()

            Exit Function        'Hier moet de code stoppen dus een return is niet nodig!'

        End If

    End Function


    Private Sub btnStartScan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartScan.Click

        Dim toPort As Integer

        Dim fromPort As Integer

        Try

            toPort = CType(txtToPort.Text, Integer)

            fromPort = CType(txtFromPort.Text, Integer)

        Catch

            Call errorHandler()

            Exit Sub

        End Try

        Dim portStatus As Boolean

        Dim aantalPorts As Integer

        Dim aantalOpenPorts As Integer

        aantalPorts = toPort - fromPort


        If fromPort > 65536 Or fromPort < 1 Then

            MsgBox("There is no such port in the system, please enter a valid one")

        ElseIf fromPort = 65535 And toPort = 65535 Then

            aantalPorts = 1

            lstPorts.Items.Add("Port: 65535 " & scanPorts(65535, Nothing))

            portStatus = scanPorts(65535, Nothing)

            If portStatus = True Then

                lstOpenPorts.Items.Add("Port: 65535" & portStatus)

            End If

        Else


            lstPorts.Items.Clear()

            lstOpenPorts.Items.Clear()


            For i = fromPort To toPort

                lstPorts.Items.Add("Port: " & i & " " & scanPorts(i, Nothing))

            Next


            For j = fromPort To toPort

                portStatus = scanPorts(j, Nothing)

                If portStatus = True Then

                    lstOpenPorts.Items.Add("Port: " & j & " " & portStatus)

                End If

            Next


            aantalOpenPorts = lstOpenPorts.Items.Count

            txtOpenPorts.Text = aantalOpenPorts

            txtPortsCount.Text = aantalPorts


        End If

    End Sub


    Private Sub lstPorts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstPorts.SelectedIndexChanged

        Dim lstPort(0 To 1) As String

        Dim selectedPort As String = lstPorts.SelectedItem

        Dim selectedPortStatus As Boolean


        lstPort = Split(selectedPort, " ")

        txtPort.Text = lstPort(1)


        selectedPortStatus = scanPorts(lstPort(1), Nothing)

        If selectedPortStatus = False Then

            txtPortStatus.Text = "Closed"

        Else

            txtPortStatus.Text = "Open"

        End If


    End Sub


    Private Sub lstOpenPorts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstOpenPorts.SelectedIndexChanged

        Dim lstOpenPort(0 To 1) As String

        Dim selectedPort As String = lstOpenPorts.SelectedItem


        lstOpenPort = Split(selectedPort, " ")

        txtPort.Text = lstOpenPort(1)


        txtPortStatus.Text = "Open"


    End Sub


    Private Sub txtFromPort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFromPort.Click

        txtFromPort.Text = ""

    End Sub


    Private Sub txtToPort_TClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtToPort.Click

        txtToPort.Text = ""

    End Sub


    Private Sub frmPcToolkit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim networkConnectionStatus As Boolean


        networkConnectionStatus = My.Computer.Network.IsAvailable

        If networkConnectionStatus = True Then

            txtnetworkConnectionStatus.Text = "Available"

        ElseIf networkConnectionStatus = False Then

            txtnetworkConnectionStatus.Text = "Not available"

        End If


        If pingToHost("www.google.com") = True Then

            txtInternetConnectivity.Text = "Available"

        ElseIf pingToHost("www.google.com") = False Then

            txtInternetConnectivity.Text = "Not available"

            MsgBox(pingToHost("www.google.com"))

        End If


        tslblNow.Text = Now



    End Sub


    Private Sub tmrNow_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrNow.Tick

        Dim networkConnectionStatus As Boolean


        networkConnectionStatus = My.Computer.Network.IsAvailable

        If networkConnectionStatus = True Then

            txtnetworkConnectionStatus.Text = "Available"

        ElseIf networkConnectionStatus = False Then

            txtnetworkConnectionStatus.Text = "Not available"

        End If


        tslblNow.Text = Now

    End Sub


    Private Sub btnPingToHost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPingToHost.Click

        If pingToHost("www.google.com") = True Then

            txtInternetConnectivity.Text = "Available"

        ElseIf pingToHost("www.google.com") = False Then

            txtInternetConnectivity.Text = "Not available"

        End If


    End Sub


    Public Function pingToHost(ByVal ipHost As String) As Boolean

        Try

            My.Computer.Network.Ping(ipHost)

            Return True

        Catch

            Return False

        End Try

        Return False

    End Function


    Public Function convertHostToIp(ByVal hostToConvert As String) As IPHostEntry

        Dim ip As IPHostEntry

        Try

            ip = Dns.Resolve(hostToConvert)

            Return ip

        Catch

            MsgBox("The hosttype was incorrect, please try again")

            Return Nothing

            Exit Function

        End Try

    End Function


    Private Sub btnConvertHostToIp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvertHostToIp.Click

        Dim conversionHost As String = txtHostToConvert.Text

        Dim ip As IPHostEntry

        Try

            ip = convertHostToIp(conversionHost)

            For Each adr As IPAddress In ip.AddressList

                txtIpFromConversion.Text = adr.ToString

            Next

        Catch

            MsgBox("An error has occured, please try again")

        End Try


    End Sub


    Private Sub btnConverteerBinary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConverteerBinary.Click

        Dim binaryInput As String

        Dim hexaInput As String


        binaryInput = txtBinaryInput.Text

        hexaInput = txtConvertToHexaInput.Text

    End Sub


    Public Function errorHandler()

        MsgBox("Er is onverwacht een fout opgetreden, gelieve het nog eens te proberen")

        Return Nothing

    End Function

End Class


I don't know where to look for the problem

corrections are welcome ( as well for my English :) )

Thx a lot!

#2
cppnewbie

cppnewbie

    Newbie

  • Members
  • Pip
  • 6 posts
A program (at least one that isn't very low level) should not be able to cause a blue screen. What is the bluescreen error message?

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
If you've a faulty network card or driver, it could certainly break when performing certain functionalities. From a brief look it does not appear that you are doing anything special other than invoking networking drivers.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
J4keVC

J4keVC

    Newbie

  • Members
  • PipPip
  • 10 posts
Is it possible that my antivirus program blocks it and shutdown my computer? :confused:

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
It could be entirely possible, heuristics of an antivirus may allow for blocking port scans (=attempt to spread). This blocking may not be properly implemented or well tested shutting down your computer due to a network driver issue.

A lot of programs try to "assert" their control by controlling the network as a service, and end up rendering the computer not bootable except for safe mode.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users