I believe the differences in Eva's and Marco's code can be accounted for by
different versions of WSH. Marco's code looks like it was developed against
version 5.0, and Eva's appears to be using version 5.6 (in which several of
the object names are cleaned up--e.g., "WshShell" instead of
"IWshShell_Class").
Probably the best thing for you to do is to use the object browser to see
what objects are available in the IWshRuntimeLibrary library & adapt your
code appropriately.
(BTW, your original code will run in VB if you delete the ref to WScript and
add a .Save call on your shortcut object.)
HTH,
-Roy
Roy Pardee
Programmer/Analyst
SWFPAC Lockheed Martin IT
Extension 8487
-----Original Message-----
From: Teck Frankie LOH [mailto:joyful0@h...]
Sent: Wednesday, November 14, 2001 4:19 AM
To: professional vb
Subject: [pro_vb] RE: shell code: Automation Error
>
>Return-Path: <joyful0@h...>
>Received: from hotmail.com ([64.4.9.79]) by mail.p2p.wrox.com with SMTP
>(ListManager WIN32 version 4.2); Wed, 14 Nov 2001 05:13:20 -0000
>Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC;
> Tue, 13 Nov 2001 21:04:31 -0800
>Received: from 203.124.0.248 by lw9fd.law9.hotmail.msn.com with HTTP;
> Wed, 14 Nov 2001 05:04:31 GMT
>X-Originating-IP: [203.124.0.248]
>From: "Teck Frankie LOH" <joyful0@h...>
>To: pro_vb@p...
>Bcc:
>Subject: Re: [pro_vb] RE: shell code: Automation Error
>Date: Wed, 14 Nov 2001 13:04:31 +0800
>Mime-Version: 1.0
>Content-Type: text/plain; format=flowed
>Message-ID: <F79hJTANZwwPcMFlF8H0000f9a7@h...>
>X-OriginalArrivalTime: 14 Nov 2001 05:04:31.0957 (UTC)
>FILETIME=[D87FE050:01C16CC9]
>
>Hi Gurus;
>
> I tried to incorporate the suggestion in my project and when execute
>encountered the following error:
>
>Run-time error '-2147352567 (80020009)':
>automation error
>Exception occurred.
>
>I have also add the suggested window scrip host model in my preference, can
>gurus give me a pointer on error I encountered?
>
>Thanks and regards
>
>
> >From: "Zadoyen, Eva" <EZadoyen@s...>
> >Reply-To: "professional vb" <pro_vb@p...>
> >To: "professional vb" <pro_vb@p...>
> >Subject: [pro_vb] RE: shell code
> >Date: Tue, 13 Nov 2001 09:34:54 -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
> >
> >
> >
> >
> >
>
>
>_________________________________________________________________
>Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
>
>
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp