Need to change icons on 400 + shortcuts

C

cjohnsonuk

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");


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top