Hi
I would like to add some hard disk cleaning features to my program, like Norton CleanSweep program and other similiar, but I haven't found many information for what I need

1. Remove all shortcut file that points to non-existing files/folders
Ok for this one, do I need to know .lnk file format in order to do that or there is easier way?
Once when I get path on which .lnk file points, how can I determine if that file/directory/whatever exists?

2. Remove all unused/shared dll's from system directory.
Ok so AFAIK windows can somehow register dll's files, I dont know how/what, so far I when developing dll's I only used them for my program private use.
So how can I determine if some dll file is no longer in use by any program, and then to delete it. Maybe those informations are kept in registry or....?
(I know this can be dangerous, so I would create backup for those dlls)

3. Remove all unused shell extensions. That is remove all registrated file types for which program no longer exists. For example when someone installs MS Word, then Word register .doc file to be opened by it. So when Word is uninstalled there could be left .doc files still registrated to point in Word (ok not likely that one will uninstall word or word would not unregister .doc but hey this is just an example :))
Ok so how can I find and remove those unused file types registrations, registry stuff I guess...?
Posted on 2003-01-04 20:08:14 by Mikky
Originally posted by Mikky
1. Remove all shortcut file that points to non-existing files/folders
Ok for this one, do I need to know .lnk file format in order to do that or there is easier way?
Once when I get path on which .lnk file points, how can I determine if that file/directory/whatever exists?

Windows has some Shell APIs (mostly COM) for manipulating Shell Links (the platform SDK has a topic on it (user interface services > windows shell > shell programmer's guide > intermediate shell techniques > programming the shell > Creating shortcuts -> Shell Links). There's even a C++ example of resolving a shortcut. To see if a file or directory exists you can use FindFirstFile (for files CreateFile can be used as well).

2. Remove all unused/shared dll's from system directory.
Ok so AFAIK windows can somehow register dll's files, I dont know how/what, so far I when developing dll's I only used them for my program private use.
So how can I determine if some dll file is no longer in use by any program, and then to delete it. Maybe those informations are kept in registry or....?
(I know this can be dangerous, so I would create backup for those dlls)

This is a very hard one. For a start, you can scan all executables & dlls and check the PE import section for references to that DLL. However packed executables/DLLs usually don't have much import information because the imports are resolved by the packer's loader. It's nearly impossible to get this import information of all executables since so many packers exist. Even if the executable isn't packed, it may call LoadLibrary+GetProcAddress to use a DLL's function at runtime.
You could scan all files for strings containing the DLL's name but it would be very unreliable (even then, you wouldn't find anything in packed executables).
Finally a DLL might contain a COM object which are created without even mentioning the DLL's filename, since it's information is stored in registry. So you'll have to scan the registry as well.
I don't know if Windows holds some information about the DLL usage, I guess windows installer does some bookkeeping...

3. Remove all unused shell extensions. That is remove all registrated file types for which program no longer exists. For example when someone installs MS Word, then Word register .doc file to be opened by it. So when Word is uninstalled there could be left .doc files still registrated to point in Word (ok not likely that one will uninstall word or word would not unregister .doc but hey this is just an example :))
Ok so how can I find and remove those unused file types registrations, registry stuff I guess...?

Probably by scanning the registry as well. File type associates reside at a known place (msdn has info on them, search for 'File Types').

Thomas
Posted on 2003-01-05 06:00:04 by Thomas
Thomas have already answered your questions. However, there is
something im curious about wich relates to the same topic.

How can you wipe the free space on a disk?
Im talking about wiping free space for security reasons ofcourse.
Is this done by creating a file wich is equally big as the free space
on a hdd? or is there something else going on?
Posted on 2003-01-06 10:00:45 by natas
natas -

You could do that, but in Windows it would probably horribly slow the PC if you did it on the swap disk. Also, you wouldn't wipe the space that is left in sectors that are only partially used by a file. It seems to me that the only way is to go really low-level, and get an exclusive lock on the volume.
Posted on 2003-01-06 10:30:21 by Qweerdy


