This maybe the simplest way to Create Shortcut. After all, it require Win98 se or higher, beacause it use the vbscript to do the job.
Now, there is still something to explain.
The ShortCutPath must be the special folders in your system. I have tried out the follows:
"Desktop :Our Desktop
Programs :Start Menu\Programs
StartMenu :Start Menu
StartUp :Start Menu\Programs\StartUp
SendTo :Windows\SentTo
Fonts :Windows\Fonts
Favorites :Windows\Favorites"
The Window_Style is a integer,
Window_Style=3 means MaximizedWindows when run.
Window_Style=7 means MinimizedWindows when run.
Well, Others means NomalWindows when run.
Default is 0.
The IconNum set our Shortcut's icon.
0 means the first icon in the target file.
1 the sencond ...
2 the third ...
and so on.
Default is 0.
VB Code:
Option Explicit Private Sub Command1_Click() 'This will Create a ShortCut of Notepad in our desktop, its name is "Notepad", minimize windows when run, use the 2nd icon as the Shortcut icon. Create_ShortCut "C:\WINDOWS\NOTEPAD.EXE", "Desktop", "Notepad", , 7, 1 End Sub Sub Create_ShortCut(ByVal TargetPath As String, ByVal ShortCutPath As String, ByVal ShortCutname As String, Optional ByVal WorkPath As String, Optional ByVal Window_Style As Integer, Optional ByVal IconNum As Integer) Dim VbsObj As Object Set VbsObj = CreateObject("WScript.Shell") Dim MyShortcut As Object ShortCutPath = VbsObj.SpecialFolders(ShortCutPath) Set MyShortcut = VbsObj.CreateShortcut(ShortCutPath & "\" & ShortCutname & ".lnk") MyShortcut.TargetPath = TargetPath MyShortcut.WorkingDirectory = WorkPath MyShortcut.WindowStyle = Window_Style MyShortcut.IconLocation = TargetPath & "," & IconNum MyShortcut.Save End Sub





Reply With Quote