VBA calls the Command executed under the CMD command line

Source: Internet
Author: User

1. Start the Windows Command Interpreter

CMD [/A |/u] [/q] [/d] [/E: On |/E: Off] [/F: On |/F: off] [/V: On |
/V: Off]

[[/S] [/c |/K] string]

/C: Execute the specified string command and then abort

/K executes the specified string command but retains

/S modify string processing after/C or/K (see below)

/Q close echo

/D stop executing the autorun command from the Registry (see below)

/A converts the output to an internal pipeline or file command to ANSI

/U converts the output to an internal pipeline or file command to Unicode

/T: FG sets the foreground/background color (for details, see color /?)

/E: Enable command extension on (see below)

/E: off stop command extension (see below)

/F: Enable file and directory name completion characters on (see below)

/F: off stop file and directory name completion characters (see below)

/V: On! Start and delay environment variable extension as a separator. For example,/V: On will

Yes! VaR! Allowed during execution! VaR! Extension variable VAR. VaR syntax

Variable extension during input, which is different from in a for loop.

/V: Off disables latency environment extension.

2. Call command line parameters in Java

Java runtime.getruntime(cmd.exe C (commandstr) can call and execute the CMD command.

CMD/C dir: Close the command window after executing the Dir command.


CMD/K dir does not close the command window after executing the Dir command.


CMD/C start dir opens a new window and executes the Dir command. The original window is closed.


CMD/K start dir will open a new window and execute the Dir command. The original window will not close.


3. Example

Shell ("command.com/C [command]", [windowstyle])

1. Execute the BAT file
Shell "batname"

 

 

2. Execute the Java EXE file

Shell ("exename", 1)

3. Execute a Java File

Shell "Java myjavaclass"

4. Open a file

Shell "CMD/c cmd /? > C:/cmdhelp.txt"

5. Clear files in cookies

Shell "C:/window/system32/cmd.exe/C del" "C:/cmdenmts and settings/my family/cookies/*. txt """,

6. Execute the EXE execution File

Shell "notepad.exe D:/ping.txt"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.