Liamfraser280

Hi all,

Im writing a little utility to delete the index.dat file, in the temporary internet files, this file is always locked by processes. The only way to delete it, is to find all the programs using it. And kill them all, including explorer which is restarted after the file is deleted. The way i find the handles is to use a command line utility, which passes a text file:

svchost.exe pid: 1196 C:\Documents and Settings\LocalService\Local Settings\Temporary Internet Files\Content.IE5\index.dat
svchost.exe pid: 1196 \BaseNamedObjects\C:_Documents and Settings_LocalService_Local Settings_Temporary Internet Files_Content.IE5_index.dat_32768
svchost.exe pid: 1196 C:\Documents and Settings\LocalService\Cookies\index.dat
svchost.exe pid: 1196 \BaseNamedObjects\C:_Documents and Settings_LocalService_Cookies_index.dat_16384
svchost.exe pid: 1196 C:\Documents and Settings\LocalService\Local Settings\History\History.IE5\index.dat
svchost.exe pid: 1196 \BaseNamedObjects\C:_Documents and Settings_LocalService_Local Settings_History_History.IE5_index.dat_16384
explorer.exe pid: 640 C:\Documents and Settings\Liam\Local Settings\History\History.IE5\MSHist012007092720070928\index.dat
explorer.exe pid: 640 C:\Documents and Settings\Liam\Local Settings\Temporary Internet Files\Content.IE5\index.dat
explorer.exe pid: 640 \BaseNamedObjects\C:_Documents and Settings_Liam_Local Settings_Temporary Internet Files_Content.IE5_index.dat_229376
explorer.exe pid: 640 C:\Documents and Settings\Liam\Local Settings\History\History.IE5\index.dat
explorer.exe pid: 640 \BaseNamedObjects\C:_Documents and Settings_Liam_Local Settings_History_History.IE5_index.dat_32768
explorer.exe pid: 640 C:\Documents and Settings\Liam\Cookies\index.dat
explorer.exe pid: 640 \BaseNamedObjects\C:_Documents and Settings_Liam_Cookies_index.dat_32768
explorer.exe pid: 640 \BaseNamedObjects\C:_Documents and Settings_Liam_Local Settings_History_History.IE5_MSHist012007092720070928_index.dat_32768
msnmsgr.exe pid: 2044 C:\Documents and Settings\Liam\Local Settings\Temporary Internet Files\Content.IE5\index.dat
msnmsgr.exe pid: 2044 \BaseNamedObjects\C:_Documents and Settings_Liam_Cookies_index.dat_32768
msnmsgr.exe pid: 2044 \BaseNamedObjects\C:_Documents and Settings_Liam_Local Settings_Temporary Internet Files_Content.IE5_index.dat_229376
msnmsgr.exe pid: 2044 C:\Documents and Settings\Liam\Cookies\index.dat
msnmsgr.exe pid: 2044 C:\Documents and Settings\Liam\Local Settings\History\History.IE5\index.dat
msnmsgr.exe pid: 2044 \BaseNamedObjects\C:_Documents and Settings_Liam_Local Settings_History_History.IE5_index.dat_32768
msnmsgr.exe pid: 2044 C:\Documents and Settings\Liam\Local Settings\History\History.IE5\MSHist012007092720070928\index.dat
msnmsgr.exe pid: 2044 \BaseNamedObjects\C:_Documents and Settings_Liam_Local Settings_History_History.IE5_MSHist012007092720070928_index.dat_32768
NMIndexStoreSvr.exe pid: 2136 \BaseNamedObjects\C:_Documents and Settings_Liam_Local Settings_History_History.IE5_index.dat_32768
NMIndexStoreSvr.exe pid: 2136 C:\Documents and Settings\Liam\Local Settings\History\History.IE5\index.dat
NMIndexStoreSvr.exe pid: 2136 \BaseNamedObjects\C:_Documents and Settings_Liam_Cookies_index.dat_32768
NMIndexStoreSvr.exe pid: 2136 C:\Documents and Settings\Liam\Cookies\index.dat
NMIndexStoreSvr.exe pid: 2136 \BaseNamedObjects\C:_Documents and Settings_Liam_Local Settings_Temporary Internet Files_Content.IE5_index.dat_229376
NMIndexStoreSvr.exe pid: 2136 C:\Documents and Settings\Liam\Local Settings\Temporary Internet Files\Content.IE5\index.dat

