Sign in to follow this  

need help with c++ !!!

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

so i got a question for c++ ! 1. i want my program to check if there is a running process named "blabla.exe" or something like that. 2. i want to, if he finds this process, shut down the programm. 3. how can i delete programms ? i mean like in visual basic it was: kill c:/programs/hi/lol.txt what is this in c++ ??? 4. How can i check for a data on the computer ? like c:/programs/hi/lol.txt how can i look for this data on c++ ? thanks

Share this post


Link to post
Share on other sites
The only way I know how to do it in C++ is with the system() function.

It lets you give commands at a fake dos prompt, like system("delete file.exe");
It's bad to use it for somereason though.
Just include <cstdlib> to use it.

Share this post


Link to post
Share on other sites
Not to be offensive, but I have to admit, I am rather suspicious of your motives. You wish to shut things down, delete files, and find data, have a name like ShitFire, and seem to have not put forth much effort searching for the answers elsewhere before asking people who have to spend time to respond. So first of all, please expand on the purpose for which you want to know these things, because they could be used in a malicious way, and I'd prefer not to help someone with malicious activities. I am truly sorry if I've got it all wrong, but I'd rather be on the cautious side, so hopefully you'll understand.

Share this post


Link to post
Share on other sites
well i think i have to reply to the last post !

i do NOT have the pupose of making any virus!!!

i will tell u why i need this: So I was making a text based RPG for c++ with my friend but then i noticed that this project is going to take far to long for that what it is worth.
i decided to make a different project: ANTI virus !!!

yes i want to see if i can do this. yesterday i came on to this idea because i have some adware called: IBIS TOOLBAR. well i cant get rid of it... i had to get tons of Antivir programs. i am even surfing with mozilla...

i thought how cool Kaspersky was so i wanted to make my own ^^

thatswhy i need this: detect running process: (Wsup.exe)
stop process.
delete data of virus. (if i know what the data is :P )

please dont missunderstand me :(


EDIT: i tried this:

i opened an Opengl program named : LadyOfDarkAutumn.exe
then i went on: system("delete LadyOfDarkAutumn.exe");

but he didnt delete it :/ hmm...
thansk for helping ;)

thx

Share this post


Link to post
Share on other sites
Sounds like spyware, and not a virus, to me. BTW, it's easier to program a text RPG than it is to program Antivirus software.

It's a little more than just shutting down processes and deleting files. I say re-format your computer, and stick with your original RPG plans :)

Share this post


Link to post
Share on other sites
well no i dont want to stick with text rpgs ;)

i know that i cant delete the virus i am scanning (i dont mean my spyware!!!) but atleast i can detect it!

i searcht a while and i came but with:

#include "windows.h"
DeleteFile("LadyOfDarkAutumn.exe");

i put it in a dos program but it doesnt work :(

please can some1 help me and tell me how i can detect and shut down processes ?

at least u could tell me how to detect. that would be a start.

thanks ;)

Share this post


Link to post
Share on other sites
anything you write inside system() function is same as writing it in a dos/console prompt.
for deleting files you can use remove("c:/programs/hi/lol.txt");
it is an ANSI-C function to erase files.
I was thinking you're doing a small app to remove some spyware you cant delete.
In Windows, instead of writing your own files finder algorithm- you can use a ready one.
If you're programming in .NET, you probably like to look at the Process Class.
I see you're intersted in Security, then you may be intersted in this link.

By the way, deleting doesn't mean shutting down.
what you tried to do, is to delete LadyOfDarkAutumn.exe from the current directory, which doesn't exist or cannot be removed while running?
you want to close LadyOfDarkAutumn.exe, right? (i dont know how to do this instead of using the Process Class.)

pex.

Share this post


Link to post
Share on other sites
you cant run 'x' and delete 'x' while 'x' is still running.
same why you cant write/edit 'x' while it is running.
you can do that each time windows is start- you'll delete 'x'.
just add 'delete x' in c:\auto.bat (i think this is the file in win98, but i dont think it is exist in xp. well, you can always make a small program which deletes x and tell windows to run this file before any other program (exept windows of course).
it is somewhere inside the Registry. i found it in past, just a second.

pex.

Share this post


Link to post
Share on other sites
Well i tried this code:

#include "stdio.h"

void main()
{
cout<<"Geben sie was ein"<<endl;
cin>> a;
if(a==b)
{
remove("c:/hiho.txt");
}
}

but it doesnt delete the .txt file :(

what should i do ?

Share this post


Link to post
Share on other sites
Isn't it #include <stdio.h>?
anyway, then the remove() function returned a non-zero number, right?
is hiho.txt read/writeable? (have you tried DeleteFile() instead?)

by the way, this is the registry address:
HKEY_LOCALMACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Value name: program name
Type: REG_SZ
Data: program full address

Share this post


Link to post
Share on other sites
Quote:
Original post by ShitFire
Well i tried this code:

#include "stdio.h"

void main()
{
cout<<"Geben sie was ein"<<endl;
cin>> a;
if(a==b)
{
remove("c:/hiho.txt");
}
}

but it doesnt delete the .txt file :(

what should i do ?



system("del C:\\chiho.txt");


[smile]. You can use dos commands using that system function. However you must make sure the file is not open. If it is open you must close the window. To do that, take a look at my post here.

Quote:

HWND notepad = FindWindow("Notepad","Untitled - Notepad");
if( !notepad )
{
cout << "Cannot find window!";
return 0;
}

SendMessage(notepad,WM_CLOSE,0,0);


Is around the section you need to read.

- Drew

Share this post


Link to post
Share on other sites
Quote:
Isn't it #include <stdio.h>?


Yea, though "stdio.h" will work because if the the compiler (preprocessor.. whatever) can't find it in the current directory it will check your include path(s) automagically. AFAIK, at least. Seems like a bad habit to me though.

Share this post


Link to post
Share on other sites
You haven't actually said what platform your writing this under but as you've got some code above that has a #include "windows.h" in it I'll assume you're using x86/Windows.

First of all look at the Process and Thread functions section of the platform SDK reference in MSDN here. You can use the functions listed there to determine if a particular process is running and terminate it. You can use EnumProcesses to search for the the specific process and get it's handle and then use TerminateProcess to shut it down.

You can use Win32 file management functions (a list of them is available here) to check if a file exists and to delete it. FindFirstFile could be used to find the file and DeleteFile could be used to delete it.

Share this post


Link to post
Share on other sites
You won't usually be able to delete an executable if its currently running.
The windows equivalent of kill is taskkill.
/F forces the kill
/PID kills via process id
/IM kills via imagename
You would then immediatly want to delete the file or quarantine the file.

I had to look up this information a few weeks ago. I was trying to play a DVD on my sister's laptop and it kept pausing and loosing syncronization. We endedup having to write a batch file to kill a program and delete it. It was a particularly nasty program that started itself up immediatly after being shutdown.

Share this post


Link to post
Share on other sites

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this