Results 1 to 11 of 11

Thread: Command promt in VB 6

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    4

    Question Command promt in VB 6

    Hi guys,
    I am an begginer in VB... and I need help in running the command promt in my VB program. i know that when i want to run the command promt I type in the button " Shell ("cmd.exe") " and when I run the program and click the button it will run the command promt. Now I want to know how to make the program automaticaly type and execute commands.

    thanx in advance

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

    Re: Command promt in VB 6

    welcome to the forums...

    may be creating a batch file(with the commands needed) and executing it using vb6 is a good idea.... (Shell "mybatchfile.bat" )

    or, some thing like this:
    Code:
    Shell "cmd.exe /c ren abc.txt new.txt", vbHide
    others may have better solutions...

    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,...

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

    Re: Command promt in VB 6

    It depends on how much you can do "blind" and how much requires interaction.

    Simply "typing" a series of fixed commands is pretty easy. You can create a .CMD or .BAT file and execute that.

    However you might need to run a program, give it input, read and parse the output, then give it new input, etc. This requires another approach and a big part of the challenge can be in writing your program to interpret and act on those output responses.

    If all you really want is to perform things like file and directory management though you'd probably be better off just using the related VB6 statements (Kill, FileCopy, MkDir, Name, etc.). I'm not sure what the benefit of spawning CMD.EXE really is unless you just want to use its command-line file redirection for blind operations.

    The simple demo attached here contains ShellPipe and its helper class SmartBuffer. See the ShellPipe source for a description of the control and its use.


    When I need a program to spawn console processes and interact with them I use my ShellPipe control. This lets you start such programs and retain control. You can receive the program's output, send the program input, abort the process as needed, etc. It operates asynchronously using an event model similar to that of the Winsock control.
    Attached Files Attached Files

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    4

    Post Re: Command promt in VB 6

    guys tanx for answers but it didn`t help much... as I said i am an bigginer in VB but I desperately need to make a program. i want to make it like this:

    it would need just to type the names of the files I want to work with and the directory it needs to interact. the parameters between should be automatically typed and executed...

    I know that this is a bit hard since I am just a bigginer but I am a fast learner... please help me...

  5. #5
    Addicted Member pcuser's Avatar
    Join Date
    Jun 2008
    Posts
    219

    Re: Command promt in VB 6

    @dilettante, very nice control!!! Is it ok to use this in my own projects?

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

    Re: Command promt in VB 6

    Quote Originally Posted by pcuser View Post
    @dilettante, very nice control!!! Is it ok to use this in my own projects?
    Sure thing. I don't provide support though, so I hope the logic is clear enough if you want to modify it for your own needs.

    It is pretty stable now though and I use it "as is" in many projects. I'm at the point where I treat it as a black box just as if it were compiled into an OCX.

    You might have another alternative to the SmartBuffer class. If you do use SmartBuffer you may want to look at the tuning constants CHUNK_SIZE and CHUNK_SOFT_LIMIT and adjust them to fit your application. For example if your interactions with the child process tend to be closer to 80-column lines of text you might make CHUNK_SIZE = 100 or so, and then maybe change CHUNK_SOFT_LIMIT = CHUNK_SIZE * 100 or something.

    The defaults are working pretty well for me, and don't seem to cause any problems with excessive memory consumption.

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

    Re: Command promt in VB 6

    Quote Originally Posted by Arxya View Post
    I know that this is a bit hard since I am just a bigginer but I am a fast learner... please help me...
    You weren't really clear about the operations you want to perform on these files.

    As I said earlier, VB has a number of file-related statements and functions for performing many common operations though. You should not need to spawn and interact with a command interpreter like CMD.EXE to do this.

    Look in the documentation for the Kill, FileCopy, Name, MkDir, and similar statements.


    If those don't do what you need we'll need more information.

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    4

    Re: Command promt in VB 6

    look... it`s not that simple... I need this so I can make a program to extract AUTOMATICALY the .sdc files. The only way to extrack these files is to use the command promt and type everything in... i know that way but it would be simpler to do it like this... thats why I need help... I hope you wont steal my idea

  9. #9
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: Command promt in VB 6

    Your attitude leaves a bit to be desired (look...). The folks here are not paid
    to provide solutions, they volunteer. I have no idea what the extension .sdc
    refers to nor what program does this extraction. If you can do it from the
    command line, then you can easily write a batch file (.bat) to be called from
    VB6. Note that if the process is time consuming you will need to call the
    batch file asynchronously. Google for 'Shell And Wait'

  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    4

    Re: Command promt in VB 6

    I am so sorry for my behavior and I very appreciate your work that you have done for me. Does any of you has a web page or something that could help me learn the basics of Visual Basic 6? I need this because I have a great desire to know how to make projects and programs... and who knows, maybe someday I will do what you are exactly doing... helping others

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

    Re: Command promt in VB 6


    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,...

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