Error running command with system () function

Guys,

I'm trying to run the following command to uninstall a software, the source code looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[])
{
	char mess[] = "\"C:\\PROGRA~2\\Pasta1\\AUTOUP~1\\UninstallApp.exe\" {56D68699-5DDF-4376-85B2-05B3C268D743} "; 
	
	char mess1[] =  "\"C:\\Windows\\TEMP\\{34D596F3-A716-4A73-98A9-AC65AD2E8DE4}\\{56D68699-5DDF-4376-85B2-05B3C268D743}Uninstall.log\"";

	
	strcat(mess,mess1);
	
	printf("%s\n",mess);
	
	system(mess);
	
	system("pause");
	return 0;
}


The assembly is correct because if there take exit printf and paste directly into the terminal it runs, I tried to run. Exe with administrator permission, or the calling terminal and the return is the same:

"C:\PROGRA~2\Pasta1\AUTOUP~1\UninstallApp.exe" {56D68699-5DDF-4376-85B2-05B3C268D743}Uninstall "C:\Windows\TEMP\{34D596F3-A716-4A73-98A9-AC65AD2E8DE4}\{56D68699-5DDF-4376-85B2-05B3C268D743}Uninstall.log" The syntax of the file name, directory name or volume label is incorrect.
Press any key to continue. . .


Any idea why this error occurs?
Last edited on
Line 16 is a buffer overrun. But that doesn't really explain why it doesn't run. Personally, I'd use CreateProcess to run an external command, I'd never use system.
You say that the string that printf display is correct, but that might not be what gets though to the system function and lower.

It might be that the only reason printf is displaying the string correctly is that nothing has trampled on the bits of your string which have massively overrun the buffer.

Try using a decent sized buffer, e.g.

1
2
3
4
5
6
7
	char mess0[] = "\"C:\\PROGRA~2\\Pasta1\\AUTOUP~1\\UninstallApp.exe\" {56D68699-5DDF-4376-85B2-05B3C268D743} "; 
	
	char mess1[] =  "\"C:\\Windows\\TEMP\\{34D596F3-A716-4A73-98A9-AC65AD2E8DE4}\\{56D68699-5DDF-4376-85B2-05B3C268D743}Uninstall.log\"";

	char mess[1024] = ""; // to zero it
	strcpy(mess,mess0);
	strcat(mess,mess1);


You should consider using CreateProcess as kbw suggested (with decent sized buffer.)

Andy
Last edited on
Guys,

Thank you for using CreateProcess could help.

Thank you so much!!
Topic archived. No new replies allowed.