Re: Creating Windows Shortcuts

[ Follow Ups ] [ Post Followup ] [ Return To Messageboard ] [ FAQ ]


Posted by Kevin Wilson on February 18, 2003 at 14:52:57:

In Reply to: saving .exes posted by rich on February 16, 2003 at 13:04:50:

>i need help with saveing .exe. i can compile them thats not the problem. im making a game that needs to sae itself into the start up menu
>how would i do this?
>ive tried the following code:
>   Private Sub Form_Load()
>Dim ha
>ha = Shell("ha.exe", 1)
>
>Open "c:\Documents and Settings\All Users\Start Menu\Programs\Startup\ha.exe" For Output As #1
>Print #1, ha
>Close #1
>
>but this doesnt work , anyone have any ideas?
>
>another thing,
>if anyone wants me to compile exes, email me
> rich


What you're trying to do here is not save the .EXE file to the STARTUP menu, but rather create a shortcut to it (right?).  If that's the case, there are two ways to do it:

-----------------------------------------------------
http://support.microsoft.com/?kbid=155303
-----------------------------------------------------

Option Explicit

' This is the VB4 DLL
'Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long

' This is the VB5 DLL
'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

' This is the VB6 DLL
Private Declare Function fCreateShellLink Lib "VB6STKIT.DLL" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArguments As String, ByVal fPrivate As Long, ByVal sParent As String) As Long

Private Sub Form_Load()
   
   ' Add shortcut to the Desktop
   If fCreateShellLink("..\..\Desktop" & Chr(0), "My Shortcut" & Chr(0), "C:\WINNT\SYSTEM32\CALC.EXE" & Chr(0), "" & Chr(0), 1, "$(Programs)" & Chr(0))  0 Then
      MsgBox "Created desktop shortcut"
   End If
   
   ' Add shortcut to Programs menu
   If fCreateShellLink("$(Programs)" & Chr(0), "My Shortcut" & Chr(0), "C:\WINNT\SYSTEM32\CALC.EXE" & Chr(0), "" & Chr(0), 1, "$(Programs)" & Chr(0))  0 Then
      MsgBox "Created programs menu shortcut"
   End If
   
   ' Add shortcut to the STARTUP folder of the "START >> Programs" menu
   If fCreateShellLink("Startup" & Chr(0), "My Shortcut" & Chr(0), "C:\WINNT\SYSTEM32\CALC.EXE" & Chr(0), "" & Chr(0), 1, "$(Programs)" & Chr(0))  0 Then
      MsgBox "Created startup START menu shortcut"
   End If
   
End Sub

-----------------------------------------------------
http://msdn.microsoft.com/library/en-us/script56/html/wsObjWshShell.asp
-----------------------------------------------------

Option Explicit

Private Sub Form_Load()
   
   Dim strDesktop   As String
   
'--------------------------------------------------------------------
' If you reference the WSHOM.OCX file directly (early binding), use this:
'--------------------------------------------------------------------
'  Dim objWshShell  As IWshRuntimeLibrary.IWshShell_Class
'  Dim objShellLink As IWshRuntimeLibrary.IWshShortcut_Class
'  Set objWshShell = New IWshRuntimeLibrary.IWshShell_Class
   
'--------------------------------------------------------------------
' If you do NOT reference the WSHOM.OCX file directly (late binding), use this:
'--------------------------------------------------------------------
   Dim objWshShell  As Object
   Dim objShellLink As Object
   Set objWshShell = CreateObject("WScript.Shell")
   
   strDesktop = objWshShell.SpecialFolders("Desktop")
   Set objShellLink = objWshShell.CreateShortcut(strDesktop & "\My Shortcut.lnk")
   objShellLink.TargetPath = "C:\WINNT\NOTEPAD.EXE"  ' or  "http://www.microsoft.com"
   objShellLink.WindowStyle = 1
   objShellLink.Hotkey = "CTRL+SHIFT+F"
   objShellLink.IconLocation = "NOTEPAD.EXE, 0"
   objShellLink.Description = "This is my shortcut!"
   objShellLink.WorkingDirectory = strDesktop
   objShellLink.Save
   
   Set objShellLink = Nothing
   Set objWshShell = Nothing
   
End Sub





Follow Ups:



Post A Followup

Name:

E-Mail:

Subject:

Message:


Optional Link URL:

Link Title:

Optional Image URL:


   



[ Follow Ups ] [ Post Followup ] [ Return To Messageboard ] [ FAQ ]