desktop, programs, etc. shortcut

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Iv tried the code founded on Paul's site and dosent works for XP
Then i check this code for vb

Declare Function fCreateShellLink Lib "VB5STKIT.DLL" ( _
ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, _
ByVal lpstrLinkPath As String, _
ByVal lpstrLinkArgs As String) As Long

Dim x As Long
x = fCreateShellLink("..\..\Desktop", "My Link", _
"C:\MyFolder\Program.Exe", "")

(http://spazioinwind.libero.it/vbprogzon ... ip020.html
http://spazioinwind.libero.it/vbprogzon ... ip037.html)

My code:

If OpenLibrary(0, "c:\windows\system32\vb5stkit.dll")

Result = IsFunction(0, "fCreateShellLink")

If Result
Result.l = CallFunction("c:\windows\system32\vb5stkit.dll","fCreateShellLink","..\..\Desktop","Testing","c:\windows\notepad.exe",0)

MessageRequester("",Str(Result),0)

EndIf
EndIf
CloseLibrary(0)

But its crashes always.

What im doing wrong?

This API let create shortcuts on any folder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Im lookinf for some way to create shortcuts on desktop, start menu, etc.
Is there alternative way to do it?
I repeat that tried the snipet on Paul's site but can make iy works on XP.

Thanks in advance
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Hi ricardo.

When you make a DLL call your syntax should start like this:

Code: Select all

If OpenLibrary(0,"vb5stkit.dll") 
  *call=IsFunction(0,"fCreateShellLink") 
  If *call
    Result=CallFunctionFast(*call, ... parameters) 
or this...

Code: Select all

If OpenLibrary(0,"vb6stkit.dll") 
  If IsFunction(0,"fCreateShellLink") 
    Result=CallFunction(0,"fCreateShellLink", ... parameters) 
Good luck !
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.


Thanks Paul for the advice.
However this on e dosent works even with that change.

vb5stkit.dll is a small dll (30Kbs) that let us create lnks, but im should be missing soething somewhere since i cant make it work.

Maybe its the null terminated string? VB need it and i saw in some VB6 code that they send the strings:

"..\..\Desktop" & VBNull, etc, etc...

Adding always that VBNull, im not shure if has something to do with my failure...

Any idea?

Tanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.


As i said before, VB5STKIT.DLL is a small dll, then i check and this code runs fine on my XP (not the desktop shortcut, but this one does).
There is no vbnull here, but i saw ByVal in the Lib Call.

Private Declare Function fCreateShellLink Lib "VB5STKIT.DLL" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
Private Sub Form_Load()
'Create a shell link on your start group
lngresult = fCreateShellLink("", "LINK", "C:\myfile.exe", "")
MsgBox lngresult
End Sub

If i try to do this same on PB it dosnt work, any idea how to achive it?

Code: Select all

If OpenLibrary(0,"vb5stkit.dll")  
  *call=IsFunction(0,"fCreateShellLink")  
  If *call 
   Result = CallFunction(0,"fCreateShellLink","","LINK","C:\myfile.exe","")
          MessageRequester("",Str(Result),0)  
  EndIf
EndIf
Thanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

You could try Danilo's advice and see if you can work it out using CallCOM()

It looks like you are not able to use this DLL outside of VB? I just tried VB6STKIT.DLL (since I don't have VB5STKIT.DLL and it works out of VB but nothing else)

Very strange.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.
[You could try Danilo's advice and see if you can work it out using CallCOM()
But its not a COM (i think...)
It looks like you are not able to use this DLL outside of VB? I just tried VB6STKIT.DLL (since I don't have VB5STKIT.DLL and it works out of VB but nothing else)
Very strange.
I guess the problem is with the parameters, VB6STKIT need vbnull, VB5SKIT dont (thats why im trying with this one) but i notice that if any parameter is wrong then dont do nothing... and this what happends here. As i see in some other psot (about vbnull) sometimes its not easy to send parameters to some APIs.
In this c ase i tried to add the null after the string, but dont work either.

Thanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Hi ricardo,
Sorry for not being more clear. I meant try using IShellLink (which is a COM object) for placing shortcuts on the desktop.

As for using vbnull, yes that is what I was doing since the API called for it. But like I said, it would only work for me in VB, not outside of it.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

This is my tricky code after a hard night searching how to do it :):cry::):)

Note: User must have WSH on his PC (alm ost everyone has cause it comes with windows i think)

Code: Select all


Temp$ = WindowsDirectory() + "\Temp\"

If OpenFile(0,Temp$ + "Shortcut.vbs")
  WriteStringN("'Sad example of creating a shortcut")
  WriteStringN("Dim ws")
  WriteStringN("Set ws = CreateObject(" +  Chr(34) + "WScript.Shell" +  Chr(34) + ")")
  WriteStringN("Scut = ws.SpecialFolders(" +  Chr(34) + "Desktop" +  Chr(34) + ")&" +  Chr(34) + "\MyShortCut.lnk" +  Chr(34))
  WriteStringN("With ws.CreateShortcut(Scut)")
  WriteStringN(".Hotkey = " +  Chr(34  ) + "ALT+R" +  Chr(34))
  WriteStringN(".Description = " +  Chr(34) + "really hard to make this crap!!" +  Chr(34))
  WriteStringN(".WindowStyle = 4")
  WriteStringN(".TargetPath = " +  Chr(34) + "%windir%\notepad.exe" +  Chr(34))
  WriteStringN(".IconLocation = " +  Chr(34) + "%windir%\notepad.exe, 0" +  Chr(34))
  WriteStringN(".WorkingDirectory=ws.SpecialFolders(" +  Chr(34  ) + "Desktop" +  Chr(34  ) + ")")
  WriteStringN("'.Arguments = " +  Chr(34) + "" +  Chr(34) )
  WriteStringN(".Save")
  WriteStringN("End With")
  WriteStringN("'Promise never do it againg!!")
  
  If OpenFile(1,Temp$ + "Run.Bat")
     WriteStringN("Shortcut.vbs")
     CloseFile(1)
  EndIf
  CloseFile(0)
EndIf


If RunProgram(Temp$ + "Run.Bat","",1|2)
   DeleteFile(Temp$ + "Run.Bat")
   DeleteFile(Temp$ + "Shortcut.vbs")
   ;PostMessage_(FindWindow_("ProgMan",0),$0100,$74,0)
EndIf

I know, i know, i know what are you thinking... sorry.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> This is my tricky code after a hard night searching how to do it :):cry::):)
> Note: User must have WSH on his PC

I've got a way to do it that doesn't require any libraries, DLLs, or
WSH to be installed. I'm testing it here at work on NT, but won't post
it here until I get home later (much later today) so I can test it with
98 and XP. I'm sure it will work on those, though. :)


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

IShellLink Interface?
Here you will find more...

http://msdn.microsoft.com/library/defau ... lllink.asp


If there is somebody that want to generate link files with own purebasic code take a look at:

http://www.wotsit.org

There is the 'Shortcut file format' described, and some examples in C.
Search for the LNK extension.
With this information it should be possible to create lnk file in every way you need, also for exe files...


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.
If there is somebody that want to generate link files with own purebasic code take a look at:

http://www.wotsit.org
Disassembly of a hypothetical shortcut file
http://www.wotsit.org/download.asp?f=shortcut

Code: Select all

Disassembly of a hypothetical shortcut file
Offset Bytes Contents
Header
0000 		4C 00 00 00 	‘L’ Magic value
0004 		01 04 02 00 	GUID of shortcut files
		00 00 00 00 
		C0 00 00 00 
		00 00 00 46
0014 		3F 00 00 00 	Flags
						Has item id list
						Target is a file
						Has description string
						Has relative pathname
						Has a working directory
						Has a custom icon
0018 		20 00 00 00 	File attibutes
						Archive
001C 		C0 0E 82 D5 	Time 1
		C1 20 BE 01
0024 		00 08 BF 46 	Time 2
		D5 20 BE 01
002C 		00 47 AA EC 	Time 3
		EC 15 BE 01
0034 		A0 86 00 00 	File-length 34464 bts.86A0h
0038 		05 00 00 00 	Icon number 5
003C 		01 00 00 00 	Normal window
0040 		46 06 00 00 	Ctrl-Alt-F hotkey
0044 		00 00 00 00 	Always zero,unknown/reserved
0048 		00 00 00 00       Always zero,unknown/reserved
Item Id List
004C 		2A 00 		Size of item id list
First item
004E 		28 00 		Length of first item
0050 		32 00 		???
0052 		A0 86 00 00 	File length
0056 		76 25 71 3E 	???
005A 		20 00 		File attributes?
005C 		62 65 73 74 5F 37 "best_773.mid" Long name
		37 33 2E 6D 69 64
		00 			Null terminator
0069 		42 45 53 54 5F 37 "BEST_773.MID" Short name
		37 33 2E 4D 49 44
		00 			Null terminator
Last item
0076 		00 00 		Zero length value
	
File location info
0078 		74 00 00 00 	Structure length
007C 		1C 00 00 00 	Offset past last item in structure
0080 		03 00 00 00 	Flags
						Local volume
						Network volume
0084 		1C 00 00 00 	Offset of local volume table
0088 		34 00 00 00 	Offset of local path string
008C 		40 00 00 00 	Offset of network volume table
0090 		5F 00 00 00 	Offset of final path string
Local volume table
0094 		18 00 00 00 	Length of local volume table
0098 		03 00 00 00 	Fixed disk
009C 		D0 07 33 3A 	Volume serial number 3A33-07D0
00A0 		10 00 00 00 	Offset to volume label
00A4 		44 52 49 56 45 20 "DRIVE C",0
		43 00
00AC 		43 3A 5C 57 49 4E "C:\WINDOWS\" local path string
		44 4F 57 53 5C 00
Network volume table
00B8 		1F 00 00 00 	Length of network volume table
00BC 		02 00 00 00 	???
00C0 		14 00 00 00 	Offset of share name
00C4 		00 00 00 00 	???
00C8 		00 00 02 00 	???
00CC 		5C 5C 4A 45 53 53 "\\JESSE\WD",0 Share name
		45 5C 57 44 00
00D7 		44 65 73 6B 74 6F "Desktop\best_773.mid",0
		70 5C 62 65 73 74 Final path name
		5F 37 37 33 2E 6D
		69 64 00
Description string
00EC 		12 00 		Length of string
00EE 		42 65 73 74 20 37 "Best 773 midi file"
		37 33 20 6D 69 64
		69 20 66 69 6C 65
Relative path
0100 		0E 00 		Length of string
0102 		2E 5C 62 65 73 74 ".\best_773.mid"
		5F 37 37 33 2E 6D
		69 64
Working directory
0114 		12 00 		Length of string
0116 		43 3A 5C 57 49 4E "C:\WINDOWS\Desktop"
		44 4F 57 53 5C 44
		65 73 6B 74 6F 70
Command line arguments
0128 		06 00
012A 		2F 63 6C 6F 73 65 "/close"
Icon file
0130 		16 00 		Length of string
0132 		43 3A 5C 57 49 4E "C:\WINDOWS\Mplayer.exe"
		44 4F 57 53 5C 4D
		70 6C 61 79 65 72
		2E 65 78 65
Ending stuff
0148 		00 00 00 00 	Length 0 - no more stuff
The target is located at:
C:\WINDOWS\Desktop\best_773.mid
The windows directory is shared as:
\\JESSE\WD
I hope that somebody couls help us to understand this and maybe to generate directly the lnks

Thanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> I hope that somebody couls help us to understand this and maybe to
> generate directly the lnks

My method below works perfectly, except for creating EXE shortcuts on
Windows XP due to that system purposely preventing it. But, I think
I have a workaround for that too (coming soon).

(BTW, as similar as my method looks to yours, I swear I didn't notice
the similarities until later -- I didn't steal/modify your method).

viewtopic.php?t=1932


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.
Originally posted by PB
(BTW, as similar as my method looks to yours, I swear I didn't notice
the similarities until later -- I didn't steal/modify your method).

PB - Registered PureBasic Coder
:):)

Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.
My method below works perfectly, except for creating EXE shortcuts on
Windows XP due to that system purposely preventing it. But, I think
I have a workaround for that too (coming soon).
But if we understan how to write directly the lnks we may dont need tricks that could be unestable.

I try to write every byte and i can get an lnk, we only need to know how to manage it to give the name, path, etc. og our file and we can create a lnk file by ourselves.

Im trying to make some structure to manage all the info needed to write a link, but i dont understand some points (as 64 bit integers), etc.

Download the file where i get the table provided in the last post and you will see that it seams not to be that difficult making some lnks, just need to know exactly how to make the structure (in fact seems to be 4 structures):

.LNK File Header

1 dword Always 0000004Ch ‘L’
16 bytes GUID of shortcut files 'Always {00021401-0000-0000-00C0 000000000046}
1 dword Flags
1 dword File attributes
1 qword Time 1 (64 bit integer
1 qword Time 2
1 qword Time 3
1 dword File length
1 dword Icon number
1 dword ShowWnd value
1 dword Hot key
2 dwords Unknown, always zero

File Location Info


1 dword This is the total length of this structure and all following data
1 dword This is a pointer to first offset after this structure. 1Ch
1 dword Flags
1 dword Offset of local volume info
1 dword Offset of base pathname on local system
1 dword Offset of network volume info
1 dword Offset of remaining pathname

The local volume table

1 dword Length of this structure.
1 dword Type of volume
1 dword Volume serial number
1 dword Offset of the volume name (Always 10h)
ASCIZ Volume label

The network volume table

1 dword Length of this structure
1 dword Unknown, always 2h?
1 dword Offset of network share name (Always 14h)
1 dword Unknown, always zero?
1 dword Unknown, always 20000h?
ASCIZ Network share name

complete description of every element: http://www.wotsit.org/download.asp?f=shortcut

If some one is versed with making this kind of structures, im sure that can help us to understand it.

Maybe it seems a larger code solution, but think that the result could not fail Could be cool to do it directly :)

Thanks
Post Reply