Toon posts:

VB6 process control over net

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hallo daar,

ik zit met het volgende probleem: ik heb een printje gebouwd waarmee ik kan schakelen en kan
inlezen via de parallelle poort, heel beperkt echter.
Het printje werkt perfect op m'n pc en onder verschillende progtalen kan ik via een waarde naar de poort te schrijven, de uitgangen schakelen.
Ik wil dit nu echter via m'n netwerk op meerdere pc's gebruiken, ttz via iedere pc de mogelijkheid
hebben om de uitgangen van de print te schakelen.
Wat is nu het idee: ik wil via m'n Internet Explorer inloggen op de pc met het printje, zodaning dat ik via een willekeurige pc met internet verbinding uitgangen kan schakelen op de pc met het printje.
Ik heb nu al hetvolgende: op de pc met het printje draait er nu een apache server, ik kan inloggen op deze pc met al m'n andere pc's en kan de gewenste webpagina zien, wat ik ook wil.
Ik heb nu met VB6 dhtml een webpagina gemaakt met een aantal knoppen op waarmee ik de uitgangen kan schakelen. Het probleem is nu echter dat dit enkel werkt op de pc waarop de server draait en de schakeling is aangesloten. De webpagina wordt wel gedownload naar de ingelogde pc's, maar dan wordt de printerpoort van deze pc's aangestuurd en niet van de server pc, wat ik wel kan begrijpen en wat eigenlijk normaal is ook. Ik weet echter niet hoe ik dit moet oplossen zodat ik kan sturen en controleren over m'n netwerk, kan iemand me op weg helpen?
Thanx

  • Gerco
  • Registratie: Mei 2000
  • Laatst online: 08-05 18:46

Gerco

Professional Newbie

Je zal met een serverside proces moeten schakelen itt wat je nu doet (clientside).

Je kunt in VB6 een applicatie maken die het kan, maar het is volgens mij niet de handigste taal daarvoor. Je moet namelijk vanwege de CGI interface met de webserver de stdin en stdout streams gaan gebruiken en VB6 heeft daar geen ondersteuning voor.

Wat voor jou waarschijnlijk het handigste is, is een klein php script schrijven wat de VB6 app met bepaalde commandline parameters aanroept en dan kan de vb6 app het schakelen doen.

- "Als ik zou willen dat je het begreep, legde ik het wel beter uit!" | All number systems are base 10!


  • ZaZ
  • Registratie: Oktober 2002
  • Laatst online: 19-03 00:48

ZaZ

Tweakers abonnee

misschien dat het bruikbaar is:
een Class dat je makkelijk de stdout kan lezen
hij schopt alle output naar een event

Visual Basic:
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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 GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub ZeroMemory Lib "kernel32" Alias "RtlZeroMemory" (dest As Any, ByVal numBytes As Long)
Private Declare Function PeekNamedPipe Lib "kernel32" (ByVal hNamedPipe As Long, lpBuffer As Any, ByVal nBufferSize As Long, ByVal lpBytesRead As Long, lpTotalBytesAvail As Long, ByVal lpBytesLeftThisMessage As Long) As Long
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long


Public Event ReadProcess(sOutput As String)

Private Type SECURITY_ATTRIBUTES
  nLength As Long
  lpSecurityDescriptor As Long
  bInheritHandle As Long
End Type

Private Type PROCESS_INFORMATION
  hProcess As Long
  hThread As Long
  dwProcessId As Long
  dwThreadId As Long
End Type

Private Type STARTUPINFO
  cb As Long
  lpReserved As String
  lpDesktop As String
  lpTitle As String
  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 Const STARTF_USESTDHANDLES = &H100
Private Const STARTF_USESHOWWINDOW = &H1
Private Const SW_HIDE = 0

Private Const BUFFER_SIZE = 1024

Dim hOutWrite As Long
Dim hOutRead As Long
Dim bCancel As Boolean
Dim hProc As Long

Dim m_cmdLine As String
Dim m_procID As Long

Public Property Get CommandLine() As String
    CommandLine = m_cmdLine
End Property

Public Property Get ProcessID() As Long
    ProcessID = m_procID
End Property

Public Function RunProcess(cmdLine As String, Optional startDir As String = vbNullString) As Long
  Dim saPipe As SECURITY_ATTRIBUTES
  Dim siStart As STARTUPINFO
  Dim piNewProc As PROCESS_INFORMATION
  Dim inBuff As String
  Dim bytesRead As Long
  Dim bytesLeft As Long
  Dim junk As Long
    
  On Local Error GoTo Cleanup
  
  If (hProc) Then Exit Function
   
  m_cmdLine = cmdLine
  
  saPipe.nLength = Len(saPipe)
  saPipe.bInheritHandle = -1
  saPipe.lpSecurityDescriptor = 0
  
  If CreatePipe(hOutRead, hOutWrite, saPipe, 0) Then
        
    siStart.cb = Len(siStart)
    siStart.hStdOutput = hOutWrite
    siStart.hStdError = hOutWrite
    siStart.dwFlags = STARTF_USESTDHANDLES Or STARTF_USESHOWWINDOW
    siStart.wShowWindow = SW_HIDE
    
    If CreateProcess(vbNullString, m_cmdLine, ByVal 0, ByVal 0, -1, 0, ByVal 0, startDir, siStart, piNewProc) Then

      m_procID = piNewProc.dwProcessId
      inBuff = String$(BUFFER_SIZE, Chr$(0))
            
      bCancel = False
      Do Until bCancel
        If PeekNamedPipe(hOutRead, ByVal 0, 0, 0, bytesLeft, 0) Then
        
          If (bytesLeft) Then
            If bytesLeft > BUFFER_SIZE Then bytesLeft = BUFFER_SIZE
            If ReadFile(hOutRead, ByVal inBuff, bytesLeft, bytesRead, ByVal 0) Then
              CloseHandle hOutWrite
              RaiseEvent ReadProcess(Left$(inBuff, bytesRead))
              ZeroMemory ByVal inBuff, BUFFER_SIZE
            Else
              bCancel = True
            End If
          Else
            DoEvents
          End If
        Else
          bCancel = True
        End If
      Loop
    Else
      Err.Raise vbObjectError + 402, "StdOut", "Failed to create process"
    End If
  Else
    Err.Raise vbObjectError + 401, "StdOut", "Failed to create pipe"
  End If
  GetExitCodeProcess piNewProc.hProcess, RunProcess

Cleanup:
  CloseHandle hOutWrite
  CloseHandle hOutRead
  CloseHandle piNewProc.hThread
  CloseHandle piNewProc.hProcess
  m_procID = 0
  m_cmdLine = ""
  If Err.Number <> 0 Then MsgBox "Error: " & CStr(Err.Number) & vbCrLf & "Description: " & Err.Description, vbCritical
End Function

Public Sub Cancel()
    bCancel = True
End Sub

Lekker op de bank


  • sopsop
  • Registratie: Januari 2002
  • Laatst online: 11-05 08:55

sopsop

[v] [;,,;] [v]

neem wat je nu hebt gemaakt, maak er een dll van. Geen idee hoe dit in php werkt, maar in ASP kun je het volgende doen.

Maak een asp pagina die buttonclicks verwerkt.
create een object met daarin de classe uit je dll, roep de functie die bij de geklikte button hoort aan.

Wat je nu (waarschijnlijk) hebt gedaan is een activex object gemaakt die zodra je die aanroept wordt gedownload en uitgevoerd. Alleen dat uitvoeren doet hij ook lokaal.