PG1
PG1

Reputation: 1232

Visual Basic: how to execute commands in cmd without pressing "ENTER" by user?

I am creating a visual basic application where I have a Format drive button, which calls cmd to execute the format code as follows:

cmd_str = "cmd.exe /c format " + driveletter + " /q"
        Call Shell(cmd_str, vbNormalFocus)

where driveletter is the drive name. The problem is to execute the code, the user has to press ENTER KEY twice. I want the command so that the user don't have to press ENTER , so that I can further make the cmd process as hidden . Any suggetions?

Upvotes: 0

Views: 913

Answers (1)

Grintor
Grintor

Reputation: 56

pipe the answers to the questions to it:

format c:

asks a question:

The type of the file system is xxx.

WARNING, ALL DATA ON NON-REMOVABLE DISK
DRIVE C: WILL BE LOST!
Proceed with Format (Y/N)?

if the answer is "y" you can do:

echo y | format c:

that will display the question and auto-enter the answer. If you want to suppress all output do you can do:

echo y | format c: > nul

Upvotes: 0

Related Questions