Results 1 to 14 of 14

Thread: Strings(?) And CMD

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    8

    Strings(?) And CMD

    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.

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    8

    Re: Strings(?) And CMD

    Help please :s

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Strings(?) And CMD

    you can not do like this
    Code:
    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    8

    Re: Strings(?) And CMD

    I dunno how to do in another way. I really just wanted the DOS...

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    8

    Re: Strings(?) And CMD

    Isn't there anyway to make Visual Basic to perform the next command.exe in the same smd.exe already open?

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Strings(?) And CMD

    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    8

    Re: Strings(?) And CMD

    From what I see, theres no way to run a single cmd.exe prompt without going to libraries and all that messy stuff :/

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Strings(?) And CMD

    exactly

    there are some vbs examples, see post #12, but this is not using vb6
    http://www.visualbasicscript.com/m29832.aspx
    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

  9. #9

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    8

    Re: Strings(?) And CMD

    Yeah. Too hard :/

    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 :/

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Strings(?) And CMD

    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

  11. #11

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    8

    Re: Strings(?) And CMD

    whats a vbs file and how to do what you saying?

  12. #12
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Strings(?) And CMD

    whats a vbs file and how to do what you saying?
    VBS is VB Script...
    VBS users guide

    ---Edit---

    how to do what you saying?
    See this link
    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


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  13. #13

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    8

    Re: Strings(?) And CMD

    Still, i don't get what to do with that :s

  14. #14
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Strings(?) And CMD

    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.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width