Desktop shortcuts

BlitzPlus Forums/BlitzPlus Beginners Area/Desktop shortcuts

I am wanting to create a desktop shortcut from mu Blitz+ program - I assume that I will need to use the windows api functions, but I have no idea where to start looking.

Can anyone give me any pointers? All I need to do is create a desktop shortcut back to the program that is being executed.

Cheers,
MarkyV

I'm not quite sure what you mean by 'desktop shortcut' but have you checked out the HotKeyEvent command?

He means a windows shortcut.

I know the file extension for them is a hidden .Ink but apart from that, I don't know the insides.

Yes - sorry, I do mean windows (.lnk) shortcut - which I want to put on the desktop (is there an environment variable that contains the path to the desktop?)

Cheers,

MarkyV

Try going into Command Prompt and type 'Set'. I can't find one - The closest is the users folder.

Print "Desktop: "+GetEnv$("userprofile")
WaitKey

Here is a DLL to create shortcuts. Desktop Shortcut DLL

It is for another language, but should be easy to convert over. ;c)

I forgot to say - I found a way of doing this - alas not directly in blitz - so if anyone is interested:

I used the following line in Blitz+ (executable is called "Menu.exe"):

ExecFile(mydir$+"shortcut.vbs "+mydir$+"Menu.exe")

Then created the file "shortcut.vbs" which contained the following:

Dim ws, fso, arFldrs, Fldr, Index, Menu, Title, Usage, Src

Set ws = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

Tgt = ws.SpecialFolders("Desktop")
Src = WScript.Arguments.Item(0)
With ws.CreateShortcut(Tgt & "\" & fso.GetBaseName(Src) & ".lnk")
.TargetPath = Src
.Description = "Description of program"
.Save
End With
ws.Popup "Menu shortcut created on the desktop.", 5, Title, 64

Set ws = Nothing
Set fso = Nothing
WScript.Quit

-----------------------------

Just in case anyone was wondering :)

Cheers,

MarkyV
http://www.my3d.co.uk

Of course it wouldn't always work, since may computers have VBS scripting disabled since a large portion of VBS scripts these days do some pretty nasty stuff.

This is the proper way to do it BUT the code is in Delphi 3. If anyone has the time to make it into a DLL then away you go.

procedure ccCreateDesktopShortcut(ObjectPath, Description: String; HotKey: Word); //JB
var
  MyObject  : IUnknown;
  MySLink   : IShellLink;
  MyPFile   : IPersistFile;
  Directory : String;
  WFileName : WideString;
  MyReg     : TRegIniFile;
begin
  //Hotkey ... Best to pass an Ord('Key') and let this function apply Ctrl+Alt to it
  //Open up a COM Object to create the shell link (shortcut)
  MyObject := CreateComObject(CLSID_ShellLink);
  MySLink := MyObject as IShellLink;
  MyPFile := MyObject as IPersistFile;
  with MySLink do begin
      //SetArguments(''); //not used
    If HotKey<>0 then //don't create a blank hotkey! JB 09/10/00
      SetHotKey(HotKey+HOTKEYF_ALT*256+HOTKEYF_CONTROL*256); //*256 to get high order byte
    SetPath(PChar(ObjectPath));
    SetWorkingDirectory(PChar(ExtractFilePath(ObjectPath))); //sensible
  end;

  //Open the Registry to find out the Desktop Path
  MyReg := TRegIniFile.Create(
    'Software\MicroSoft\Windows\CurrentVersion\Explorer');

  Try
    Directory := MyReg.ReadString('Shell Folders','Desktop','');

    //Create the Link !
    WFileName := Directory + '\' + Description + '.lnk';
    MyPFile.Save(PWChar(WFileName),False);
  Finally
    MyReg.Free;
  End;
end;

/////////////////////////////
procedure ccCreateStartMenuShortcut(ObjectPath, ShortcutSubPath, Description: String); //JB
var
  MyObject  : IUnknown;
  MySLink   : IShellLink;
  MyPFile   : IPersistFile;
  Directory : String;
  WFileName : WideString;
  MyReg     : TRegIniFile;
begin
  //Specify the ShortcutSubPath like this: Program Files\My Folder

  //Open up a COM Object to create the shell link (shortcut)
  MyObject := CreateComObject(CLSID_ShellLink);
  MySLink := MyObject as IShellLink;
  MyPFile := MyObject as IPersistFile;
  with MySLink do begin
      //SetArguments(''); //not used
    SetPath(PChar(ObjectPath));
    SetWorkingDirectory(PChar(ExtractFilePath(ObjectPath))); //sensible
  end;

  //Open the Registry to find out the Start Menu Path
  MyReg := TRegIniFile.Create(
    'Software\MicroSoft\Windows\CurrentVersion\Explorer');

  Try
    //Make Start Menu sub-folder
    Directory := MyReg.ReadString('Shell Folders','Start Menu','')
      + '\' + ShortcutSubPath;
    CreateDir(Directory);

    //Create the Link !
    WFileName := Directory + '\' + Description + '.lnk';
    MyPFile.Save(PWChar(WFileName),False);
  Finally
    MyReg.Free;
  end;
end;


I created a dll using the Desktop Shortcut DLL.
Get it http://www.angelfire.com/nc3/filestorage1/Desktop.zip <-- There
You need to copy and paste it into the address bar.
CreateShortCut(Shortcut to,Shortcut name, Description)