Mega Code Archive

 
Categories / Delphi / VCL
 

Create A Link (1.00)

Title: Create A Link (1.00) Question: I've needed for a while to be able to create/modify shortcuts so I sat down and with an example from delphi3000 I made a unit. Answer: First I have to thank Peter Lieber for his original artical about creating a lnk file from delphi (Artical ID: 471) Now. Where I work we have 2 class of machines, one is Server, and the other is (you guessed it) Workstation. On both these machines there is a folder on the desktop that contains every day icons used on both. The problem arose when we wanted to convert a workstation (easily) to a server or visa-versa for the useual reasons one would need to do such a thing. All the shortcuts on workstations work point to d:\etc\etc and all the shortcuts on servers point to c:\etc\etc, now anyone who has EVER had shortcuts that point to networked drives and then unplugged the cable, knows that it's hell trying to change more then one or to links. So, I wrote this unit to aid in the automation of such an act. below is a simple procedure to take a shortcut pointing from C and point it to D but don't think thats all this unit is usefull for... Uses CreateALink; ..... procedure SwapDrive(LNKFILE:String;DstDrv:Char;FixIcon:boolean); var cal: TCreateALink; tmp: String; begin cal := TCreateALink.Create; cal.openlink(LNKFile); tmp := cal.TargetName; tmp[1] := DstDrv; cal.TargetName := tmp; tmp := cal.WorkingDirName; tmp[1] := DstDrv; if FixIcon then begin //Heh, Not everyone uses the default icon (c: tmp := cal.IconPathFile; tmp[1] := DstDrv; cal.IconPathFile := tmp; end; cal.savelink; cal.free; end; Now all you need to do is download the unit (see attachment), and create a function that scans for you links and passes the full path through here (c: You could probably swap the fixicon stuff for something like if copy(cal.TargetName,Length(TargetName) - 3, 4) = 'exe' then begin tmp := cal.iconpathfile := cal.iconpathfile; tmp[1] := dstdrv; cal.iconpathfile := tmp; end; Ok, I've done the hard work for you, no go off and enjoy it. Regards Shannon