[vb] Hoe zat het ook al weer met die commando's?

Pagina: 1
Acties:

  • sebastius
  • Registratie: September 2000
  • Laatst online: 09-09 19:18

sebastius

Laten we lekker link gaan doen

Topicstarter
Wat ik wil is een commando uitvoeren:

NET SEND user "bericht"

Ik heb de user als textstring en bericht als textstring.

Maar hoe laat ik hem dat ook al weer versturen?

Hier op de TU hebben we wel VB, maar de MSDN cd's zijn niet ge-installeerd...

  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 12-09 21:31

Janoz

Moderator Devschuur®

!litemod

msdn is ook online hoor, en ik neem aan dat er op de TU wel internet is...

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


  • sebastius
  • Registratie: September 2000
  • Laatst online: 09-09 19:18

sebastius

Laten we lekker link gaan doen

Topicstarter
Ga ik ook daar effe zoeken. Dankjewel.

  • sebastius
  • Registratie: September 2000
  • Laatst online: 09-09 19:18

sebastius

Laten we lekker link gaan doen

Topicstarter
Ik voel me zooo dom, ik kan het echt niet vinden... En ik wist dus hoe het zat, maar ben het straal vergeten... Het was iets met CMD geloof ik, maar ben er niet zeker van.

Verwijderd

code:
1
2
3
4
5
6
7
8
9
10
11
Private Sub Command1_Click()

    Dim strText As String
    Dim strUser As String
    
    strText = "Hello world"
    strUser = "name goes here"
    
    Shell ("NET SEND " & strUser & " " & strText)
    
End Sub

Maak voor de test een formpje, mieter daar een button op, en zet deze code in de button.

Verwijderd

Op dinsdag 19 februari 2002 10:32 schreef Sepans het volgende:
code:
1
2
3
4
5
6
7
8
9
10
11
Private Sub Command1_Click()

    Dim strText As String
    Dim strUser As String
    
    strText = "Hello world"
    strUser = "name goes here"
    
    Shell ("NET SEND " & strUser & " " & strText)
    
End Sub

Maak voor de test een formpje, mieter daar een button op, en zet deze code in de button.
sjit weer te laat moet toch ff sneller leren typen B-)

  • sebastius
  • Registratie: September 2000
  • Laatst online: 09-09 19:18

sebastius

Laten we lekker link gaan doen

Topicstarter
SHELL!!! Dat was het!!! Dank je wel!

  • thomasdebans
  • Registratie: November 2001
  • Laatst online: 11-09 13:08
Using the Winsock Control


A WinSock control allows you to connect to a remote machine and exchange data using either the User Datagram Protocol (UDP) or the Transmission Control Protocol (TCP). Both protocols can be used to create client and server applications. Like the Timer control, the WinSock control doesn't have a visible interface at run time.

Possible Uses
Create a client application that collects user information before sending it to a central server.


Create a server application that functions as a central collection point for data from several users.


Create a "chat" application.
Selecting a Protocol
When using the WinSock control, the first consideration is whether to use the TCP or the UDP protocol. The major difference between the two lies in their connection state:

The TCP protocol control is a connection-based protocol, and is analogous to a telephone the user must establish a connection before proceeding.


The UDP protocol is a connectionless protocol, and the transaction between two computers is like passing a note: a message is sent from one computer to another, but there is no explicit connection between the two. Additionally, the maximum data size of individual sends is determined by the network.
The nature of the application you are creating will generally determine which protocol you select. Here are a few questions that may help you select the appropriate protocol:

Will the application require acknowledgment from the server or client when data is sent or received? If so, the TCP protocol requires an explicit connection before sending or receiving data.


Will the data be extremely large (such as image or sound files)? Once a connection has been made, the TCP protocol maintains the connection and ensures the integrity of the data. This connection, however, uses more computing resources, making it more "expensive."


Will the data be sent intermittently, or in one session? For example, if you are creating an application that notifies specific computers when certain tasks have completed, the UDP protocol may be more appropriate. The UDP protocol is also more suited for sending small amounts of data.
Setting the Protocol
To set the protocol that your application will use: at design-time, on the Properties window, click Protocol and select either sckTCPProtocol, or sckUDPProtocol. You can also set the Protocol property in code, as shown below:

Winsock1.Protocol = sckTCPProtocol

Determining the Name of Your Computer
To connect to a remote computer, you must know either its IP address or its "friendly name." The IP address is a series of three digit numbers separated by periods (xxx.xxx.xxx.xxx). In general, it's much easier to remember the friendly name of a computer.

To find your computer's name

On the Taskbar of your computer, click Start.


On the Settings item, click the Control Panel.


Double-click the Network icon.


Click the Identification tab.


The name of your computer will be found in the Computer name box.
Once you have found your computer's name, it can be used as a value for the RemoteHost property.

TCP Connection Basics
When creating an application that uses the TCP protocol, you must first decide if your application will be a server or a client. Creating a server means that your application will "listen," on a designated port. When the client makes a connection request, the server can then accept the request and thereby complete the connection. Once the connection is complete, the client and server can freely communicate with each other.

The following steps create a rudimentary server:

To create a TCP server

Create a new Standard EXE project.


Change the name of the default form to frmServer.


Change the caption of the form to "TCP Server."


Draw a Winsock control on the form and change its name to tcpServer.


Add two TextBox controls to the form. Name the first txtSendData, and the second txtOutput.


Add the code below to the form.
Private Sub Form_Load()
' Set the LocalPort property to an integer.
' Then invoke the Listen method.
tcpServer.LocalPort = 1001
tcpServer.Listen
frmClient.Show ' Show the client form.
End Sub

Private Sub tcpServer_ConnectionRequest _
(ByVal requestID As Long)
' Check if the control's State is closed. If not,
' close the connection before accepting the new
' connection.
If tcpServer.State <> sckClosed Then _
tcpServer.Close
' Accept the request with the requestID
' parameter.
tcpServer.Accept requestID
End Sub

Private Sub txtSendData_Change()
' The TextBox control named txtSendData
' contains the data to be sent. Whenever the user
' types into the textbox, the string is sent
' using the SendData method.
tcpServer.SendData txtSendData.Text
End Sub

Private Sub tcpServer_DataArrival _
(ByVal bytesTotal As Long)
' Declare a variable for the incoming data.
' Invoke the GetData method and set the Text
' property of a TextBox named txtOutput to
' the data.
Dim strData As String
tcpServer.GetData strData
txtOutput.Text = strData
End Sub

The procedures above create a simple server application. However, to complete the scenario, you must also create a client application.

To create a TCP client

Add a new form to the project, and name it frmClient.


Change the caption of the form to TCP Client.


Add a Winsock control to the form and name it tcpClient.


Add two TextBox controls to frmClient. Name the first txtSend, and the second txtOutput.


Draw a CommandButton control on the form and name it cmdConnect.


Change the caption of the CommandButton control to Connect.


Add the code below to the form.
Important Be sure to change the value of the RemoteHost property to the friendly name of your computer.

Private Sub Form_Load()
' The name of the Winsock control is tcpClient.
' Note: to specify a remote host, you can use
' either the IP address (ex: "121.111.1.1") or
' the computer's "friendly" name, as shown here.
tcpClient.RemoteHost = "RemoteComputerName"
tcpClient.RemotePort = 1001
End Sub

Private Sub cmdConnect_Click()
' Invoke the Connect method to initiate a
' connection.
tcpClient.Connect
End Sub

Private Sub txtSendData_Change()
tcpClient.SendData txtSend.Text
End Sub

Private Sub tcpClient_DataArrival _
(ByVal bytesTotal As Long)
Dim strData As String
tcpClient.GetData strData
txtOutput.Text = strData
End Sub

