Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Maury Shortcut (Componente) - MauryShortCut.pas

MauryShortCut.pas

Caricato da: Maury91
Scarica il programma completo

  1. unit MauryShortCut;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, Classes, Registry, shlobj, ActiveX, ComObj, Windows;
  7.  
  8. type
  9.   TMauryShortCut = class(TComponent)
  10.   private
  11.     ffilename: TFileName;
  12.     { Private declarations }
  13.   protected
  14.     { Protected declarations }
  15.   public
  16.     { Public declarations }
  17.   published
  18.     { Published declarations }
  19.     property FileCollegato : TFileName read ffilename write FFilename;
  20.     function GetDesktopDirectory : String;
  21.     function GetStartMenuDirectory : String;
  22.     function GetStartupDirectory : String;
  23.     function GetProgramsDirectory : String;
  24.     procedure CreaCollegamentoA(Directory,NomeFile : string);
  25.     procedure CreaCollegamentoB(NomeFile : string);
  26.   end;
  27.  
  28. procedure Register;
  29.  
  30. implementation
  31.  
  32. procedure Register;
  33. begin
  34.   RegisterComponents('MauryTecnologies', [TMauryShortCut]);
  35. end;
  36.  
  37. { TMauryShortCut }
  38.  
  39. procedure TMauryShortCut.CreaCollegamentoA(Directory, NomeFile: string);
  40. var
  41. AnObj : IUnknown;
  42. Shlink : IShellLink;
  43. PFile : IPersistFile;
  44. WFilename : WideString;
  45. begin
  46. AnObj := CreateComObject(CLSID_ShellLink);
  47. Shlink := AnObj as IShellLink;
  48. PFile := AnObj as IPersistFile;
  49. Shlink.SetPath(PChar(FileCollegato));
  50. Shlink.SetWorkingDirectory(PChar(Directory));
  51. WFilename := ChangeFileExt(IncludeTrailingPathDelimiter(Directory)+NomeFile,'.lnk');
  52. PFile.Save(PWChar(WFilename), False);
  53. end;
  54. procedure TMauryShortCut.CreaCollegamentoB(NomeFile: string);
  55. var
  56. AnObj : IUnknown;
  57. Shlink : IShellLink;
  58. PFile : IPersistFile;
  59. WFilename : WideString;
  60. begin
  61. AnObj := CreateComObject(CLSID_ShellLink);
  62. Shlink := AnObj as IShellLink;
  63. PFile := AnObj as IPersistFile;
  64. Shlink.SetPath(PChar(FileCollegato));
  65. Shlink.SetWorkingDirectory(PChar(ExtractFilePath(NomeFile)));
  66. WFilename := ChangeFileExt(NomeFile,'.lnk');
  67. PFile.Save(PWChar(WFilename), False);
  68. end;
  69.  
  70. function TMauryShortCut.GetDesktopDirectory: String;
  71. var reg : TRegIniFile;
  72. begin
  73. reg := TRegIniFile.Create;
  74. reg.RootKey := HKEY_LOCAL_MACHINE;
  75. Result := reg.ReadString('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Common Desktop','Non esiste');
  76. if Result = 'Non esiste' then
  77. Result := reg.ReadString('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Desktop','');
  78. reg.Free;
  79. end;
  80.  
  81. function TMauryShortCut.GetProgramsDirectory: String;
  82. var reg : TRegIniFile;
  83. begin
  84. reg := TRegIniFile.Create;
  85. reg.RootKey := HKEY_LOCAL_MACHINE;
  86. Result := reg.ReadString('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Common Programs','Non esiste');
  87. if Result = 'Non esiste' then
  88. Result := reg.ReadString('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Programs','');
  89. reg.Free;
  90. end;
  91.  
  92. function TMauryShortCut.GetStartMenuDirectory: String;
  93. var reg : TRegIniFile;
  94. begin
  95. reg := TRegIniFile.Create;
  96. reg.RootKey := HKEY_LOCAL_MACHINE;
  97. Result := reg.ReadString('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Common Start Menu','Non esiste');
  98. if Result = 'Non esiste' then
  99. Result := reg.ReadString('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Start Menu','');
  100. reg.Free;
  101. end;
  102.  
  103. function TMauryShortCut.GetStartupDirectory: String;
  104. var reg : TRegIniFile;
  105. begin
  106. reg := TRegIniFile.Create;
  107. reg.RootKey := HKEY_LOCAL_MACHINE;
  108. Result := reg.ReadString('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Common Startup','Non esiste');
  109. if Result = 'Non esiste' then
  110. Result := reg.ReadString('SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Startup','');
  111. reg.Free;
  112. end;
  113.  
  114. end.