Home > Archive > Visual Basic > December 2005 > Visual Basic 6 - Run a shortcut
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Visual Basic 6 - Run a shortcut
|
|
| Tatakau 2005-12-09, 6:56 pm |
| Is there a way to run a shortcut that you know the path to?
eg., Run("c:\documents and settings\all users\start
menu\programs\accessories\notepad")
Nick
| |
| Rick Rothstein [MVP - Visual Basic] 2005-12-09, 6:56 pm |
| > Is there a way to run a shortcut that you know the path to?
>
> eg., Run("c:\documents and settings\all users\start
> menu\programs\accessories\notepad")
More than likely, VB's Shell function will do what you want.
Rick
| |
| Bob Butler 2005-12-09, 6:56 pm |
| "Tatakau" <Tatakau@discussions.microsoft.com> wrote in message
news:E6233CCE-F0F1-4A6A-A13F-C0243EF2C58A@microsoft.com
> Is there a way to run a shortcut that you know the path to?
>
> eg., Run("c:\documents and settings\all users\start
> menu\programs\accessories\notepad")
try
shell environ$("comspec") & " /c ""c:\documents and settings\all users\start
menu\programs\accessories\notepad.lnk"""
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
| |
|
| "=?Utf-8?B?VGF0YWthdQ==?=" <Tatakau@discussions.microsoft.com> wrote in
news:E6233CCE-F0F1-4A6A-A13F-C0243EF2C58A@microsoft.com:
> Is there a way to run a shortcut that you know the path to?
>
> eg., Run("c:\documents and settings\all users\start
> menu\programs\accessories\notepad")
>
> Nick
since you already know the path to it, just use the ShellExecute API.
DanS
| |
|
|
"Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net>
wrote in message news:%234ygdqN$FHA.504@TK2MSFTNGP09.phx.gbl...
>
> More than likely, VB's Shell function will do what you want.
Unfortunately it doesn't because Shell does not consider the .lnk extension
to be that of an executable file. I suppose you could modify the PATHEXT
environment variable, though.
In any case, ShellExecute works fine on shortcuts.
--
Mike
Microsoft MVP Visual Basic
| |
| Tatakau 2005-12-09, 6:56 pm |
| shellexecute sounds like it'd work, but what reference do I need to add to
get it to work? it's not defined when I try using it!
Nick
"MikeD" wrote:
>
> "Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net>
> wrote in message news:%234ygdqN$FHA.504@TK2MSFTNGP09.phx.gbl...
>
>
> Unfortunately it doesn't because Shell does not consider the .lnk extension
> to be that of an executable file. I suppose you could modify the PATHEXT
> environment variable, though.
>
> In any case, ShellExecute works fine on shortcuts.
>
> --
> Mike
> Microsoft MVP Visual Basic
>
>
>
| |
| Tatakau 2005-12-09, 6:56 pm |
| FYI - I got the shell command to technically 'work', except it messes up a
lot of permissions and such. Mainly, forms don't work right, and I can't
open mail merged documents that reference the database. If I run the
database via a shortcut though, there are no problems like this.
arguments = "c:\progra~1\mvcmar~1\bin\prototype.mdb /wrkgrp
m:\mvcmar~1\_prototype\bin\workgroup.mdw"
Shell "C:\Program Files\Microsoft Office\office12\MSACCESS.EXE " &
arguments, vbMaximizedFocus
Nick
"Tatakau" wrote:
[color=darkred]
> shellexecute sounds like it'd work, but what reference do I need to add to
> get it to work? it's not defined when I try using it!
>
> Nick
>
> "MikeD" wrote:
>
| |
|
|
| Tatakau 2005-12-09, 6:56 pm |
| I implemented the form in the website. Most controls I tested work (like
launching a browser, explorer, recycle bin, etc. But it won't open any
links... nothing happens! Which I think is a bit odd. Any idea what's going
on?
Nick
"Veign" wrote:
> ShellExecute Madness:
> http://vbnet.mvps.org/index.html?co...hellexecute.htm
>
> --
> Chris Hanscom - Microsoft MVP (VB)
> Veign's Resource Center
> http://www.veign.com/vrc_main.asp
> Veign's Blog
> http://www.veign.com/blog
> --
>
>
> "Tatakau" <Tatakau@discussions.microsoft.com> wrote in message
> news:B537B558-75D6-4621-A4E4-1B33DC80ACEC@microsoft.com...
>
>
>
| |
|
|
"Tatakau" <Tatakau@discussions.microsoft.com> wrote in message
news:46BD68B4-7D7B-4476-839B-3DEDC8437129@microsoft.com...
>I implemented the form in the website. Most controls I tested work (like
> launching a browser, explorer, recycle bin, etc. But it won't open any
> links... nothing happens! Which I think is a bit odd. Any idea what's
> going
> on?
>
You need to clarify some things. You originally asked how to run a
shortcut. You received answers on how to do that. Now, you're talking
about web sites and controls and launching the browser (and other things).
Huh? I don't know about anyone else, but I'm thoroughly .
--
Mike
Microsoft MVP Visual Basic
| |
| Randy Birch 2005-12-10, 6:55 pm |
| Because the Madness demo includes those aspects of ShellExecute, as well as
link files.
To Tatakau ... I just tried the code as posted and it works on .lnk files as
advertised. Naturally you have to change file referenced in the demo. What
error do you get (if any). To prevent errors with long filenames, have you
tried encasing the path/filename in additional quotes (Chr$(34)), e.g.
sFile = Chr$(34) & "c:\program files\my app\shortcut to my app.lnk" &
Chr$(34)
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------
"MikeD" <nobody@nowhere.edu> wrote in message
news:%23YqcMvR$FHA.3852@TK2MSFTNGP14.phx.gbl...
:
: "Tatakau" <Tatakau@discussions.microsoft.com> wrote in message
: news:46BD68B4-7D7B-4476-839B-3DEDC8437129@microsoft.com...
: >I implemented the form in the website. Most controls I tested work (like
: > launching a browser, explorer, recycle bin, etc. But it won't open any
: > links... nothing happens! Which I think is a bit odd. Any idea what's
: > going
: > on?
: >
:
:
: You need to clarify some things. You originally asked how to run a
: shortcut. You received answers on how to do that. Now, you're talking
: about web sites and controls and launching the browser (and other things).
: Huh? I don't know about anyone else, but I'm thoroughly .
:
: --
: Mike
: Microsoft MVP Visual Basic
:
:
| |
| Tatakau 2005-12-12, 6:56 pm |
| Well, after a complete uninstall and full reinstall, opening the links with
ShellExecute is working. No idea why it didn't work before... but well, it's
working now. The program does what it should, for the most part. I have
another issue though that would probably be better suited for a separate
thread...
The program runs fine on a computer with Windows XP and framework 1.1
installed. However, I tried running it on a Windows 98 computer with no
framework and it didn't work. So then I downloaded framework 2.0 and
installed it on the Windows 98 computers and the program still didn't work.
The Windows 98 maching is capable of running VB6 applications (a blank form
program worked flawlessly :-D ) but it looks like it's having problems with
either accessing a database and/or the ShellExecute command. I tried copying
all referenced files into the Windows directories, but that still didn't fix
it. Is there something I could install on the Win98 computers to get them to
run my program?
I really appreciate everything you guys have done for me. Thanks again for
all your help!
Nick
"Randy Birch" wrote:
> Because the Madness demo includes those aspects of ShellExecute, as well as
> link files.
>
> To Tatakau ... I just tried the code as posted and it works on .lnk files as
> advertised. Naturally you have to change file referenced in the demo. What
> error do you get (if any). To prevent errors with long filenames, have you
> tried encasing the path/filename in additional quotes (Chr$(34)), e.g.
>
> sFile = Chr$(34) & "c:\program files\my app\shortcut to my app.lnk" &
> Chr$(34)
>
>
> --
>
> Randy Birch
> MS MVP Visual Basic
> http://vbnet.mvps.org/
> ----------------------------------------------------------------------------
> Read. Decide. Sign the petition to Microsoft.
> http://classicvb.org/petition/
> ----------------------------------------------------------------------------
>
>
>
> "MikeD" <nobody@nowhere.edu> wrote in message
> news:%23YqcMvR$FHA.3852@TK2MSFTNGP14.phx.gbl...
> :
> : "Tatakau" <Tatakau@discussions.microsoft.com> wrote in message
> : news:46BD68B4-7D7B-4476-839B-3DEDC8437129@microsoft.com...
> : >I implemented the form in the website. Most controls I tested work (like
> : > launching a browser, explorer, recycle bin, etc. But it won't open any
> : > links... nothing happens! Which I think is a bit odd. Any idea what's
> : > going
> : > on?
> : >
> :
> :
> : You need to clarify some things. You originally asked how to run a
> : shortcut. You received answers on how to do that. Now, you're talking
> : about web sites and controls and launching the browser (and other things).
> : Huh? I don't know about anyone else, but I'm thoroughly .
> :
> : --
> : Mike
> : Microsoft MVP Visual Basic
> :
> :
>
>
| |
| Randy Birch 2005-12-12, 6:56 pm |
| If you're using VB6, the version of the framework installed is moot as
classic VB doesn't give a rat's a** about it. And if you're using vb.net,
you've posted to the wrong newsgroup -- net questions go to the dotnet and
vsnet newsgroups.
As for 98 -- there's nothing that should prevent working ShellExecute code
from performing the required function on 98. If the VB runtime files are
installed on the 98 box, and you have only a form with a command button to
test the ShellExecute call (to a legitimate shortcut, of course), you should
get the expected results. If the app you're porting has other controls on
it, you can't just copy the dependencies to the other machine as they have
to be properly installed and registers, part of the install process
developed through the app deployment wizard under VB6 addins.
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------
"Tatakau" <Tatakau@discussions.microsoft.com> wrote in message
news:9671B40A-98A3-4F51-AF2F-E350D3A7F64C@microsoft.com...
: Well, after a complete uninstall and full reinstall, opening the links
with
: ShellExecute is working. No idea why it didn't work before... but well,
it's
: working now. The program does what it should, for the most part. I have
: another issue though that would probably be better suited for a separate
: thread...
:
: The program runs fine on a computer with Windows XP and framework 1.1
: installed. However, I tried running it on a Windows 98 computer with no
: framework and it didn't work. So then I downloaded framework 2.0 and
: installed it on the Windows 98 computers and the program still didn't
work.
:
: The Windows 98 maching is capable of running VB6 applications (a blank
form
: program worked flawlessly :-D ) but it looks like it's having problems
with
: either accessing a database and/or the ShellExecute command. I tried
copying
: all referenced files into the Windows directories, but that still didn't
fix
: it. Is there something I could install on the Win98 computers to get them
to
: run my program?
:
: I really appreciate everything you guys have done for me. Thanks again
for
: all your help!
:
: Nick
:
:
: "Randy Birch" wrote:
:
: > Because the Madness demo includes those aspects of ShellExecute, as well
as
: > link files.
: >
: > To Tatakau ... I just tried the code as posted and it works on .lnk
files as
: > advertised. Naturally you have to change file referenced in the demo.
What
: > error do you get (if any). To prevent errors with long filenames, have
you
: > tried encasing the path/filename in additional quotes (Chr$(34)), e.g.
: >
: > sFile = Chr$(34) & "c:\program files\my app\shortcut to my app.lnk" &
: > Chr$(34)
: >
: >
: > --
: >
: > Randy Birch
: > MS MVP Visual Basic
: > http://vbnet.mvps.org/
:
> ----------------------------------------------------------------------------
: > Read. Decide. Sign the petition to Microsoft.
: > http://classicvb.org/petition/
:
> ----------------------------------------------------------------------------
: >
: >
: >
: > "MikeD" <nobody@nowhere.edu> wrote in message
: > news:%23YqcMvR$FHA.3852@TK2MSFTNGP14.phx.gbl...
: > :
: > : "Tatakau" <Tatakau@discussions.microsoft.com> wrote in message
: > : news:46BD68B4-7D7B-4476-839B-3DEDC8437129@microsoft.com...
: > : >I implemented the form in the website. Most controls I tested work
(like
: > : > launching a browser, explorer, recycle bin, etc. But it won't open
any
: > : > links... nothing happens! Which I think is a bit odd. Any idea
what's
: > : > going
: > : > on?
: > : >
: > :
: > :
: > : You need to clarify some things. You originally asked how to run a
: > : shortcut. You received answers on how to do that. Now, you're
talking
: > : about web sites and controls and launching the browser (and other
things).
: > : Huh? I don't know about anyone else, but I'm thoroughly .
: > :
: > : --
: > : Mike
: > : Microsoft MVP Visual Basic
: > :
: > :
: >
: >
| |
|
|
"Tatakau" <Tatakau@discussions.microsoft.com> wrote in message
news:9671B40A-98A3-4F51-AF2F-E350D3A7F64C@microsoft.com...
> The program runs fine on a computer with Windows XP and framework 1.1
> installed. However, I tried running it on a Windows 98 computer with no
> framework and it didn't work. So then I downloaded framework 2.0 and
> installed it on the Windows 98 computers and the program still didn't
> work.
>
> The Windows 98 maching is capable of running VB6 applications (a blank
> form
> program worked flawlessly :-D ) but it looks like it's having problems
> with
> either accessing a database and/or the ShellExecute command. I tried
> copying
> all referenced files into the Windows directories, but that still didn't
> fix
> it. Is there something I could install on the Win98 computers to get them
> to
> run my program?
>
> I really appreciate everything you guys have done for me. Thanks again
> for
> all your help!
Framework? You talking about the .NET Framework? That has nothing to do
with a VB6 app.
Most likely you're missing some dependency file and/or it's not registered.
You can't simply copy files to the System folder. This is extremely
dangerous (especially since you're using files from a WinXP box). You need
to create an installation program and properly install your app. You also
mentioned accessing a database. What data access library are you using, DAO
or ADO? I believe Win98 includes DAO 3.5/Jet 3.5, but I don't think it
includes DAO 3.6/Jet 4.0 or any version of ADO. These will need installed
too.
--
Mike
Microsoft MVP Visual Basic
| |
| Tatakau 2005-12-13, 6:56 pm |
| Hmm.... I think you're probably right about missing dependancies. I already
copied the files to the c:\windows directory, but I'll give copying them to
the c:\windows\system directory a shot. They're both included in the Path on
startup though, so I don't know if it'll make too much of a difference.
As far as what's in this thing, I 'think' it's ADO, though I really don't
know much about coding VB6 (I'm developing on an XP Pro box, with Visual
Studio 6 Pro). I've done my share with VBA in Access, but this is quite
different.
My not-so-elegant code (see the shortcuts section) for the app thus far,
rather jury-rigged I think:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~
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
Sub Main()
On Error GoTo EH
Dim objConn As New ADODB.Connection
Dim objRs As New ADODB.Recordset
Dim arguments As String
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' CONNECT TO DATABASE AND FIND VERSION NUMBERS
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ConnectionString = "Provider=Microsoft Jet 4.0 OLE DB Provider;Data
Source=C:\Program Files\MVC Marketing\bin\prototype.mdb;Jet OLEDB:System
database=M:\MVC Marketing\_prototype\bin\workgroup.mdw;User
ID=mvcinfo;Password=mvcinfo;"
objConn.Open ConnectionString
CommandText = "SELECT [version] FROM [_local] WHERE [index]=1"
Set objRs = objConn.Execute(CommandText)
verlocal = objRs(0)
CommandText = "SELECT [version] FROM [_settings] WHERE [index]=1"
Set objRs = objConn.Execute(CommandText)
vernetwork = objRs(0)
objRs.Close
objConn.Close
Set objRs = Nothing
Set objConn = Nothing
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' COMPARE VERSION NUMBERS AND COPY NEW FILE IF NECESSARY
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If vernetwork > verlocal Then
MsgBox "A new verion of the database is available on the network! It
will be downloaded automatcially.", vbInformation, "New Version"
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("C:\Program Files\MVC Marketing\bin\prototype.mdb")
Then
Kill "C:\Program Files\MVC Marketing\bin\prototype.mdb"
End If
FileCopy "M:\MVC Marketing\_prototype\bin\prototype.mdb",
"C:\Program Files\MVC Marketing\bin\prototype.mdb"
End If
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' RUN THE CORRECT SHORTCUT, DEPENDING ON OFFICE VERSION
' SHORTCUT = "c:\program files\microsoft office\office\msaccess.exe"
"c:\program files\mvc marketing\bin\prototype.mdb" /wrkgrp "m:\mvc
marketing\_prototype\bin\workgroup.mdw", PATH = "c:\program files\microsoft
office\office"
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("C:\Program Files\Microsoft
Office\Office13\msaccess.exe") Then
Shell Environ$("comspec") & " /c ""c:\program files\mvc
marketing\links\office13 - mvc marketing.lnk"""
Else
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("C:\Program Files\Microsoft
Office\Office12\msaccess.exe") Then
Shell Environ$("comspec") & " /c ""c:\program files\mvc
marketing\links\office12 - mvc marketing.lnk"""
Else
If fs.FileExists("C:\Program Files\Microsoft
Office\Office11\msaccess.exe") Then
Shell Environ$("comspec") & " /c ""c:\program files\mvc
marketing\links\office11 - mvc marketing.lnk"""
Else
If fs.FileExists("C:\Program Files\Microsoft
Office\Office10\msaccess.exe") Then
Shell Environ$("comspec") & " /c ""c:\program files\mvc
marketing\links\office10 - mvc marketing.lnk"""
Else
If fs.FileExists("C:\Program Files\Microsoft
Office\Office\msaccess.exe") Then
Shell Environ$("comspec") & " /c ""c:\program
files\mvc marketing\links\office - mvc marketing.lnk"""
Else
MsgBox "Microsoft Office was not detected on this
computer! Please verify installation or reinstall to default directories.",
vbCritical, "Microsoft Office not found!"
End If
End If
End If
End If
End If
Exit Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ERROR HANDLING
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EH:
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("M:\MVC Marketing\MVC Marketing Installer.exe") = False
Then
arguments = "Please check network connections and drive mappings."
Else
arguments = "Files may be missing or corrupt. Please re-install
application."
End If
MsgBox "Error launching MVC Marketing database. " & arguments,
vbCritical, "Error"
Exit Sub
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~
| |
| Tatakau 2005-12-13, 6:56 pm |
| I added debugging messageboxes to the code, and it looks like everything is
working fine except for ShellExecute, which it seems to pass over like it
isn't even there. I tried copying the associated library (STKIT432.DLL) to
the Win98 box, but that doesn't seem to make a difference, whether copied to
the c:\windows, c:\windows\system, c:\windows\system32, or the program
directory itself (c:\program files\mvc marketing\bin). Hell, I even copied
it to the base directory (c:\)!
Maybe installing Visual Studio onto the Win98 boxes would solve the
problem... except I only have one license to the program, and it's mine, not
the company's, and I really don't want to do that... any suggestions?
Thanks!
Nick
"Tatakau" wrote:
> Hmm.... I think you're probably right about missing dependancies. I already
> copied the files to the c:\windows directory, but I'll give copying them to
> the c:\windows\system directory a shot. They're both included in the Path on
> startup though, so I don't know if it'll make too much of a difference.
>
> As far as what's in this thing, I 'think' it's ADO, though I really don't
> know much about coding VB6 (I'm developing on an XP Pro box, with Visual
> Studio 6 Pro). I've done my share with VBA in Access, but this is quite
> different.
>
> My not-so-elegant code (see the shortcuts section) for the app thus far,
> rather jury-rigged I think:
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~
> 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
>
> Sub Main()
> On Error GoTo EH
> Dim objConn As New ADODB.Connection
> Dim objRs As New ADODB.Recordset
> Dim arguments As String
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ' CONNECT TO DATABASE AND FIND VERSION NUMBERS
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ConnectionString = "Provider=Microsoft Jet 4.0 OLE DB Provider;Data
> Source=C:\Program Files\MVC Marketing\bin\prototype.mdb;Jet OLEDB:System
> database=M:\MVC Marketing\_prototype\bin\workgroup.mdw;User
> ID=mvcinfo;Password=mvcinfo;"
> objConn.Open ConnectionString
> CommandText = "SELECT [version] FROM [_local] WHERE [index]=1"
> Set objRs = objConn.Execute(CommandText)
> verlocal = objRs(0)
> CommandText = "SELECT [version] FROM [_settings] WHERE [index]=1"
> Set objRs = objConn.Execute(CommandText)
> vernetwork = objRs(0)
> objRs.Close
> objConn.Close
> Set objRs = Nothing
> Set objConn = Nothing
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ' COMPARE VERSION NUMBERS AND COPY NEW FILE IF NECESSARY
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> If vernetwork > verlocal Then
> MsgBox "A new verion of the database is available on the network! It
> will be downloaded automatcially.", vbInformation, "New Version"
> Set fs = CreateObject("Scripting.FileSystemObject")
> If fs.FileExists("C:\Program Files\MVC Marketing\bin\prototype.mdb")
> Then
> Kill "C:\Program Files\MVC Marketing\bin\prototype.mdb"
> End If
> FileCopy "M:\MVC Marketing\_prototype\bin\prototype.mdb",
> "C:\Program Files\MVC Marketing\bin\prototype.mdb"
> End If
>
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ' RUN THE CORRECT SHORTCUT, DEPENDING ON OFFICE VERSION
> ' SHORTCUT = "c:\program files\microsoft office\office\msaccess.exe"
> "c:\program files\mvc marketing\bin\prototype.mdb" /wrkgrp "m:\mvc
> marketing\_prototype\bin\workgroup.mdw", PATH = "c:\program files\microsoft
> office\office"
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Set fs = CreateObject("Scripting.FileSystemObject")
> If fs.FileExists("C:\Program Files\Microsoft
> Office\Office13\msaccess.exe") Then
> Shell Environ$("comspec") & " /c ""c:\program files\mvc
> marketing\links\office13 - mvc marketing.lnk"""
> Else
> Set fs = CreateObject("Scripting.FileSystemObject")
> If fs.FileExists("C:\Program Files\Microsoft
> Office\Office12\msaccess.exe") Then
> Shell Environ$("comspec") & " /c ""c:\program files\mvc
> marketing\links\office12 - mvc marketing.lnk"""
> Else
> If fs.FileExists("C:\Program Files\Microsoft
> Office\Office11\msaccess.exe") Then
> Shell Environ$("comspec") & " /c ""c:\program files\mvc
> marketing\links\office11 - mvc marketing.lnk"""
> Else
> If fs.FileExists("C:\Program Files\Microsoft
> Office\Office10\msaccess.exe") Then
> Shell Environ$("comspec") & " /c ""c:\program files\mvc
> marketing\links\office10 - mvc marketing.lnk"""
> Else
> If fs.FileExists("C:\Program Files\Microsoft
> Office\Office\msaccess.exe") Then
> Shell Environ$("comspec") & " /c ""c:\program
> files\mvc marketing\links\office - mvc marketing.lnk"""
> Else
> MsgBox "Microsoft Office was not detected on this
> computer! Please verify installation or reinstall to default directories.",
> vbCritical, "Microsoft Office not found!"
> End If
> End If
> End If
> End If
> End If
> Exit Sub
>
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ' ERROR HANDLING
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> EH:
> Set fs = CreateObject("Scripting.FileSystemObject")
> If fs.FileExists("M:\MVC Marketing\MVC Marketing Installer.exe") = False
> Then
> arguments = "Please check network connections and drive mappings."
> Else
> arguments = "Files may be missing or corrupt. Please re-install
> application."
> End If
> MsgBox "Error launching MVC Marketing database. " & arguments,
> vbCritical, "Error"
> Exit Sub
> End Sub
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~
| |
| Randy Birch 2005-12-13, 9:55 pm |
| Oh where to begin?
First, I would not delete the local copy of the mdb before you've copied it
over to the local system and verified it's success. What if a glitch in the
network prevented access or interrupted the filecopy? Copy it to the user's
local temp folder (GetTempPath API), verify its size, then nuke the local
copy and filecopy the new version to the user's working folder.
The multiple if tests for access versions are not required. Whether access
is installed is a straightforward check ... you can use FindExecutable
(testing for the association for .mdb files), or hit the registry directly
under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Wi
ndows\CurrentVersion\App
Paths. What if the user decided they wanted a different foldername for the
Office files? Or it was located on a drive other than C:?
Why (and where) are you attempting to execute the lnk file? Is it because
you have parameters to pass (ie the workgroup) that are already in the lnk
file?
ShellExecute (which is what I thought this discussion was about) is part of
the OS - it is present on all windows systems since Win95. As for copying
your app's dependency files --- as I said before, unless it is a bare-bones
command-button-and-text-box-app, you HAVE to "install" the application using
the package and deployment wizard or some other comparable setup tool.
Simply copying over files you identify as dependencies does nothing, as
dependencies have dependencies themselves that you don't see but the setup
tool does, plus all the COM-based dependencies must be registered on the
system after identifying whether a more recent version already exists.
Again, this is what the setup tools do for you.
In pseudo-code it appears this part of your app is as simple as:
- get local access path
- confirm local msaccess.exe and work mdb exist
- check for new version of mdb
- if new version available
- get temp directory
- copy mdb to temp folder
- verify copy
- retry if failed
- kill local mdb
- copy temp mdb to local mdb
- verify file copy
- kill temp mdb
- shell or shellexecute to mdb
Based on the command line in your sample code, and the shellexecute demo I
gave you, drop this into the "case 17" position in the command1_click event
(this is the button on the form at the bottom of the first column that I had
forgot to code, that reads "Option1" in the demo):
Case 17:
sFile = "c:\program files\mvc marketing\bin\prototype.mdb"
sParams = "/wrkgrp m:\mvc
marketing\_prototype\bin\workgroup.mdw"
Using this same format here on a local database ShellExecute opened the file
without a problem.
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------
"Tatakau" <Tatakau@discussions.microsoft.com> wrote in message
news:E6D5A14F-332C-4079-9D3C-B679C4DE2B54@microsoft.com...
: Hmm.... I think you're probably right about missing dependancies. I
already
: copied the files to the c:\windows directory, but I'll give copying them
to
: the c:\windows\system directory a shot. They're both included in the Path
on
: startup though, so I don't know if it'll make too much of a difference.
:
: As far as what's in this thing, I 'think' it's ADO, though I really don't
: know much about coding VB6 (I'm developing on an XP Pro box, with Visual
: Studio 6 Pro). I've done my share with VBA in Access, but this is quite
: different.
:
: My not-so-elegant code (see the shortcuts section) for the app thus far,
: rather jury-rigged I think:
:
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~
: 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
:
: Sub Main()
: On Error GoTo EH
: Dim objConn As New ADODB.Connection
: Dim objRs As New ADODB.Recordset
: Dim arguments As String
: '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: ' CONNECT TO DATABASE AND FIND VERSION NUMBERS
: '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: ConnectionString = "Provider=Microsoft Jet 4.0 OLE DB Provider;Data
: Source=C:\Program Files\MVC Marketing\bin\prototype.mdb;Jet OLEDB:System
: database=M:\MVC Marketing\_prototype\bin\workgroup.mdw;User
: ID=mvcinfo;Password=mvcinfo;"
: objConn.Open ConnectionString
: CommandText = "SELECT [version] FROM [_local] WHERE [index]=1"
: Set objRs = objConn.Execute(CommandText)
: verlocal = objRs(0)
: CommandText = "SELECT [version] FROM [_settings] WHERE [index]=1"
: Set objRs = objConn.Execute(CommandText)
: vernetwork = objRs(0)
: objRs.Close
: objConn.Close
: Set objRs = Nothing
: Set objConn = Nothing
: '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: ' COMPARE VERSION NUMBERS AND COPY NEW FILE IF NECESSARY
: '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: If vernetwork > verlocal Then
: MsgBox "A new verion of the database is available on the network!
It
: will be downloaded automatcially.", vbInformation, "New Version"
: Set fs = CreateObject("Scripting.FileSystemObject")
: If fs.FileExists("C:\Program Files\MVC
Marketing\bin\prototype.mdb")
: Then
: Kill "C:\Program Files\MVC Marketing\bin\prototype.mdb"
: End If
: FileCopy "M:\MVC Marketing\_prototype\bin\prototype.mdb",
: "C:\Program Files\MVC Marketing\bin\prototype.mdb"
: End If
:
: '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: ' RUN THE CORRECT SHORTCUT, DEPENDING ON OFFICE VERSION
: ' SHORTCUT = "c:\program files\microsoft office\office\msaccess.exe"
: "c:\program files\mvc marketing\bin\prototype.mdb" /wrkgrp "m:\mvc
: marketing\_prototype\bin\workgroup.mdw", PATH = "c:\program
files\microsoft
: office\office"
: '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: Set fs = CreateObject("Scripting.FileSystemObject")
: If fs.FileExists("C:\Program Files\Microsoft
: Office\Office13\msaccess.exe") Then
: Shell Environ$("comspec") & " /c ""c:\program files\mvc
: marketing\links\office13 - mvc marketing.lnk"""
: Else
: Set fs = CreateObject("Scripting.FileSystemObject")
: If fs.FileExists("C:\Program Files\Microsoft
: Office\Office12\msaccess.exe") Then
: Shell Environ$("comspec") & " /c ""c:\program files\mvc
: marketing\links\office12 - mvc marketing.lnk"""
: Else
: If fs.FileExists("C:\Program Files\Microsoft
: Office\Office11\msaccess.exe") Then
: Shell Environ$("comspec") & " /c ""c:\program files\mvc
: marketing\links\office11 - mvc marketing.lnk"""
: Else
: If fs.FileExists("C:\Program Files\Microsoft
: Office\Office10\msaccess.exe") Then
: Shell Environ$("comspec") & " /c ""c:\program files\mvc
: marketing\links\office10 - mvc marketing.lnk"""
: Else
: If fs.FileExists("C:\Program Files\Microsoft
: Office\Office\msaccess.exe") Then
: Shell Environ$("comspec") & " /c ""c:\program
: files\mvc marketing\links\office - mvc marketing.lnk"""
: Else
: MsgBox "Microsoft Office was not detected on this
: computer! Please verify installation or reinstall to default
directories.",
: vbCritical, "Microsoft Office not found!"
: End If
: End If
: End If
: End If
: End If
: Exit Sub
:
: '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: ' ERROR HANDLING
: '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: EH:
: Set fs = CreateObject("Scripting.FileSystemObject")
: If fs.FileExists("M:\MVC Marketing\MVC Marketing Installer.exe") =
False
: Then
: arguments = "Please check network connections and drive mappings."
: Else
: arguments = "Files may be missing or corrupt. Please re-install
: application."
: End If
: MsgBox "Error launching MVC Marketing database. " & arguments,
: vbCritical, "Error"
: Exit Sub
: End Sub
:
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~
| |
| Tatakau 2005-12-15, 6:55 pm |
| Hey Randy!
Unfortunately, the bit of code you suggested works only to an extent. When
I ran your "Case 17" code snippet, it did manage to open the database.
However, it did not open it with full permissions. The database that is
opened is only the front-end, and when it is opened with ShellExecute, I do
not have permissions to access the back-end. Sorta odd. Even when I add
/user and /pwd arguments. When it is run from a shortcut though, it works
fine. I really don't know why.
You'd think that Microsoft would have better planned this kinda
functionality between it's own products...
Nick
"Randy Birch" wrote:
> Oh where to begin?
>
> First, I would not delete the local copy of the mdb before you've copied it
> over to the local system and verified it's success. What if a glitch in the
> network prevented access or interrupted the filecopy? Copy it to the user's
> local temp folder (GetTempPath API), verify its size, then nuke the local
> copy and filecopy the new version to the user's working folder.
>
> The multiple if tests for access versions are not required. Whether access
> is installed is a straightforward check ... you can use FindExecutable
> (testing for the association for .mdb files), or hit the registry directly
> under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Wi
ndows\CurrentVersion\App
> Paths. What if the user decided they wanted a different foldername for the
> Office files? Or it was located on a drive other than C:?
>
> Why (and where) are you attempting to execute the lnk file? Is it because
> you have parameters to pass (ie the workgroup) that are already in the lnk
> file?
>
> ShellExecute (which is what I thought this discussion was about) is part of
> the OS - it is present on all windows systems since Win95. As for copying
> your app's dependency files --- as I said before, unless it is a bare-bones
> command-button-and-text-box-app, you HAVE to "install" the application using
> the package and deployment wizard or some other comparable setup tool.
> Simply copying over files you identify as dependencies does nothing, as
> dependencies have dependencies themselves that you don't see but the setup
> tool does, plus all the COM-based dependencies must be registered on the
> system after identifying whether a more recent version already exists.
> Again, this is what the setup tools do for you.
>
> In pseudo-code it appears this part of your app is as simple as:
>
> - get local access path
> - confirm local msaccess.exe and work mdb exist
> - check for new version of mdb
> - if new version available
> - get temp directory
> - copy mdb to temp folder
> - verify copy
> - retry if failed
> - kill local mdb
> - copy temp mdb to local mdb
> - verify file copy
> - kill temp mdb
> - shell or shellexecute to mdb
>
>
> Based on the command line in your sample code, and the shellexecute demo I
> gave you, drop this into the "case 17" position in the command1_click event
> (this is the button on the form at the bottom of the first column that I had
> forgot to code, that reads "Option1" in the demo):
>
> Case 17:
> sFile = "c:\program files\mvc marketing\bin\prototype.mdb"
> sParams = "/wrkgrp m:\mvc
> marketing\_prototype\bin\workgroup.mdw"
>
>
> Using this same format here on a local database ShellExecute opened the file
> without a problem.
>
>
> --
>
>
> Randy Birch
> MS MVP Visual Basic
> http://vbnet.mvps.org/
> ----------------------------------------------------------------------------
> Read. Decide. Sign the petition to Microsoft.
> http://classicvb.org/petition/
> ----------------------------------------------------------------------------
>
>
>
> "Tatakau" <Tatakau@discussions.microsoft.com> wrote in message
> news:E6D5A14F-332C-4079-9D3C-B679C4DE2B54@microsoft.com...
> : Hmm.... I think you're probably right about missing dependancies. I
> already
> : copied the files to the c:\windows directory, but I'll give copying them
> to
> : the c:\windows\system directory a shot. They're both included in the Path
> on
> : startup though, so I don't know if it'll make too much of a difference.
> :
> : As far as what's in this thing, I 'think' it's ADO, though I really don't
> : know much about coding VB6 (I'm developing on an XP Pro box, with Visual
> : Studio 6 Pro). I've done my share with VBA in Access, but this is quite
> : different.
> :
> : My not-so-elegant code (see the shortcuts section) for the app thus far,
> : rather jury-rigged I think:
> :
> : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~
> : 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
> :
> : Sub Main()
> : On Error GoTo EH
> : Dim objConn As New ADODB.Connection
> : Dim objRs As New ADODB.Recordset
> : Dim arguments As String
> : '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : ' CONNECT TO DATABASE AND FIND VERSION NUMBERS
> : '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : ConnectionString = "Provider=Microsoft Jet 4.0 OLE DB Provider;Data
> : Source=C:\Program Files\MVC Marketing\bin\prototype.mdb;Jet OLEDB:System
> : database=M:\MVC Marketing\_prototype\bin\workgroup.mdw;User
> : ID=mvcinfo;Password=mvcinfo;"
> : objConn.Open ConnectionString
> : CommandText = "SELECT [version] FROM [_local] WHERE [index]=1"
> : Set objRs = objConn.Execute(CommandText)
> : verlocal = objRs(0)
> : CommandText = "SELECT [version] FROM [_settings] WHERE [index]=1"
> : Set objRs = objConn.Execute(CommandText)
> : vernetwork = objRs(0)
> : objRs.Close
> : objConn.Close
> : Set objRs = Nothing
> : Set objConn = Nothing
> : '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : ' COMPARE VERSION NUMBERS AND COPY NEW FILE IF NECESSARY
> : '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : If vernetwork > verlocal Then
> : MsgBox "A new verion of the database is available on the network!
> It
> : will be downloaded automatcially.", vbInformation, "New Version"
> : Set fs = CreateObject("Scripting.FileSystemObject")
> : If fs.FileExists("C:\Program Files\MVC
> Marketing\bin\prototype.mdb")
> : Then
> : Kill "C:\Program Files\MVC Marketing\bin\prototype.mdb"
> : End If
> : FileCopy "M:\MVC Marketing\_prototype\bin\prototype.mdb",
> : "C:\Program Files\MVC Marketing\bin\prototype.mdb"
> : End If
> :
> : '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : ' RUN THE CORRECT SHORTCUT, DEPENDING ON OFFICE VERSION
> : ' SHORTCUT = "c:\program files\microsoft office\office\msaccess.exe"
> : "c:\program files\mvc marketing\bin\prototype.mdb" /wrkgrp "m:\mvc
> : marketing\_prototype\bin\workgroup.mdw", PATH = "c:\program
> files\microsoft
> : office\office"
> : '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : Set fs = CreateObject("Scripting.FileSystemObject")
> : If fs.FileExists("C:\Program Files\Microsoft
> : Office\Office13\msaccess.exe") Then
> : Shell Environ$("comspec") & " /c ""c:\program files\mvc
> : marketing\links\office13 - mvc marketing.lnk"""
> : Else
> : Set fs = CreateObject("Scripting.FileSystemObject")
> : If fs.FileExists("C:\Program Files\Microsoft
> : Office\Office12\msaccess.exe") Then
> : Shell Environ$("comspec") & " /c ""c:\program files\mvc
> : marketing\links\office12 - mvc marketing.lnk"""
> : Else
> : If fs.FileExists("C:\Program Files\Microsoft
> : Office\Office11\msaccess.exe") Then
> : Shell Environ$("comspec") & " /c ""c:\program files\mvc
> : marketing\links\office11 - mvc marketing.lnk"""
> : Else
> : If fs.FileExists("C:\Program Files\Microsoft
> : Office\Office10\msaccess.exe") Then
> : Shell Environ$("comspec") & " /c ""c:\program files\mvc
> : marketing\links\office10 - mvc marketing.lnk"""
> : Else
> : If fs.FileExists("C:\Program Files\Microsoft
> : Office\Office\msaccess.exe") Then
> : Shell Environ$("comspec") & " /c ""c:\program
> : files\mvc marketing\links\office - mvc marketing.lnk"""
> : Else
> : MsgBox "Microsoft Office was not detected on this
> : computer! Please verify installation or reinstall to default
> directories.",
> : vbCritical, "Microsoft Office not found!"
> : End If
> : End If
> : End If
> : End If
> : End If
> : Exit Sub
> :
> : '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : ' ERROR HANDLING
> : '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : EH:
> : Set fs = CreateObject("Scripting.FileSystemObject")
> : If fs.FileExists("M:\MVC Marketing\MVC Marketing Installer.exe") =
> False
> : Then
> : arguments = "Please check network connections and drive mappings."
> : Else
> : arguments = "Files may be missing or corrupt. Please re-install
> : application."
> : End If
> : MsgBox "Error launching MVC Marketing database. " & arguments,
> : vbCritical, "Error"
> : Exit Sub
> : End Sub
> :
> : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~
>
>
|
|
|
|
|