iLogic save to lnk (Shortcut)

iLogic save to lnk (Shortcut)

checkcheck_master
Advocate Advocate
596 Views
3 Replies
Message 1 of 4

iLogic save to lnk (Shortcut)

checkcheck_master
Advocate
Advocate

Hello.

Does anyone know how to save a to an lnk Shortcut in iLogic?
I try everything but without success, see code variants I have tried.
This seems to be a thing:
Imports IWshRuntimeLibrary

'Sub CreateShortCut(ByVal TargetName As String, ByVal ShortCutPath As String, ByVal ShortCutName As String) 
 
''Dim Shell As New WshShell. 
''Dim Shortcut As WshShortcut
'Dim Shell As IWshRuntimeLibrary.WshShell
'Dim Shortcut As IWshRuntimeLibrary.WshShortcut
 
'  'initialize the object WshShell 
'   Shell = New WshShell 
 
'  'initialize the object WshShortcut 
'  'the complete name of the .lnk file, include full path plus the .LNK file extension 
'   objShortcut = objShell.CreateShortcut (txtLnkName.Text) 
 
'  'the file to be called by the .lnk file, ej. "c:\windows\calc.exe" 
'  Shortcut.TargetPath = TargetName 
  
'  '(optional) := any command line supported by the file indicated in txtTarget.Text 
'  'objShortcut.Arguments = xxxx 
 
'  '(optional) : = a valid icon file : = To use the same icon of the target file, do not use the next line. 
'  'objShortcut.IconLocation = xxxx 
  
'  'Save the .lnk 
'  Shortcut.Save 
 
'End Sub

'Private Sub CreateShortCut(ByVal FileName As String, ByVal Title As String)
'    Try
'        Dim WshShell As New WshShell
'        ' short cut files have a .lnk extension
'        Dim Shortcut As IWshRuntimeLibrary.IWshShortcut = DirectCast(WshShell.CreateShortcut(FileName, IWshRuntimeLibrary.IWshShortcut)

'        ' set the shortcut properties
'        With Shortcut
'            .TargetPath = Application.ExecutablePath
'            .WindowStyle = 1I
'            .Description = Title
'            .WorkingDirectory = Application.StartupPath
'            ' the next line gets the first Icon from the executing program
'            .IconLocation = Application.ExecutablePath & ", 0"
'            .Arguments = String.Empty
'            .Save() ' save the shortcut file
'        End With
'    Catch ex As System.Exception
'        MessageBox.Show("Could not create the shortcut" & Environment.NewLine & ex.Message, g_strAppTitleVersion, MessageBoxButtons.OK, MessageBoxIcon.Error)
'    End Try
'End Sub

'Private Function CreateShortCut(ByVal TargetName As String, ByVal ShortCutPath As String, ByVal ShortCutName As String) As Boolean
'    Dim oShell As Object
'    Dim oLink As Object
'    ' You don’t need to import anything in the project reference to create the Shell Object

'    Try

'        oShell = CreateObject("WScript.Shell")
'        oLink = oShell.CreateShortcut(ShortCutPath & "\" & ShortCutName & ".lnk")

'        oLink.TargetPath = TargetName
'        oLink.WindowStyle = 1
'        oLink.Save()
'    Catch ex As Exception

'    End Try

'End Function

'Private Sub CreateShortCut(TargetPath As String, WorkingDirectory As String)
'    Dim wsh As WshShellClass = New WshShellClass()
'    Dim Shortcut As IWshRuntimeLibrary.IWshShortcut = TryCast(wsh.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\shorcut.lnk"), IWshRuntimeLibrary.IWshShortcut)
'    Shortcut.Arguments = ""
'    Shortcut.TargetPath = TargetPath '"c:\app\myftp.exe"
'    Shortcut.WindowStyle = 1
'    Shortcut.Description = "my shortcut description"
'    Shortcut.WorkingDirectory = WorkingDirectory '"c:\app"
'    Shortcut.IconLocation = "specify icon location"
'    Shortcut.Save()
'End Sub

 

0 Likes
597 Views
3 Replies
Replies (3)
Message 2 of 4

Ralf_Krieg
Advisor
Advisor

Hello

 

What are you trying to achive? Want ot create a lnk file somewhere on your computers filesystem?

Sub main
	CreateShortCut("C:\Temp\1.bmp","C:\Temp\","ShortCut to 1")
End Sub

Private Function CreateShortCut(ByVal TargetName As String, ByVal ShortCutPath As String, ByVal ShortCutName As String) As Boolean
	'TargetName		- The full path including filename and extension of the file the link points to
	'ShortCutPath	- the path where the shortcut is created in
	'ShortCutName	- the name of the shortcut file wihout file extension
	Dim oShell As Object
	Dim oLink As Object

	Try
	    oShell = CreateObject("WScript.Shell")
	    oLink = oShell.CreateShortcut(ShortCutPath & "\" & ShortCutName & ".lnk")
	
	    oLink.TargetPath = TargetName
	    oLink.WindowStyle = 1
	    oLink.Save()
	Catch ex As Exception

	End Try

End Function

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 4

checkcheck_master
Advocate
Advocate
Thank you Krieg for your response.
I'm going to try that code.

The reason, you know what I'm more or less into.
That gives an overview of Phantom, Weldments and other Parts.
An excellent structure for engineering to have an overview and to see where we stand.
Our purchasing department would like to see it subdivided into the breakdown structure that we use.
Now I create both structures, the second one by means of a copy of the jpg, pdf etc. in that second structure.
Of course you don't want two of the same files, certainly not twice an stp file.
Hence the idea to create a shortcut to easily go through the same data but in a different structure.
With the idea that if this works it could work for many overviews, for example I mention a PaintSpec overview.

Did you see my question about parts from a dictionary to an Excel BOM?
0 Likes
Message 4 of 4

checkcheck_master
Advocate
Advocate

Hi Krieg.
Finally got/had it working as I had in mind, shortcuts of eg a jpg where when you hover over it you get to see the picture.
With another nearly identical sub, it took me a while to realize that a folder needs to be created.
After I set it up for the PDF as well, apparently two identical files were created and the fun was over.
If I put it back to the way it was I don't get that shortcut with the hover function back.
Any idea how I can force that?
Could it be that I have a setting in a certain position with my messing around but I can't see it?
After a few more tries, I'm more sure, the call to the sub is in a TryCatch, which shows me that an error persists when CreateShortCut is called.
See screenshots, property of the shortcut file where Target now remains empty while it looks like the data is sufficient, see screenshot with the repeating 3 lines of data.

 

0 Likes