It lists all the processes using index.dat, and gives the process id, which i need to kill the process. As you can see, the same process is on the list a few times.

Im struggling to think of a way to get only the four PID's i need (1196, 640, 2044, 2136) from the string.

Also, if there are 21 different PID's, i need to get them all

Maybee if you do a code to get all the int's after "pid:", and list them

i just dont know

Any help would be great


Re: Visual C# General Please Help, Getting and Sorting Data from Strings???

Zamial

the way to do it is to read line by line and get every PID into a List.

The finally loop though that array and insert the pid into a new array only if it does not already exist. You will finally have an array of just the pid's you want. It's not really smooth and sexy but it get's the job done

For instance the second part looks a bit like

List<int> pids = new List<int>();

//loop thru text file i have all pids.

foreach(line in textfile)

{

pids.Add(extractedPidId);

}

List<int> uniquePids = new List<int>();

foreach(int pid in pids)

{

//note the ! <---

if(!uniquePids.Contains(pid)

{

uniquePids.Add(pid);

}

}





Re: Visual C# General Please Help, Getting and Sorting Data from Strings???

Peter Ritchie

And what happens if you kill a process that is currently writing data to this file and cut it off in the middle Do you think that file will not be corrupted






Re: Visual C# General Please Help, Getting and Sorting Data from Strings???

Zamial

If the ultimate goal is to delete the file would it not be important if it was corrupted though

I personally have never wanted to delete index.dat and i've heard it monitors everything i am doing





Re: Visual C# General Please Help, Getting and Sorting Data from Strings???

Peter Ritchie

It may not be important to the application killing processes. But, the other processes that are still using it, are still using it. If they encounter a corrupted file, there's not telling what will happen. (i.e. bad things).






Re: Visual C# General Please Help, Getting and Sorting Data from Strings???

Liamfraser280

It dont really matter if it gets corrupted, because its getting deleted anyways




Re: Visual C# General Please Help, Getting and Sorting Data from Strings???

Zamial

Yea i agree with that Peter means that when you start killing processes using the file, other processes may crash when they encounter a corrupted file or a file that is not released and cannot be read or written to. Hence I guess you could create some real problems for yourself and force the user to have to reboot Smile

I see where he's coming from you'll have to be careful how you go about killing processes.





Re: Visual C# General Please Help, Getting and Sorting Data from Strings???

Peter Ritchie

The take-away is you can't be careful when you go about killing processes. You don't know what they're doing, and you don't know what the consequences are of killing them. index.dat is just one file that these applications are using; what if they're using other files, or other system resources (it's very unlikely that all they're doing is read/writing index.dat). You're pretty much guaranteed to cause issues with all the other applications in your list that are using index.dat when you start killing processes; but you're also likely to cause other problems.






Re: Visual C# General Please Help, Getting and Sorting Data from Strings???

Peter Ritchie

Another problem is between the generation of the text file containing the list of processes using index.dat and when you actually try to kill a process with a given PID, that process may have exited and another process may have been created and has been assigned that, now free, PID. So, you'd be killing a process that has nothing to do with index.dat.






Re: Visual C# General Please Help, Getting and Sorting Data from Strings???

Liamfraser280

Actually, the text file is made in the same event as the event where the process will be killed, so...

its made about 1/2 second before its actually killed




Re: Visual C# General Please Help, Getting and Sorting Data from Strings???

eradicator

I think there's a larger question to ask: WHY is there a perceived 'need' to delete this file in the first place No need to directly answer me, I just hope the author of this topic has really thought this out. Somehow I doubt he/she is even barking up the right tree.






Re: Visual C# General Please Help, Getting and Sorting Data from Strings???

Liamfraser280

I know why im writing this, lol

Because when you ask internet explorer to clear all history, the index.dat are not cleared, so this offers some privacy




Re: Visual C# General Please Help, Getting and Sorting Data from Strings???

Peter Ritchie

Liamfraser280 wrote:
Actually, the text file is made in the same event as the event where the process will be killed, so...

its made about 1/2 second before its actually killed
On my system about 8-12 applications can be started and terminated in 1/2 second, not to mention the time it takes to loop through all the processes in your list and kill them. On my system PIDs seem to always be three or four numbers; making highly likely that PIDs would be reused in a relatively short amount of time.