Thema: making executable that executes an file

could anyone help me in finding out how to write an c++ code for an win32 PE executable (shell.exe) that once executed would look in an text file (shell.ini) and execute the program of wich the path is written in the textfile then exit
i need it preferabely in c++ so i can add options an further improve it
i want the file in order to rename it to explorer.exe an put it in / so will load instead of window's explorer at boot<p>although i would really apreciate the full code because i am an newbie in c++ and the entire code would be great for me to work on  any kind of help ranging from links to documentation or the name of the variable used to call an file and execute it is welcome

2

Re: making executable that executes an file

Howdy! <p>That shouldn't be a big problem ... but I just know c, so I will post it in c.
<blockquote><font size="1" face="Verdana, Helvetica, sans-serif">Code:</font><hr><pre>
#include <stdio.h><p>int main() {
    char *to_exec;    //the programmes that are to be run
    const char *path = "shell.ini"; //the path to the shell.ini or whatever you name the file
    FILE *f; <p>   f = fopen(path,"r"); //open the file in rea mode
    while(fscanf(f,"%s",&to_exec) != EOF) { //read as long till you come to the end of the file (line by line
           system(to_exec); //execute every command
    }
    close(f) //close file again <p>   return 1;
}
</pre><hr></blockquote><p>It has been a little while since I programmed in C, but I hope everything is right. Your shell.ini should look like this:
c:something.exe
d:folderprogramme.exe
etc. 
Every line in teh shell.ini stands for one command...<p>I hope you understand everything, otherwise you ask...<p>CU Az

Life is given...life is taken
and somewhere there between I live my life

Re: making executable that executes an file

Thank You Azrael !

Re: making executable that executes an file

but your path has to be one word, so replace scanf with gets or fscanf with fgets (and replace the n with )
look in your compiler's help

mfG whitehouse

Re: making executable that executes an file

ok i did that white ...thanx .....but i cant find no /n to replace
<blockquote><font size="1" face="Verdana, Helvetica, sans-serif">Code:</font><hr><pre>
#include <stdio.h><p>int main()
{
    char *to_exec;
    const char *path = "shell.ini";
    FILE *f;
    f = fopen(path,"r");
    while(fgets(f,"%s",&to_exec) != EOF)
    {
    system(to_exec);
    }
    close(f);
return 1;
}
</pre><hr></blockquote><p>but still would anyone be able to show me how to convert the code to C++ ?

Re: making executable that executes an file

be satisfied. this is correct c++.
while writing n I thought the escape sequence meaning NEWLINE. just n (10).
<blockquote><font size="1" face="Verdana, Helvetica, sans-serif">Code:</font><hr><pre>
for (int i = strlen(s) - 1; i >= 0; i--)
   if (s[i] == 'n') {
     s[i] = 0;
     break;
   }
</pre><hr></blockquote>
should work (it's C++ - the "int i" in the for-loop wouldn't be allowed in "Old Plain C")

mfG whitehouse

Re: making executable that executes an file

<blockquote><font size="1" face="Verdana, Helvetica, sans-serif">Code:</font><hr><pre>
#include <stdio.h>
#define N 256
int main()
{
   char link[N];
   const char *path = "shell.ini";
   FILE *f = fopen(path, "r");
   while ( fgets(link, N, f) )
   {
     for (int i = strlen(link) - 1; i >= 0; i--)
       if (link[i] == 'n')
       {
          link[i] = 0;
          break;
       }
     system(link);
   }
}
</pre><hr></blockquote>
i haven't tested it yet

mfG whitehouse

Re: making executable that executes an file

what can i say ... thank you !
it goes to show how good this board is as i posted the same topic on 3 some other boards and got no reply<p>but there is still an minor problem
when using Microsoft Visual C++ 6.0 to compile i get the following 2 errors :<p>: error C2065: 'system' : undeclared identifier
: error C2065: 'strlen' : undeclared identifier<p>this is the code i used ... notice i added an return 0; at the end of it
<blockquote><font size="1" face="Verdana, Helvetica, sans-serif">Code:</font><hr><pre>
#include <stdio.h>
#define N 256
int main()

    char link[N]; 
    const char *path = "shell.ini"; 
    FILE *f = fopen(path, "r"); 
    while ( fgets(link, N, f) ) 
    {   
    for (int i = strlen(link) - 1; i >= 0; i--)
    if (link[i] == 'n')   
    {
     link[i] = 0; 
     break;     
     } 
     system(link);
      }
     return 0;
}
</pre><hr></blockquote><p>bythe way i have to ask this is there any diference between visualC++ (VC++) and C++ or its the same language ?<p>[ 16.01.2002: Beitrag editiert von: developed ]</p>

Re: making executable that executes an file

please report if I'm not right but you shouldn't forget to include <stdlib.h> and <string.h> - I did
this means, add after the line #include <stdio.h>
<blockquote><font size="1" face="Verdana, Helvetica, sans-serif">Code:</font><hr><pre>
#include <stdlib.h>
#include <string.h>
</pre><hr></blockquote>

mfG whitehouse

Re: making executable that executes an file

well whitehouse you are right again ...i included and it works like an charm
i hope i will be able to make it up for this....my friends tell me my im really good at graphics so if u ever need some grafix work feel free to ask

Re: making executable that executes an file

oh, I think C (and C++) is a wonderful language so it was just fun to do that. it's our "job" to help.

mfG whitehouse