Hey

I have been having this problem, that my little program here, won't delete the file that i am asking it to. Can anyone help me?
I am using Live Messenger as an example ;)

#include <iostream.h>
#include <windows.h>

int start = 1;

int main()
{

while(start == 1)
	if(start == 1)
	{
		system("taskkill /IM msnmsgr.exe /f");
		Sleep(10000);
                                remove( "C:\Program Files\Windows Live\Messenger\msnmsgr.exe" )
	}
	else
	{
		cout << "FEJL";
	}
}

Plz, ask me if you need to know exactly what i want to make :)

>I am using Live Messenger as an example
Riiight. So what file are you actually trying to delete if not Live Messenger? Your example is a smidge suspicious.

Yea, it's for a test we need to make in a projekt, we have make a program that can delete files quick. It's like some kind of a help to make sure no programs are on a computer if they should't be there. Hope you know what i mean. :)

well Androggles, it is really true, your example is smudge suspicious but i will give you the benefit of the doubt. the system call you are using is not very clear unless i don't know about it but what i know is you can use the system call "RD PATH OF FILE"

eg: rmdir /s [drive:path of file] or rd /s [drive:path of file] (normally works for directories the the /s option deletes every file in the directory).
Again you can also use the "del" command from DOS.
something like system("del [path of file]"). i haven't tryed it but is should work.

the remove("path of file") part of your code should look something like

system("del C:\Program Files\Windows Live\Messenger\msnmsgr.exe").


try this out.

I can see all this bumbling around in the dark resulting in "rmdir c:\" at some point :icon_rolleyes:

Yes guys, i know it looks dark ;) But thats how things are done i school, always the hard way :)

Thx for the anwser geocyt, it worked, but it seems that a normal system("del") can't get acces to the program files directory. But maybe i am doing something wrong :P Although thx for you answers, great help :)

If you are trying this on a school's computer then your school may have locked you out of certain folders, giving you only read-access to c:\program Files and c:\windows. They don't want you screwing around with those folders, possibly adding viruses or deleting important files.

The del command don't work unless you put quotes around the path system("del \"C:\Program Files\Windows Live\Messenger\msnmsgr.exe\"")

If you want to use paths in string, you need to escape the backslash by adding an extra backslash, or use normal slashes instead:

remove( "C:\\blah\\foo.bar" );

or:

remove( "/tmp/foo.bar" );

No, i am on my own computer, running a virtualbox, for safety ;)

Now my code looks like this:

#include <iostream.h>
#include <windows.h>

int start = 1;

int main()
{

while(start == 1)
	if(start == 1)
	{
		system("taskkill /IM msnmsgr.exe /f");
		Sleep(2000);
		system("del C:\\Program Files\\Windows Live\\Messenger\\msnmsgr.exe");
	}
	else
	{
		cout << "FEJL";
	}
}

But still i can only delete files from anywhere else than program files?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.