vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Erstellen von dynamischen Kontextmen?s - wann immer Sie sie brauchen!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Fortgeschrittene Programmierung
Re: dos Fenster starten 
Autor: marcoköln
Datum: 04.07.06 15:18

ich habe vollgenden Code gefunden. Habe Ihn auch umgeändert. Indem ich mit plink.exe eine Verbindung aufbaue.
Dies funktioniert auch wunderbar.Jetzt möchte ich aber dem gleichen processe einen Buchstaben z.b " L " mit einem Enter dahinter schicken.Und dann die Ausgabe vom Process wieder auslesen.
Option Explicit
 
Private Declare Function CreatePipe Lib "kernel32" (phReadPipe _
        As Long, phWritePipe As Long, lpPipeAttributes As Any, _
        ByVal nSize As Long) As Long
 
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile _
        As Long, ByVal lpBuffer As String, ByVal _
        nNumberOfBytesToRead As Long, lpNumberOfBytesRead As _
        Long, ByVal lpOverlapped As Any) As Long
 
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
        lpApplicationName As Long, ByVal lpCommandLine As _
        String, lpProcessAttributes As Any, lpThreadAttributes _
        As Any, ByVal bInheritHandles As Long, ByVal _
        dwCreationFlags As Long, ByVal lpEnvironment As Long, _
        ByVal lpCurrentDirectory As Long, lpStartupInfo As Any, _
        lpProcessInformation As Any) As Long
 
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
        hObject As Long) As Long
 
Private Declare Function PeekNamedPipe Lib "kernel32" (ByVal _
        hNamedPipe As Long, lpBuffer As Any, ByVal nBufferSize _
        As Long, lpBytesRead As Long, lpTotalBytesAvail As Long, _
        lpBytesLeftThisMessage As Long) As Long
 
Private Declare Function WaitForSingleObject Lib "kernel32" ( _
        ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
 
Private Type SECURITY_ATTRIBUTES
  nLength As Long
  lpSecurityDescriptor As Long
  bInheritHandle As Long
End Type
 
Private Type STARTUPINFO
  cb As Long
  lpReserved As Long
  lpDesktop As Long
  lpTitle As Long
  dwX As Long
  dwY As Long
  dwXSize As Long
  dwYSize As Long
  dwXCountChars As Long
  dwYCountChars As Long
  dwFillAttribute As Long
  dwFlags As Long
  wShowWindow As Integer
  cbReserved2 As Integer
  lpReserved2 As Long
  hStdInput As Long
  hStdOutput As Long
  hStdError As Long
End Type
 
Private Type PROCESS_INFORMATION
  hProcess As Long
  hThread As Long
  dwProcessID As Long
  dwThreadID As Long
End Type
 
Const NORMAL_PRIORITY_CLASS = &H20&
Const STARTF_USESTDHANDLES = &H100&
 
Private Sub Command1_Click()
    Dim OutText As String
    Dim WithUml As String
 
    'Hier den Pfad einer Batchdatei oder einer Konsolenanwendung
    'die eine Ausgabe hat eintragen
Text1.Text = ExecCmd("F:\Marco\ratiodata\Putty Fernwartung\plink.exe -ssh" & _
  "10.20.100.80 -P 22 -l test -pw test")
 
End Sub
 
Private Function ExecCmd(cmdline$) As String
    Dim proc As PROCESS_INFORMATION
    Dim start As STARTUPINFO
    Dim sa As SECURITY_ATTRIBUTES
    Dim hReadPipe As Long, hWritePipe As Long
    Dim L As Long, Result As Long, bSuccess As Long
    Dim Buffer As String
 
    Dim retText As String
 
    sa.nLength = Len(sa)
    sa.bInheritHandle = 1&
    sa.lpSecurityDescriptor = 0&
    Result = CreatePipe(hReadPipe, hWritePipe, sa, 0)
 
    If Result = 0 Then
        MsgBox "CreatePipe failed Error!"
        Exit Function
    End If
 
    start.cb = Len(start)
    start.dwFlags = STARTF_USESTDHANDLES
    start.hStdOutput = hWritePipe
 
oben:
 
    Result = CreateProcessA(0&, cmdline$, sa, sa, 1&, _
        NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
 
    If Result <> 0 Then
        '*** Anfang der Verbesserung Achim Neubauer***
 
        Dim lPeekData As Long
 
        Do
            Call PeekNamedPipe(hReadPipe, ByVal 0&, 0&, ByVal 0&, _
                lPeekData, ByVal 0&)
 
            If lPeekData > 0 Then
                Buffer = Space$(lPeekData)
                bSuccess = ReadFile(hReadPipe, Buffer, Len(Buffer), L, 0&)
 
                If bSuccess = 1 Then
                    retText = retText & Left(Buffer, L)
                    MsgBox retText
                    GoTo oben
                Else
                    MsgBox "ReadFile failed!"
                End If
            Else
                bSuccess = WaitForSingleObject(proc.hProcess, 0&)
 
                If bSuccess = 0 Then
                    Exit Do
                End If
            End If
 
            DoEvents
        Loop
 
        '*** Ende der Verbesserung Achim Neubauer ***
    Else
        MsgBox "Error while starting process!"
    End If
 
    Call CloseHandle(proc.hProcess)
    Call CloseHandle(proc.hThread)
    Call CloseHandle(hReadPipe)
    Call CloseHandle(hWritePipe)
 
    ExecCmd = retText
End Function
 
Private Sub Form_Load()
    Command1.Caption = "Start"
End Sub
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
dos Fenster starten835marcoköln03.07.06 14:01
Re: dos Fenster starten542BAStler03.07.06 14:34
Re: dos Fenster starten830marcoköln04.07.06 15:18
Re: dos Fenster starten567wb-soft04.07.06 15:39
Re: dos Fenster starten590wb-soft04.07.06 15:49

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel