Hey guyz. I'm trying to make something like insert automticly throught my program in VB6 to do a CMD script.
Thing is, I'm really noob, and i dunno how to save values.
Option Explicit
Private Sub Command1_Click()
Dim Username As String
Username = Text1.Text
End Sub
Private Sub Command2_Click()
Dim Password As String
Password = Text2.Text
End Sub
Private Sub Command3_Click()
Dim PCAddress As String
PCAddress = Text3.Text
End Sub
Private Sub Command4_Click()
Shell ("cmd.exe /k telnet 192.168.1.254")
Timeropentimer.Enabled = True
End Sub
Private Sub Timer1_Timer()
Shell ("cmd.exe /k" & "Username")
Timer2.Enabled = True
Me.Enabled = False
End Sub
Private Sub Timer2_Timer()
Shell ("cmd.exe /k" & "Password")
Timer3.Enabled = True
Me.Enabled = False
End Sub
Private Sub Timer3_Timer()
Shell ("cmd.exe /k wireless macacl add ssid_id=0 hwaddr= "PCAddress" permission=allow name=Test)
Timer4.Enabled = True
Me.Enabled = False
End Sub
Private Sub Timer4_Timer()
Shell ("cmd.exe /k saveall")
Me.Enabled = False
End Sub
Private Sub Timeropentimer_Timer()
Timer1.Enabled = True
Timeropentimer.Enabled = False
End Sub
1) How to make him execute the commands in the same cmd? How to make him react to the strings? How to make timers work properly?
Here are the prints: First non-needed string command
Need Username string
Need password string
Need mac adress string
Last edited by nunopitbull; Jan 8th, 2010 at 06:48 PM.
Private Sub Command1_Click()
Dim Username As String
Username = Text1.Text
End Sub
Private Sub Command2_Click()
Dim Password As String
Password = Text2.Text
End Sub
in both these procedure the variable declared only remains in scope for the duration of the procedure, when it finishes the variable is gone
to keep a variable after the procedure is finished, it must be declared at module level or global (at the top of the form in the general section)
in this case these procedures are pointless as the variables are not really required, text1 and text2 can be accessed from anywhere directly
each time you shell a cmd window it will be a new instance, as far as i know you can not write again to an open command window, without using named pipes or some other suitable code, none of which is at beginner level, search in this forum and the vb6 codebank on named pipes command window or some variations, it may be possible to do using a scripting method, which would be a simpler code, but i have not tried it with telnet
a better alternative might be to use a winsock control to do your communications, rather than trying to automate some old dos program
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
I think the only way was using sendkeys in cmd.exe, but dunno if that exists on vb or dunno how to use them. Like if it was writing by me. Well, it was a good idea thought :/
the vbs code looks simple enough, you could create a vbs file and shell that from vb6
test the example to see if it can do what you want
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Last edited by akhileshbc; Jan 9th, 2010 at 10:06 AM.
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
Here's a sort of dumb example using my ShellPipe control.
This demo is just automating an instance of cmd.exe and then sending time /t to it every tick of a Timer until you quit. The responses are shown in a RichTextBox.
If you focus on using ShellPipe as a control and don't bother looking at its code it is pretty simple to use. Comments in ShellPipe.ctx describe its properties, methods, and events.
Note that ShellPipe works well only with Console (command line) programs that use Standard I/O. Programs that use the Console Device directly won't work because they don't have redirectable I/O.
You could use WSH (VBScript can't do it alone, those are functions of the WSH script hosts WScript and CScript) for controlling a process. However ShellPipe doesn't result in a visible console window lurking around to worry about.
If you really need to Telnet it will be easier to use a Telnet component. There is at least one in the CodeBank area here.