0

I have an executable file at location D:/a.exe. I changes its extension to a.txt. Now I would like to execute it using c program. i am following c code.

#include<windows.h>

system("start D:/a.txt");
// or
system("D:/a.txt");

The program doesn't execute it but open it into Notepad. How do I execute a.txt which is in reality is an executable file?

6
  • Try CreateProcess. Commented Nov 28, 2014 at 13:25
  • Watch Out This Question You Will Find Solution... stackoverflow.com/questions/13541956/… Commented Nov 28, 2014 at 13:27
  • Use CreateProcessW on Windows and the exec family of functions on Unix. Commented Nov 28, 2014 at 13:27
  • This is not a C question, but one about DOS/Windows. I added tags. Commented Nov 28, 2014 at 13:31
  • 1
    You'll need to provide more information about the OS version and settings. system uses the command interpreter that's set in the COMSPEC environment variable. The default is cmd, which always tries CreateProcess before falling back on ShellExecuteEx, so it should work; it does for me in Windows 7. Commented Nov 29, 2014 at 1:10

1 Answer 1

0

First you rename it then you launch it. You cannot launch a txt extension as an executable file.

#include<windows.h>

char oldname[] = "D:/a.txt";
char newname[] = "D:/a.exe";

ret = rename(oldname, newname);

if(ret == 0) 
{
    system("start D:/a.exe");
}
Sign up to request clarification or add additional context in comments.

Comments

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.