The code above creates a simple client-server application. To try the two together, run the project, and click Connect. Then type text into the txtSendData TextBox on either form, and the same text will appear in the txtOutput TextBox on the other form.

Accepting More than One Connection Request
The basic server outlined above accepts only one connection request. However, it is possible to accept several connection requests using the same control by creating a control array. In that case, you do not need to close the connection, but simply create a new instance of the control (by setting its Index property), and invoking the Accept method on the new instance.

The code below assumes there is a Winsock control on a form named sckServer, and that its Index property has been set to 0; thus the control is part of a control array. In the Declarations section, a module-level variable intMax is declared. In the form's Load event, intMax is set to 0, and the LocalPort property for the first control in the array is set to 1001. Then the Listen method is invoked on the control, making it the "listening control. As each connection request arrives, the code tests to see if the Index is 0 (the value of the "listening" control). If so, the listening control increments intMax, and uses that number to create a new control instance. The new control instance is then used to accept the connection request.

Private intMax As Long

Private Sub Form_Load()
intMax = 0
sckServer(0).LocalPort = 1001
sckServer(0).Listen
End Sub

Private Sub sckServer_ConnectionRequest _
(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
intMax = intMax + 1
Load sckServer(intMax)
sckServer(intMax).LocalPort = 0
sckServer(intMax).Accept requestID
Load txtData(intMax)
End If
End Sub

UDP Basics
Creating a UDP application is even simpler than creating a TCP application because the UDP protocol doesn't require an explicit connection. In the TCP application above, one Winsock control must explicitly be set to "listen," while the other must initiate a connection with the Connect method.

In contrast, the UDP protocol doesn't require an explicit connection. To send data between two controls, three steps must be completed (on both sides of the connection):

Set the RemoteHost property to the name of the other computer.


Set the RemotePort property to the LocalPort property of the second control.


Invoke the Bind method specifying the LocalPort to be used. (This method is discussed in greater detail below.)
Because both computers can be considered "equal" in the relationship, it could be called a peer-to-peer application. To demonstrate this, the code below creates a "chat" application that allows two people to "talk" in real time to each other:

To create a UDP Peer

Create a new Standard EXE project.


Change the name of the default form to frmPeerA.


Change the caption of the form to "Peer A."


Draw a Winsock control on the form and name it udpPeerA.


On the Properties page, click Protocol and change the protocol to UDPProtocol.


Add two TextBox controls to the form. Name the first txtSend, and the second txtOutput.


Add the code below to the form.
Private Sub Form_Load()
' The control's name is udpPeerA
With udpPeerA
' IMPORTANT: be sure to change the RemoteHost
' value to the name of your computer.
.RemoteHost= "PeerB"
.RemotePort = 1001 ' Port to connect to.
.Bind 1002 ' Bind to the local port.
End With
frmPeerB.Show ' Show the second form.
End Sub

Private Sub txtSend_Change()
' Send text as soon as it's typed.
udpPeerA.SendData txtSend.Text
End Sub

Private Sub udpPeerA_DataArrival _
(ByVal bytesTotal As Long)
Dim strData As String
udpPeerA.GetData strData
txtOutput.Text = strData
End Sub

To create a second UDP Peer

Add a standard form to the project.


Change the name of the form to frmPeerB.


Change the caption of the form to "Peer B."


Draw a Winsock control on the form and name it udpPeerB.


On the Properties page, click Protocol and change the protocol to UDPProtocol.


Add two TextBox controls to the form. Name the TextBox txtSend, and the second txtOutput.


Add the code below to the form.
Private Sub Form_Load()
' The control's name is udpPeerB.
With udpPeerB
' IMPORTANT: be sure to change the RemoteHost
' value to the name of your computer.
.RemoteHost= "PeerA"
.RemotePort = 1002 ' Port to connect to.
.Bind 1001 ' Bind to the local port.
End With
End Sub

Private Sub txtSend_Change()
' Send text as soon as it's typed.
udpPeerB.SendData txtSend.Text
End Sub

Private Sub udpPeerB_DataArrival _
(ByVal bytesTotal As Long)
Dim strData As String
udpPeerB.GetData strData
txtOutput.Text = strData
End Sub

To try the example, press F5 to run the project, and type into the txtSend TextBox on either form. The text you type will appear in the txtOutput TextBox on the other form.

About the Bind Method
As shown in the code above, you must invoke the Bind method when creating a UDP application. The Bind method "reserves" a local port for use by the control. For example, when you bind the control to port number 1001, no other application can use that port to "listen" on. This may come in useful if you wish to prevent another application from using that port.

The Bind method also features an optional second argument. If there is more than one network adapter present on the machine, the LocalIP argument allows you to specify which adapter to use. If you omit the argument, the control uses the first network adapter listed in the Network control panel dialog box of the computer's Control Panel Settings.

When using the UDP protocol, you can freely switch the RemoteHost and RemotePort properties while remaining bound to the same LocalPort. However, with the TCP protocol, you must close the connection before changing the RemoteHost and RemotePort properties.

Verwijderd

Op dinsdag 19 februari 2002 10:37 schreef thomasbansberg het volgende:
Using the Winsock Control
Zo, zet jij MSDN even online >:)

Verwijderd

Op dinsdag 19 februari 2002 10:41 schreef Sepans het volgende:

[..]

Zo, zet jij MSDN even online >:)
cewl waarom iets in 5 regels code doen als het in 5 pagina's kan.. |:(

  • sebastius
  • Registratie: September 2000
  • Laatst online: 09-09 19:18

sebastius

Laten we lekker link gaan doen

Topicstarter
Hee, een soort groupchatbox? Grappig plan. Ga ik nog mee klooien, maar NET SEND is nu ff voldoende hierzo.

  • johnwoo
  • Registratie: Oktober 1999
  • Laatst online: 14:28

johnwoo

3S-GTE

Misschien een mooiere oplossing dan telkens net.exe te shellen: de NetMessageBufferSend API.
The NetMessageBufferSend function sends a buffer of information to a registered message alias.

Declare Function NetMessageBufferSend Lib "NETAPI32.DLL" (yServer As Any, _
yToName As Byte, _
yFromName As Any, _
yMsg As Byte, _
ByVal lSize As Long) As Long

· servername
[in] Pointer to a constant Unicode string specifying the name of the remote server on which the function is to execute. The string must begin with \\. If this parameter is NULL, the local computer is used.

· msgname
[in] Pointer to a constant Unicode string specifying the message alias to which the message buffer should be sent.

· fromname
[in] Pointer to a constant Unicode string specifying who the message is from. If this parameter is NULL, the message is sent from the local computer name.

· buf
[in] Pointer to a buffer that contains the message text.

· buflen
[in] Specifies a DWORD value that contains the length, in bytes, of the message text pointed to by the buf parameter.
:Y)

4200Wp ZO + 840Wp ZW + 1680Wp NW | 14xIQ7+ + 1xDS3-L | MTVenusE | HWP1


  • sebastius
  • Registratie: September 2000
  • Laatst online: 09-09 19:18

sebastius

Laten we lekker link gaan doen

Topicstarter
haha! Daarmee kan ik dus een andere PC mijn berichtje laten sturen? Briljant! (dat gaan ze niet leuk vinden...)

  • sebastius
  • Registratie: September 2000
  • Laatst online: 09-09 19:18

sebastius

Laten we lekker link gaan doen

Topicstarter
Hmm ik doe iets fout denk ik? ik krijg een wazige error als ik die Declare in een command button dump.

"Only comments may appear after end sub (blablabla)"

Verwijderd

Op dinsdag 19 februari 2002 16:50 schreef sebastius het volgende:
Hmm ik doe iets fout denk ik? ik krijg een wazige error als ik die Declare in een command button dump.

"Only comments may appear after end sub (blablabla)"
Post even (een deel van) je code, is wat duidelijker.

