Problem in CGI - C

udhayakumar
udhayakumar used Ask the Experts™
on
Hai,

I have problem in CGI-C.

This is my Exec.htm.It is displaying textbox controle and submit button.

printf("<html>\n");
printf("<head>\n");
printf("<title>Execute</title>\n");
printf("</head>\n");
printf("<body>\n");
printf("<form name=\"frm\" method=\"get\" action=\"ExecuteBatch.cgi\">\n");
printf("<input type=\"text\" name=\"Batch\" value=\"test.bat\">\n");
printf("<input type=\"submit\" name=\"submit\" value=\"submit\">\n");
printf("</form>\n");
printf("</body>\n");
printf("</html>\n");

This is my Exeute batch.cgi.
Here i am decoding and get the value of Batch file name.
Now i want to execute this batch and i will close the browser.

     length = atoi(getenv("CONTENT_LENGTH"));
     if(length == 0)
     {
          return;
     }

     /* Store the request from browser */
     while(i<length)
     {
          pString[i++] = getchar();
     }
     pQString[i] = '\0';

       //I am calling decode function here to decode.
         It resturn the decoded one and i am spliting
         batch file and stroing in executeFile.

      WinExec(executeFile,"SH_SHOW");          
       //This statment close the browser.
       printf("<html>\n");
     printf("<head>\n");
     printf("<script language='JavaScript'>\n");
     printf("function hideToolbar()\n");
     printf("{\n");
     printf("self.close()\n");
     printf("}\n");
     printf("</script>\n");
     printf("</head>\n");
     printf("<body bgcolor='DARKGRAY' onload='javascript:hideToolbar()'>\n");
     printf("</body>\n");
     printf("</html>\n");



      My problem is WinExec() is not wroking proberly.
My IIS is loaded in F drive but batch file is in D:\uuk\test.bat.

      Even if i give Notepad in the text box the server is not poping up Notepad window.

      Can any one please guide me how to do this

Regards
Udhaya
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
first of all what you doing here is insane. any one can type any command and execute it on your server.

anyhow, try winexec with SH_HIDE

Author

Commented:
Thanks for ur reply.

 Actually i hard coded and i given WinExec("CALC",SH_HIDE);

 It is not giving any error.How can i check whether this

code is excuted or not.B'coz i am not able to see the

Calculator window.

Regards
Udhaya
 
check to see if the process is running in task manager
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Hai,

 Yah if i run exe's like Calc,Notepad i am able to see in the process.But if i run exe's created by myself (ex:test.exe)it gives the following error.I am able to see the test.exe in Process.But after clicking ok it vanishes

Intiallization of Comctl32.dll fails.(D:\winnt\system32\Comctl32.dll).

So please let me know how to solve this problem

Regards
Udhaya
this means your executable depends on comctrl32.dll and that there is a problem loading it when the process starts.

could you post the code for the executable you are trying to run?

Author

Commented:
Sorry makerp.

 It is running.I hope i accepet ur answer.I made mistake in my code.Ysd itself i accepet ur answer.I have one more problem in finding directory path in service.

 See now i am hard coding the path of Test.txt which is used as a DB.But after installation i want to know which Drive the software is installed.

 this is the structure of my project

  -- temp (Service.exe)

  -- value (DB)

    So in my code how can i access the DB which is redise in value directory.

 Can u help me?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial