Parancsikont a Programok albejegyzésébe

Parancsikont a Programok albejegyzésébe
2014-11-19T10:40:15+01:00
2014-11-19T13:57:06+01:00
2022-10-15T23:01:21+02:00
UserX
"Windows / Start-menü / Minden program / Programnév / Parancsikon" helyre szeretnék parancsikont elhelyezni, de csak a "Minden program" helyre tudok az alábbi programmal. Megvalósítható-e ez, lehetőleg rendszergazdai jogosultság nélkül?

procedure CreateShortcut(SourceFileName: string; Location: ShortcutType; SubDirectory: string); var MyObject: IUnknown; MySLink: IShellLink; MyPFile: IPersistFile; Directory, LinkName: string; WFileName: WideString; MyReg, QuickLaunchReg: TRegIniFile; begin MyObject:=CreateComObject(CLSID_ShellLink); MySLink:=MyObject as IShellLink; MyPFile:=MyObject as IPersistFile; MySLink.SetPath(PChar(SourceFileName)); MyReg:=TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\Explorer'); try LinkName:=ChangeFileExt(SourceFileName, '.lnk'); LinkName:=ExtractFileName(LinkName); case Location of _OTHERFOLDER: Directory:=SubDirectory; _DESKTOP: Directory:=MyReg.ReadString('Shell Folders', 'Desktop', ''); _STARTMENU: Directory:=MyReg.ReadString('Shell Folders', 'Start Menu', ''); _SENDTO: Directory:=MyReg.ReadString('Shell Folders', 'SendTo', ''); _QUICKLAUNCH: begin QuickLaunchReg:=TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\GrpConv'); try Directory:=QuickLaunchReg.ReadString('MapGroups', 'Quick Launch', ''); finally QuickLaunchReg.Free; end; end; end; if Directory<>'' then begin if (SubDirectory<>'') and (Location<>_OTHERFOLDER) then WFileName:=Directory+''+SubDirectory+''+LinkName else WFileName:=Directory+''+LinkName; MyPFile.Save(PWChar(WFileName), False); end; finally MyReg.Free; end; end;

Hívás:
CreateShortcut('c:\Program Files\MyProg\MyProg.exe',_STARTMENU,'Programs');
és
CreateShortcut('c:\Program Files\MyProg\MyProg.exe',_DESKTOP,'');
Mutasd a teljes hozzászólást!
1. A Windows mappa alá való íráshoz valóban rendszergazdai jogosultság kell, de szerencsére nem ott van a start menü ahová írnod kell.Kicsit javítanom kellett az eljáráson.
CreateShortcut('Myprogpath\Myprog.exe',_STARTMENU,'Programs\MyprogFolder');
paraméterekkel készít egy Myprog.lnk parancsikont a  Start-menü / Minden program / MyprogFolder  alatt.
uses comobj,activex,Registry,ShlObj; type ShortcutType = ( _OTHERFOLDER, _DESKTOP, _STARTMENU, _SENDTO, _QUICKLAUNCH); procedure CreateShortcut(SourceFileName: string; Location: ShortcutType; SubDirectory: string); var MyObject: IUnknown; MySLink: IShellLink; MyPFile: IPersistFile; Directory, LinkName: string; WFileName: WideString; MyReg, QuickLaunchReg: TRegIniFile; begin MyObject:=CreateComObject(CLSID_ShellLink); MySLink:=MyObject as IShellLink; MyPFile:=MyObject as IPersistFile; MySLink.SetPath(PChar(SourceFileName)); MyReg:=TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\Explorer'); try LinkName:=ChangeFileExt(SourceFileName, '.lnk'); LinkName:=ExtractFileName(LinkName); case Location of _OTHERFOLDER: Directory:=SubDirectory; _DESKTOP: Directory:=MyReg.ReadString('Shell Folders', 'Desktop', ''); _STARTMENU: Directory:=MyReg.ReadString('Shell Folders', 'Start Menu', ''); _SENDTO: Directory:=MyReg.ReadString('Shell Folders', 'SendTo', ''); _QUICKLAUNCH: begin QuickLaunchReg:=TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\GrpConv'); try Directory:=QuickLaunchReg.ReadString('MapGroups', 'Quick Launch', ''); finally QuickLaunchReg.Free; end; end; end; if Directory<>'' then begin if (SubDirectory<>'') and (Location<>_OTHERFOLDER) then begin if not directoryexists(Directory+'\'+SubDirectory) then mkdir(Directory+'\'+SubDirectory); WFileName:=Directory+'\'+SubDirectory+'\'+LinkName; end else begin if not directoryexists(Directory) then mkdir(Directory); WFileName:=Directory+'\'+LinkName; end; MyPFile.Save(PWChar(WFileName), False); end; finally MyReg.Free; end; end;
Mutasd a teljes hozzászólást!

Tetszett amit olvastál? Szeretnél a jövőben is értesülni a hasonló érdekességekről?
abcd