Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: shell code


Message #1 by Greg Partin <GPartin@c...> on Mon, 12 Nov 2001 14:34:03 -0500
Marco, 
I tried to adopt your code and found that it works with a little bit
different object declaration:
( setting up reference to the "Windows Script Host Object Model", as you
suggested)
***************************************************
Sub sbCreateShortCut()

 Dim MyShell As New IWshRuntimeLibrary.WshShell

    Dim sDesktop As String
    sDesktop = MyShell.SpecialFolders.Item("Desktop")
    Dim lNewShortcut As IWshRuntimeLibrary.WshShortcut
    Set lNewShortcut = MyShell.CreateShortcut(sDesktop & "\MyNewShortcut to
notepad.lnk")
    With lNewShortcut
        .TargetPath 
MyShell.ExpandEnvironmentStrings("%windir%\notepad.exe")
        .WorkingDirectory = MyShell.ExpandEnvironmentStrings("%windir%")
        .WindowStyle = 4
        .Save
    End With

End Sub
**********************************************************

	Eva

-----Original Message-----
From: Marco Straforini [mailto:marco.straforini@c...]
Sent: Monday, November 12, 2001 3:20 PM
To: professional vb
Subject: [pro_vb] RE: shell code


I prefer to add a reference to "Windows Script Host Object Model"
so I can use early binding. This works on my pc:

    Dim oShell As New IWshShell_Class
    Set oShell = New IWshShell_Class
    
    Dim sDesktop As String
    sDesktop = oShell.SpecialFolders.Item("Desktop")
    
    Dim MyShortcut As IWshShortcut_Class
    Set MyShortcut = oShell.CreateShortcut(sDesktop & "\Shortcut to
notepad.lnk")
    MyShortcut.TargetPath 
oShell.ExpandEnvironmentStrings("%windir%\notepad.exe")
    MyShortcut.WorkingDirectory 
oShell.ExpandEnvironmentStrings("%windir%")
    MyShortcut.WindowStyle = 4
    MyShortcut.Save


-----Original Message-----
From: Greg Partin [mailto:GPartin@c...]
Sent: Monday, November 12, 2001 11:34 AM
To: professional vb
Subject: [pro_vb] shell code


Hi folks,

I'm trying to create a shortcut programaticaly.  I found the following code
on Microsoft:

Set WSHShell = WScript.CreateObject("WScript.Shell")
Dim MyShortcut, MyDesktop, DesktopPath ' Read desktop path using
WshSpecialFolders object
DesktopPath = WSHShell.SpecialFolders("Desktop") ' Create a shortcut object
on the desktop
Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & _
    "\Shortcut to notepad.lnk") ' Set shortcut object properties and save it
MyShortcut.TargetPath = WSHShell.ExpandEnvironmentStrings _
    ("%windir%\notepad.exe")
MyShortcut.WorkingDirectory = WSHShell.ExpandEnvironmentStrings _
    ("%windir%")
MyShortcut.WindowStyle = 4
MyShortcut.IconLocation = WSHShell.ExpandEnvironmentStrings _
    ("%windir%\notepad.exe, 0")

This code does not work for me when running it in VB.  I'm assuming there is
a reference that I need to include or something but can't seem to find
anything on the Microsoft website or their documentation.  Could somebody
please point me in the right direction.  

Thank you and much obliged,

Greg

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.295 / Virus Database: 159 - Release Date: 11/1/2001
 



  Return to Index