edit: Typen, het blijft moeilijk. :+

  • sebastius
  • Registratie: September 2000
  • Laatst online: 09-09 19:18

sebastius

Laten we lekker link gaan doen

Topicstarter
Gewoon die Declare regel
code:
1
2
3
4
5
Declare Function NetMessageBufferSend Lib "NETAPI32.DLL" (yServer As Any, _
yToName As Byte, _
yFromName As Any, _
yMsg As Byte, _
ByVal lSize As Long) As Long

Die dus een paar reacties hoger stond. Hoe plaats en gebruik ik die?

Verwijderd

Op dinsdag 19 februari 2002 19:05 schreef sebastius het volgende:
Gewoon die Declare regel
code:
1
2
3
4
5
Declare Function NetMessageBufferSend Lib "NETAPI32.DLL" (yServer As Any, _
yToName As Byte, _
yFromName As Any, _
yMsg As Byte, _
ByVal lSize As Long) As Long

Die dus een paar reacties hoger stond. Hoe plaats en gebruik ik die?
PRIVATE Declare Function NetMessageBufferSend Lib "NETAPI32.DLL" (yServer As Any, _
yToName As Byte, _
yFromName As Any, _
yMsg As Byte, _
ByVal lSize As Long) As Long

In de kop van je form Of Declare...(impliciet public)/Public Declare in een .bas module.

[edit] Declareren van API calls kan niet in een Event [edit]

  • sebastius
  • Registratie: September 2000
  • Laatst online: 09-09 19:18

sebastius

Laten we lekker link gaan doen

Topicstarter
Aha, ik ben dus gewoon een beetje dom bezig. Dank Je Wel!

  • sebastius
  • Registratie: September 2000
  • Laatst online: 09-09 19:18

sebastius

Laten we lekker link gaan doen

Topicstarter
Nou doe ik het nog fout geloof ik.
code:
1
NetMessageBufferSend(, basxp, , , 1) = "Hello"

Basxp is mijn pc.

Verwijderd

Kijk ff hier:

http://www.allapi.net/agnet/aanreg.php

Even aanmelden en de api tools downloaden.

Vrijwel alle API's staan hier beschreven inclusief voorbeelden.

[Edit] Je return waarde is een long dus het zal zoiets worden als:

Dim lResult as Long

lResult = NetMessageBufferSend(YourServer, basxp,Reciever ,message , 1)

[edit]

Verwijderd

Maybe this will help....

Gewoon in een formpje plakkenen ff je eigen waarden invullen :+


Private Declare Function NetMessageBufferSend Lib _
"NETAPI32.DLL" (yServer As Any, yToName As Byte, _
yFromName As Any, yMsg As Byte, ByVal lSize As Long) As Long
Private Const NERR_Success As Long = 0&
Public Function SendMessage(RcptToUser As String, _
FromUser As String, BodyMessage As String) As Boolean

Dim RcptTo() As Byte
Dim From() As Byte
Dim Body() As Byte

RcptTo = RcptToUser & vbNullChar
From = FromUser & vbNullChar
Body = BodyMessage & vbNullChar

If NetMessageBufferSend(ByVal 0&, RcptTo(0), ByVal 0&, _
Body(0), UBound(Body)) = NERR_Success Then
SendMessage = True
End If

End Function
Private Sub Form_Load()
'Example created by X-MaD (x-mad@zolnetwork.com)
'Visit his website at http://www.zolnetwork.com/x-mad
Dim RetVal As Boolean
RetVal = SendMessage("Utente", "FromUser", "BodyText")
End Sub

  • sebastius
  • Registratie: September 2000
  • Laatst online: 09-09 19:18

sebastius

Laten we lekker link gaan doen

Topicstarter
Hoei! Ik heb het door! Ik ga ff een mooie app in elkaar klussen. Bedankt! (en eventuele nuttige resultaten zal ik posten...)
Pagina: 1