Verknüpfung erstellen PB 5.21

Für allgemeine Fragen zur Programmierung mit PureBasic.
Moxl
Beiträge: 150
Registriert: 26.10.2012 13:19

Verknüpfung erstellen PB 5.21

Beitrag von Moxl »

Hallo,

hat jemand ne Idee wie man eine einfache Dateiverknüpfung mit PB 5.21 hin kriegt?
hab schon sämtliche sufus benutzt aber kriege nur Proceduren wo mir schon fehler beim kompilieren angezeigt werden. Denke mal das meine Purebasic version zu neu ist.

Danke schonmal :allright:
Benutzeravatar
Bisonte
Beiträge: 2474
Registriert: 01.04.2007 20:18

Re: Verknüpfung erstellen PB 5.21

Beitrag von Bisonte »

Naja mit Create + Shortcut, wärste auf Danilo's Beispiel von TS-Soft gepostet gestossen....

Das Beispiel sollte so auch noch funktionieren, beachte allerdings, dass ab Windows Vista ADMINRECHTE dafür erforderlich sind.
PureBasic 6.21 (Windows x86/x64) | Windows11 Pro x64 | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | GeForce RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Re: Verknüpfung erstellen PB 5.21

Beitrag von ts-soft »

Code findet er hier: http://www.purebasic.fr/german/viewtopi ... 48#p270648
Soweit ich das sehe, ist nur eine Zeile abzuändern:

Code: Alles auswählen

If Not WorkingDir : WorkingDir = GetPathPart(Path) : EndIf
in

Code: Alles auswählen

If WorkingDir = "" : WorkingDir = GetPathPart(Path) : EndIf
Hab es aber nicht getested.
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Benutzeravatar
RSBasic
Admin
Beiträge: 8047
Registriert: 05.10.2006 18:55
Wohnort: Gernsbach
Kontaktdaten:

Re: Verknüpfung erstellen PB 5.21

Beitrag von RSBasic »

In meiner WinAPI Library gibt es unter "Dateien" auch einen Code von ts-soft zum Erstellen einer Verknüpfung.
Den Code habe ich auf die neuste Version aktualisiert und ist im nächsten Update verfügbar.

@Bisonte
Administratorrechte braucht man nicht.
Aus privaten Gründen habe ich leider nicht mehr so viel Zeit wie früher. Bitte habt Verständnis dafür.
Bild
Bild
Benutzeravatar
Bisonte
Beiträge: 2474
Registriert: 01.04.2007 20:18

Re: Verknüpfung erstellen PB 5.21

Beitrag von Bisonte »

RSBasic hat geschrieben:Administratorrechte braucht man nicht.
Wenn ich unter Win7 x64 diese Routinen ausprobierte, klappte es nie ohne Adminrechten.
Nur mit, wurde in den Systemverzeichnissen auch die Verknüpfung wirklich angelegt.
PureBasic 6.21 (Windows x86/x64) | Windows11 Pro x64 | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | GeForce RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
Moxl
Beiträge: 150
Registriert: 26.10.2012 13:19

Re: Verknüpfung erstellen PB 5.21

Beitrag von Moxl »

Also hab jetzt folgenden Code:

Code: Alles auswählen

Macro DEFINE_GUID(Name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
  CompilerIf Defined(Name, #PB_Variable)
    If SizeOf(Name) = SizeOf(GUID)
      Name\Data1    = l
      Name\Data2    = w1
      Name\Data3    = w2
      Name\Data4[0] = b1
      Name\Data4[1] = b2
      Name\Data4[2] = b3
      Name\Data4[3] = b4
      Name\Data4[4] = b5
      Name\Data4[5] = b6
      Name\Data4[6] = b7
      Name\Data4[7] = b8
    Else
      Debug "Error - variable not declared as guid"
    EndIf
  CompilerEndIf
EndMacro
Procedure CreateShortcut(Path.s, Link.s, WorkingDir.s = "", Argument.s = "", ShowCommand.l = #SW_SHOWNORMAL, Description.s =  "", HotKey.l = #Null, IconFile.s = "|", IconIndex.l = 0)
  Protected psl.IShellLinkW, ppf.IPersistFile, Result
  Protected.GUID CLSID_ShellLink, IID_IShellLink, IID_IPersistFile
 
  DEFINE_GUID(CLSID_ShellLink, $00021401, $0000,$0000, $C0, $00, $00, $00, $00, $00, $00, $46) ; {00021401-0000-0000-C000-000000000046}
  DEFINE_GUID(IID_IShellLink, $000214F9, $0000,$0000, $C0, $00, $00, $00, $00, $00, $00, $46)  ; {000214F9-0000-0000-C000-000000000046}
  DEFINE_GUID(IID_IPersistFile, $0000010B, $0000,$0000, $C0, $00, $00, $00, $00, $00, $00, $46); {0000010b-0000-0000-C000-000000000046}
 
  If IconFile = "|" : IconFile = Path : EndIf
  If WorkingDir = "" : WorkingDir = GetPathPart(Path) : EndIf

  CoInitialize_(0)
  If CoCreateInstance_(@CLSID_ShellLink, 0, 1, @IID_IShellLink, @psl) =  #S_OK

    Set_ShellLink_preferences:
    psl\SetPath(Path)
    psl\SetArguments(Argument)
    psl\SetWorkingDirectory(WorkingDir)
    psl\SetDescription(DESCRIPTION)
    psl\SetShowCmd(ShowCommand)
    psl\SetHotkey(HotKey)
    psl\SetIconLocation(IconFile, IconIndex)
    ShellLink_SAVE:
    If psl\QueryInterface(@IID_IPersistFile, @ppf) = #S_OK
      ppf\Save(Link, #True)
      result = 1
      ppf\Release()
    EndIf
    psl\Release()
  EndIf
  CoUninitialize_()
  ProcedureReturn result
EndProcedure
der einwandfrei funktioniert, ich musste

Code: Alles auswählen

If Not WorkingDir : WorkingDir = GetPathPart(Path) : EndIf
in

Code: Alles auswählen

If WorkingDir = "" : WorkingDir = GetPathPart(Path) : EndIf
ändern.
Antworten