Need to change icons on 400 + shortcuts



We have menus with 400 + shortcuts on them that are on a network
drive. We use folder redirection in a group policy in the AD to get
all PCs to look here for their menus. We are looking for a better way
as there is a 10+ second delay after clicking start|programs before
anything displays) but until then I need to do two things

1) check that the path to the icons file is to a valid file
2) change the path to a local .ico file with all the icons in it.(and
eventually set up the menus to be copied locally too) (Can't use
mandatory profiles as users require cached details to log in to
laptops at home.)

I've used the following code that I've copied /combined off the net to
walk the program files directory tree and return the icon for
each .lnk file it finds.

It has two problems

1) Not all folders are recognised as folders. There doesn't seem to
be a pattern here. I can't see why some are listed as DIRs and some
as FILEs. Those recognised as files obviously don't get walked.
2) I think the read_shortcut subroutine requires an absolute path but
my current working directoy (&cwd) only appears to return the parent
dir.

I'm running v5.8.8 built for MSWin32-x86-multi-thread on WIndows XP
SP2
The program files are on a windows share on a 2k3 server.

Any ideas appreciated.

Output
======================
DIR>> Business & Economics
LNK>> Business Plan.lnk
path : Y:/StartMenu/Programs/Business & Economics/Business Plan.lnk
Icon : C:\WINDOWS\explorer.exe,10
LNK>> Economics Today Volumes 7 8 and 9.lnk
path : Y:/StartMenu/Programs/Economics Today Volumes 7 8 and 9.lnk
Icon : ,0
LNK>> Go Chancellor!!!.lnk
path : Y:/StartMenu/Programs/Go Chancellor!!!.lnk
Icon : ,0
LNK>> Nuffield BP.lnk
path : Y:/StartMenu/Programs/Nuffield BP.lnk
Icon : ,0
FILE CorelDRAW Graphics Suite 12
======================

======================
Code
======================
#!/usr/bin/perl -s
use Win32::OLE;
use Cwd; # module for finding the current working directory

my $wsh = new Win32::OLE 'WScript.Shell';

sub read_shortcut {
my $lnk_path = shift; # path of existing .lnk file

my $shcut = $wsh->CreateShortcut($lnk_path) or die;
# $shcut->TargetPath
$shcut->IconLocation
}

# This subroutine takes the name of a directory and recursively scans
# down the filesystem from that point looking for files named "core"
sub ScanDirectory{
my ($workdir) = shift;

my ($startdir) = &cwd; # keep track of where we began

chdir($workdir) or die "Unable to enter dir $workdir:$!\n";
opendir(DIR, ".") or die "Unable to open $workdir:$!\n";
my @names = readdir(DIR) or die "Unable to read $workdir:$!\n";
closedir(DIR);

foreach my $name (@names){
next if ($name eq ".");
next if ($name eq "..");

if (-d $name){ # is this a directory?
print "DIR>> ".$name."\n";
# $name =~ s/ /\\ /;
# print ">>DIR ".$name."\n";

&ScanDirectory($name);
next;
}
if ($name =~ m/.lnk/) { # does this filename
have .lnk in it
print "LNK>> ".$name."\n";
$mypath=&cwd."/".$name;
print "path : ".$mypath."\n";
print " Icon : ".read_shortcut("$mypath")."\n";
}
else {
print " FILE ".$name."\n";
}
chdir($startdir) or
die "Unable to change to dir $startdir:$!\n";
}
}

&ScanDirectory("Y:\\StartMenu");


======================

.



Relevant Pages

  • Re: Sometimes specific folder icons disappear
    ... today I encountered no icon problems!!! ... any icon problem and I am really happy! ... folders (I have the hidden files ... System Manufacturer     Gigabyte Technology Co., ...
    (microsoft.public.windowsxp.general)
  • Re: OT: Win 7... coming unpinned
    ... that the menus look different, but I have no problem with that (for reasons ... Surely that's the same context. ... It adds the phrase "this program" and the icon when the icon you got the ...
    (comp.sys.mac.advocacy)
  • Re: Burning a CD-R
    ... > me down a list of 8 to a CD icon. ... if you see icons for the hard drive and folders in the ... left pane, click Folders on the toolbar so you see File and Folder Tasks. ... Place the mouse cursor over the file you want to copy to CD. ...
    (microsoft.public.windowsxp.newusers)
  • Re: Wanted: a little class around here
    ... an icon handler in C#. Don't know if explorer would like/allow an icon handler for folders since it ... special icon on all program group folders. ... Rev. Bob "Bob" Crispen ...
    (microsoft.public.windowsxp.customize)
  • Re: Desktop icon that opens My Computer folders view?
    ... My Computer with the Folders view already opened? ... I have put a 'My Computer' icon on the desktop, (from Start, My Computer, ... a 'My Computer' window opens with a Folders button ... Right click an open spot on your desktop and select New -> Shortcut from the ...
    (microsoft.public.windowsxp.newusers)