Windows has some Shell APIs (mostly COM) for manipulating Shell Links (the platform SDK has a topic on it (user interface services > windows shell > shell programmer's guide > intermediate shell techniques > programming the shell > Creating shortcuts -> Shell Links). There's even a C++ example of resolving a shortcut. To see if a file or directory exists you can use FindFirstFile (for files CreateFile can be used as well).


I would advice to not use CreateFile to know if a file does exist or not because some applications may open files exclusively and other programs won't be able to open them successfully...
Imho it is better to stick with FindFirstFile that sounds the most secure way to find out if a file exist or not.
Posted on 2003-01-06 12:14:20 by JCP
Hi, thanks for your replays
I solved checking .lnk files if they are valid links, that was easiest problem here
Eventually I will solve sell extension part, but main problem I think would be finding what shared dll's are no more in use.

Scanning dll's and exe's PE header is certanly not the way to go, I dont think that guys from Symantec did that. There's got to be legal way, probably with windows registry or somthing... Problem is that I can't not find information about that.
Posted on 2003-01-06 16:11:58 by Mikky

Scanning dll's and exe's PE header is certanly not the way to go, I dont think that guys from Symantec did that. There's got to be legal way, probably with windows registry or somthing... Problem is that I can't not find information about that.
Why is that not "legal"? there is nothing wrong with scanning the import
section of a file? Im quite certain that the registry does not contain such
information. When you create a DLL file it doesnt automatically register itself
in the registry upon use. However some shared dlls may have a registry
entry. Still this would only be the group of files wich are always used.

Have you ever heard of a Dependency scanner? those kind of utillities have
been available for years(even from MS$). IIRC they just scan the import section
of the files.

Mikky, How is your program running now? have you guys fixed
the service problems in XP/etc.? hope you guys got most of the bugs
out? :alright:
Posted on 2003-01-06 16:38:38 by natas
Originally posted by Mikky
Scanning dll's and exe's PE header is certanly not the way to go, I dont think that guys from Symantec did that. There's got to be legal way, probably with windows registry or somthing... Problem is that I can't not find information about that.


There is no legal way since DLL functions can be resolved at runtime by a process which might even use encryption based on a password typed in by a user to decrypt the DLLs function name before calling it (yes, useless, but possible). Sure scanning import sections is a clean way but you'll never get 100% reliability (one packed exe and it's over). Unfortunately you need this reliability in tools like this. You don't want it to delete DLLs that are used quite often but not seen by the tool.

However there's one way I thought of, you could check the 'last access time' of each DLL. I don't know if FAT systems store these times but NTFS does it for sure. If the DLL hasn't been used for a year there is a great possibility it's useless. On the other hand, it might have been not used since a week while actually no program is using it anymore. But maybe it's of some use to you.

Thomas
Posted on 2003-01-06 17:16:40 by Thomas
So not a single person in this board has ever looked for 'applog'?? :eek:

.... press F3 and type that, and look on that dir what cool things live there.... hehehe.

My personal suggestion for hard disk cleaning, Mikky, is just to delete Temporary Internet Files... if you don't tune well IE, and still use it, the HDD easily gets hundreds of megs of bullshit... :tongue:

The dll cleaning sounds nice, but it takes a big effort for not that much sttuff.. :( ... but if you really insist on it, I'm sure applog will help ya. :)
Instead you could document wich app's use wich dll's (and/or others extensions as well: vxd, cpl, ... : ) and how often (or if they use only one or a few functions of it) ... that I think could be cool... :)

Anyway, I hope this reply at least added you something.
M$ has the annoying habit (really pisses me off >: ( of logging every little tackling insignificant useless thing your computer does... happilly many of them are very dumb to "turn off"... lol... ;)

Regards to you all,

Wicr0s0ft :alright:
Posted on 2003-01-06 20:23:06 by wicr0s0ft