Advertisement

07.07.2008 at 07:07AM PDT, ID: 23543388
[x]
Attachment Details

VB.Net Telnet timing out.

Asked by sgaggerj in Microsoft Visual Basic.Net, SSH / Telnet Software

Tags:

Hi all,

I have written a program that reboots a game server ever X hours.
It broadcasts a message to the sever (via shell telnet and sendkeys.sendwait) 30 min before reboot, 15 min before, 5 min before and 1 min before, so that players have time to logout.

It uses a System.Timers.Timer to do this.

It runs perfectly when the computer is not locked, but it timesout on the 1st broadcast when the computer is locked and the telnet window does not close. This breaks all further broadcasts as the BroadcstTimer is stopped and never restarted.

The only thing I can think of as to why this is happening is that when the computer is locked, the shelled telnet is not getting activated by AppActivate.

Any thoughts on how to fix this so that it does run properly when the computer is locked? (other than disabling the server's locking timeout?)

Below is the timer elapsed code and the broadcast code.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
Private Sub BroadcastTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles BroadcastTimer.Elapsed
        BroadcastTimer.Stop()
 
        Dim ts As TimeSpan = EndTime - Now
        If ts.TotalMinutes > 29 And ts.TotalMinutes < 31 Then
            If Not Broadcast30 Then
                Log.WriteLine("Broadcasting 30 minute warning: ") ' & My.Settings.Message & " 30 minutes.")
                BroadcastNow(My.Settings.Message & " 30 minutes.")
                Broadcast30 = True
            End If
        ElseIf ts.TotalMinutes > 14 And ts.TotalMinutes < 16 Then
            If Not Broadcast15 Then
                Log.WriteLine("Broadcasting 15 minute warning: ") ' & My.Settings.Message & " 15 minutes.")
                BroadcastNow(My.Settings.Message & " 15 minutes.")
                Broadcast15 = True
            End If
        ElseIf ts.TotalMinutes > 4 And ts.TotalMinutes < 6 Then
            If Not Broadcast5 Then
                Log.WriteLine("Broadcasting 5 minute warning: ") ' & My.Settings.Message & " 5 minutes.")
                BroadcastNow(My.Settings.Message & " 5 minutes.")
                Broadcast5 = True
            End If
        ElseIf ts.TotalMinutes > 0 And ts.TotalMinutes < 2 Then
            If Not Broadcast1 Then
                Log.WriteLine("Broadcasting 1 minute warning: ") ' & My.Settings.Message & " 1 minutes.")
                BroadcastNow(My.Settings.Message & " 1 minutes.")
                Broadcast1 = True
            End If
        End If
        BroadcastTimer.Start()
    End Sub
Private Sub CloseTelnet()
        Dim p() As Process = Process.GetProcessesByName("telnet")
        For Each pr As Process In p
            pr.Kill()
            pr.WaitForExit()
        Next
    End Sub
Private Sub BroadcastNow(ByVal msg As String)
        CloseTelnet()
        BroadcastButton.Enabled = False
        BroadcastMsg.Enabled = False
        Dim line As String = ""
        Try
            Log.WriteLine("Broadcasting: " & msg)
            Dim lReturn As Object
            line = "TELNET"
            lReturn = IIf(My.Settings.ShowTelnet, Shell("Telnet " & My.Settings.BroadcastServerIP & " " & My.Settings.BroadcastServerPort, AppWinStyle.NormalFocus, False), Shell("Telnet " & My.Settings.BroadcastServerIP & " " & My.Settings.BroadcastServerPort, AppWinStyle.Hide, False))
            Sleep(5)
            AppActivate(lReturn)
            Sleep(2)
            'login
            line = "LOGIN"
            System.Windows.Forms.SendKeys.SendWait(My.Settings.BroadcastUsername & "{ENTER}")
            Sleep(2)
            ' pass
            line = "PASS"
            System.Windows.Forms.SendKeys.SendWait(My.Settings.BroadcastPassword & "{ENTER}")
            Sleep(2)
            ' broadcast message
            line = "BROADCAST"
            System.Windows.Forms.SendKeys.SendWait("broadcast " & msg & "{ENTER}")
            Sleep(1)
            'LOGOFF
            line = "LOGOFF"
            System.Windows.Forms.SendKeys.SendWait("exit{ENTER}")
            Sleep(2)
            'CLOSE TELNET
            line = "CLOSING 1"
            System.Windows.Forms.SendKeys.SendWait("{ENTER}")
            line = "CLOSING 2"
            System.Windows.Forms.SendKeys.SendWait("%{F4}")
            BroadcastButton.Enabled = True
            BroadcastMsg.Enabled = True
        Catch ex As Exception
            'MsgBox("Error broadcasting: " & line & vbLf & ex.ToString)
            Log.WriteLine("Error broadcasting:" & vbLf & ex.ToString)
            BroadcastButton.Enabled = True
            BroadcastMsg.Enabled = True
        End Try
    End Sub
 
 
[+][-]07.07.2008 at 02:08PM PDT, ID: 21948692

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, SSH / Telnet Software
Tags: VB.Net 2005
Sign Up Now!
Solution Provided By: tasky
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.07.2008 at 02:10PM PDT, ID: 21948702

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.08.2008 at 05:35AM PDT, ID: 21953116

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 05:58AM PDT, ID: 21953291

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 10:31AM PDT, ID: 21956058

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 10:44AM PDT, ID: 21956180

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 12:20PM PDT, ID: 21957141

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.09.2008 at 05:32AM PDT, ID: 21962796

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 06:51AM PDT, ID: 21963528

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 08:42AM PDT, ID: 21964941

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 11:43AM PDT, ID: 21976276

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.17.2008 at 05:10AM PDT, ID: 22024510

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.17.2008 at 07:01AM PDT, ID: 22025531

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.18.2008 at 06:05AM PDT, ID: 22035315

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.01.2008 at 11:07AM PDT, ID: 22140588

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.14.2008 at 06:27AM PDT, ID: 22230006

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.14.2008 at 07:54AM PDT, ID: 22230855

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.06.2008 at 06:56PM PDT, ID: 22409747

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 07:05AM PDT, ID: 22417411

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 07:59AM PDT, ID: 22418022

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.10.2008 at 08:58PM PDT, ID: 22446212

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]10.01.2008 at 07:39PM PDT, ID: 22620933

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]10.02.2008 at 11:18AM PDT, ID: 22626954

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.02.2008 at 11:39AM PDT, ID: 22627141

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.06.2008 at 05:21AM PDT, ID: 22649201

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628