Dos Commands from Vb6 application

rj_khatri
rj_khatri used Ask the Experts™
on
Dear friends,
Hi there

I want to use Dos commands(like type, copy etc) from a vb6 application but don't know how should i proceed.
Please help me in this matter.
Thanks :)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:

if you want to copy a file, you can try "FileCopy"
e.g.
FileCopy "srcfile.xxx", "destfile.xxx"

if you want to get the content of a file, you can try:

    ' open file
    Dim fileh As Integer
    fileh = FreeFile
    Open "yourfile" For Binary As #fileh
   
    ' read from file
    ' into byte array
    Dim filebuf() As Byte
    ReDim filebuf(1 To LOF(fileh))
    Get #fileh, , filebuf

    ' close file after use
    Close #fileh

the content will be read into filebuf...

if you want to execute a command, you can try the "Shell" api
You could put them in a batch file and call them from there

Commented:
What commands, specifically, do you want to use, and what do you want to do with them?

You could simply use the Shell command, and tell it to run "cmd.exe" or "command.exe" and then the dos command.  You can use environ("comspec") to determine the path to the command or cmd app.

e.g.

Shell Environ("ComSpec") & " /k " & "dir c:\",vbnormalfocus

This will list the contents of your c:\ drive, using the DOS "dir" command.

Environ("ComSpec") will resolve to the path of either "cmd.exe" or "command.exe", depending on the operating system.

"/k" tells it to keep the DOS window open after the operation completes.  You could use "/c" if you want to close the window upon completion.

"dir c:\" tells DOS to list the contents of the C drive.

vbNormalFocus tell it to show the DOS window with focus.

Does this help?

Chris


Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Dear Friends

Thanks for your help.

I worked absolutely fine.

Thanks :)

Author

Commented:
Dear Friends

Thanks for your help.

I worked absolutely fine.

Thanks :)
rj_khatri,
If you have an answer that works for you please find the one that worked for you and accept the comment as an answer so this question may be closed out.  You can do this by going to the comment that helped you and looking to the right of the comment header.  Click the Accept comment as answer button and follow the prompts to close it out.  If you'd like to leave it open to receive further possible answers, then by all means leave it open but for no longer than a month.  Thanks.  

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial