Clicky

I've written a (VB) script that when deployed via SCCM silently deletes an old program off a PC that is not being used anymore.  On most PCs this works fine, but on a small proportion of PCs, this fails to delete some TTF font files that are stored in a subfolder of the programme's installation folder in Program Files.
eg  C:\Program Files\Supplier\AppName\Fonts

If I try and delete them manually through the GUI it acts as though they're in use and if I try it from a command prompt I get an Access Denied.  Effective Permissions shows I have full control and from a command prompt I CAN /rename/ them or /move/ them to a different folder but not delete them!  The files only have the +A attribute.  I can't run Handle against the PC (remotely) as it would pop up the EULA box.  I suspect it will merely show them locked by Explorer.

My uninstalling script uses the FileSystemObject to recursively delete the app folder like this:
Sub DeleteFolder(ByVal strFolder)
 a) Bind to strFolder using the FSO
 b) Enumerate subfolders
 c) For Each subfolder, Call the Sub again specifying the subfolder path
 d) Use the folder's Files collection to enumerate and then [force] delete all files in the folder
 e) Delete the now empty folder
End Sub

Has anyone seen this phenomenon before?  (Windows XP)
After a bit of Googling I found someone else who'd seen something similar having dropped a TTF file to their desktop.  No obvious reason though and I don't know why it only sometimes happens.

asked 12/12/2011 12:24

cantoris's gravatar image

cantoris ♦♦


6 Answers:
Having just submitted that, I've discovered the fonts listed here:
HKLM\Software\Microsoft\WindowsNT\CurrentVersion\Fonts
There's a load of String values where the name is the font name and the value is the full path to the TTF file within the app's folder.

If I delete them from the registry, I still can't delete the font files.  Perhaps after a reboot they'd be deleteable.  Is there a formal way of unregistering a font?
link

answered

cantoris's gravatar image

cantoris

Sounds like the fonts are registered with Windows, might not allow you to delete them directly if this is the case. I recommend having your script remove the font from the registry whenever it encounters a TTF file.

Fonts are under "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\FontName" so you will need to delete this key first and then you should be able to delete the TTF file.
link

answered 2011-12-12 at 08:34:28

the_endjinn's gravatar image

the_endjinn

Sorry, just seen your comment.

Yes, try a reboot after removing the registry entry, the font will already be loaded and I'm not aware of a way to unload it without the reboot.
link

answered 2011-12-12 at 08:35:45

the_endjinn's gravatar image

the_endjinn

Thanks :)

I'm wondering about using PendingFileRenameOperations to handle the deletion on the next reboot since I want it to be silent and automatic.
I know that this key is a multistring key and that the second of each pair of strings needs to be null.
How can I write this in using the SetMultiStringValue value of the WMI StdRegProvider?

I know I'd give it an array as a parameter, so for array index 0 I'd have a string like
"\??\C:\Program Files\Supplier\Appname\Fonts\font.ttf"  (but without quotes)
and then for array index 1 would I set it to Chr(0) ?
and then array index 2 would be the next file and so on.

There's also the question of the containing folders.  After deleting the CurrentControlSet font registry keys and rebooting, none of the folder tree should be locked so can I just put the uppermost parent folder name (and null) in as a single pair in the Pending key and ignore the individual files?
ie  "\??\C:\Program Files\Appname" - with or without a trailing "\"?

Thanks for any help.
link

answered 2011-12-12 at 08:36:45

cantoris's gravatar image

cantoris

OK I've found the answer to how to use PendingFileRenameOperations after a lot of experimenting!

Passing SetMultiStringValue an Array("\??\C:\Program Files\Supplier\Application\File", Chr(0))  works perfectly!
But it doesn't appear to work for a folder unless it's empty.
It does work though if I pass it a multistring containing all the folder contents in order followed by paths and parent paths - working my way back up the tree so it can delete them in order - this should be easy to add to my recursive script since that's the order the deletion attempts anyway.

Any suggestions for easier ways to do this, or better still, any ideas as to what would be the official technique for this whole issue?
link

answered 2011-12-12 at 09:12:45

cantoris's gravatar image

cantoris

I'm stripping the relevant font values from the registry then trying to delete the files and any that fail I'm adding into the Pending key using a subroutine I've now written.

link

answered 2011-12-12 at 10:57:26

cantoris's gravatar image

cantoris

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×1

Asked: 12/12/2011 12:24

Seen: 351 times

Last updated: 12/17/2011 05:21

Related questions