0

Can anyone tell me what is the code in c programming for the shell function just like in visual basic it is:

Shell("C:\WINDOWS\CALC.EXE", 1)

Thank You

1
  • 1
    simplest of all would be system Commented Jun 5, 2020 at 11:17

2 Answers 2

3

I believe the VB function is just a simplfied wrapper around Windows API ShellExecute.

The equivalent C code would be something like:

#include <windows.h>

ShellExecute(NULL, 
             NULL, 
             "C:\\WINDOWS\\System32\\CALC.EXE",
             NULL,
             NULL,
             SW_SHOWDEFAULT);
Sign up to request clarification or add additional context in comments.

Comments

0

You can try system() function in C.

An example:

system("calc.exe");

Edit: You need to use an escape sequence for representing a backslash, because it itself represents the starting point of defining an esc. sequence (e.g. \n), use \\ wherever you need to append \. For example:

system("My\\Long\\Long\\Path\\program.exe");

4 Comments

It opens the calculator app, but does not open the directory that i asked the program to open. ``` system("F:\Programs for Dev C++\MatrixCode.exe"); ``` The program says the following : 'F:Programs' is not recognized as an internal or external command, operable program or batch file.
@AjayKokill \ inside a C string is reserved for escape sequences. For this reason, you must always use \\ when you want an actual backslash.
In C++, \ is a string escape character. You need to use \\ instead.
@Lundin Ya, ok, got it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.