Results 1 to 2 of 2

Thread: Cmd.exe

  1. #1
    Junior Member
    Join Date
    Aug 2004
    Posts
    25

    Unhappy Cmd.exe

    Hi there,

    Please could someone tell me how I can execute/load a program from within a C program. What I really need is to be able to execute the C:\WINDOWS\SYSTEM32\CMD.exe executable from within a C program.

    Any help would be greatly appreciated.

    Thanx, in advance,
    TTAYO

  2. #2
    using the system() function...

    here's a program i'm working on, at the moment it works the same as the cmd.exe, check to see how it calls the commands:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <strings.h>
    
    
    int main(void)
    {
        char comm[200];
        char cwd[100];
        char dir[200];
        int i,j;
                                   
            while(1)
            {
            getcwd(cwd,100);
            printf("\n%s>",cwd);
            gets(comm);
            if(strlen(comm)>199)
                free(comm);
            if(strcmp(comm,"exit")==0||strcmp(comm,"quit")==0)
            {
                free(comm);
                free(cwd);
                return EXIT_SUCCESS;
            }
            if(comm[0]=='c'&&comm[1]=='d'&&comm[2]==' ')
            {
               j=3;
               for(i=0;i<strlen(comm);i++)
               {
                   dir[i]=comm[j];
                   j++;
               }
               chdir(dir);
            }
            else
            {
                system(comm);
            }
         }        
         return EXIT_SUCCESS;
    }
    so if you would like to execute the cmd you could use the following code:
    Code:
    #include <stdio.h>
    
    int main(void)
    { 
             char *command="cmd.exe";
             system(command);
             return 0;
    }

    hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •