473,320 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem using shell cmd to start MS Access app

I need to start an ms access 2003 app from a vb.net winforms app and didn't
want to load all the interop stuff for office into the .net project. I
thought that using the shell cmd would be a nice clean way to get it
started. However, when I call the shell cmd, I get a "File Not Found"
error. here's my code:
Dim ClientPath As String = Directory.GetCurrentDirectory & "\" &
System.Configuration.ConfigurationSettings.AppSett ings("ClientName")
If File.Exists(ClientPath) Then
'Code hits this line
Console.WriteLine("exists")
Else
Console.WriteLine("exists not")
End If
Dim ProcID As Integer
ProcID = Shell( ClientPath, AppWinStyle.NormalFocus)
'Also tried the line below
'ProcID = Shell("""" & ClientPath & """", AppWinStyle.NormalFocus)

Any ideas how I can get this running?

Thanks.

--
mo*******@nospam.com
Nov 21 '05 #1
3 6231
Okay folks I know this isn't kosher. Nor is it my finest work, but the code
snippet is one I actually have in production and it does work.

Where m_sAccessCmdLine is a member string value and bAccessFound is a
function bollean value defaulted at False:
If File.Exists("c:\Program Files\Microsoft Office\Office12\msaccess.exe") Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE12\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE12\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c:\Program Files\Microsoft
Office\Office11\msaccess.exe") Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c:\Program Files\Microsoft
Office\Office10\msaccess.exe") Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE10\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE10\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c:\Program Files\Microsoft Office\Office9\msaccess.exe")
Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE9\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE9\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb /x
UpdateHistTbl"

bAccessFound = True
End If

If bAccessFound Then
Shell(m_sAccessCmdLine, , True)
End If

You can see several problems with the code. Each new version of Access is in
a different location meaning that this code will need maintenance with each
release of Access. I really should not have been so lazy as to resort to a
member variable to carry out this task. A select case statement in place of
the compound If statement would be a little clearer. There are much better
ways to carry this out than using a Shell command. The Process Class comes to
mind.

But, like I said, it does work.

"moondaddy" wrote:
I need to start an ms access 2003 app from a vb.net winforms app and didn't
want to load all the interop stuff for office into the .net project. I
thought that using the shell cmd would be a nice clean way to get it
started. However, when I call the shell cmd, I get a "File Not Found"
error. here's my code:
Dim ClientPath As String = Directory.GetCurrentDirectory & "\" &
System.Configuration.ConfigurationSettings.AppSett ings("ClientName")
If File.Exists(ClientPath) Then
'Code hits this line
Console.WriteLine("exists")
Else
Console.WriteLine("exists not")
End If
Dim ProcID As Integer
ProcID = Shell( ClientPath, AppWinStyle.NormalFocus)
'Also tried the line below
'ProcID = Shell("""" & ClientPath & """", AppWinStyle.NormalFocus)

Any ideas how I can get this running?

Thanks.

--
mo*******@nospam.com

Nov 21 '05 #2
I don't suggest that you hard code the MS Access path just incase the user
has it installed on a different drive

"ocertain" wrote:
Okay folks I know this isn't kosher. Nor is it my finest work, but the code
snippet is one I actually have in production and it does work.

Where m_sAccessCmdLine is a member string value and bAccessFound is a
function bollean value defaulted at False:
If File.Exists("c:\Program Files\Microsoft Office\Office12\msaccess.exe") Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE12\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE12\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c:\Program Files\Microsoft
Office\Office11\msaccess.exe") Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c:\Program Files\Microsoft
Office\Office10\msaccess.exe") Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE10\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE10\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c:\Program Files\Microsoft Office\Office9\msaccess.exe")
Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE9\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE9\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb /x
UpdateHistTbl"

bAccessFound = True
End If

If bAccessFound Then
Shell(m_sAccessCmdLine, , True)
End If

You can see several problems with the code. Each new version of Access is in
a different location meaning that this code will need maintenance with each
release of Access. I really should not have been so lazy as to resort to a
member variable to carry out this task. A select case statement in place of
the compound If statement would be a little clearer. There are much better
ways to carry this out than using a Shell command. The Process Class comes to
mind.

But, like I said, it does work.

"moondaddy" wrote:
I need to start an ms access 2003 app from a vb.net winforms app and didn't
want to load all the interop stuff for office into the .net project. I
thought that using the shell cmd would be a nice clean way to get it
started. However, when I call the shell cmd, I get a "File Not Found"
error. here's my code:
Dim ClientPath As String = Directory.GetCurrentDirectory & "\" &
System.Configuration.ConfigurationSettings.AppSett ings("ClientName")
If File.Exists(ClientPath) Then
'Code hits this line
Console.WriteLine("exists")
Else
Console.WriteLine("exists not")
End If
Dim ProcID As Integer
ProcID = Shell( ClientPath, AppWinStyle.NormalFocus)
'Also tried the line below
'ProcID = Shell("""" & ClientPath & """", AppWinStyle.NormalFocus)

Any ideas how I can get this running?

Thanks.

--
mo*******@nospam.com

Nov 21 '05 #3
Yep. I did say it wasn't kosher and has even more problems than you pointed
out. If I were handed this task today I would *not* use this approach.

"Crouchie1998" wrote:
I don't suggest that you hard code the MS Access path just incase the user
has it installed on a different drive

"ocertain" wrote:
Okay folks I know this isn't kosher. Nor is it my finest work, but the code
snippet is one I actually have in production and it does work.

Where m_sAccessCmdLine is a member string value and bAccessFound is a
function bollean value defaulted at False:
If File.Exists("c:\Program Files\Microsoft Office\Office12\msaccess.exe") Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE12\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE12\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c:\Program Files\Microsoft
Office\Office11\msaccess.exe") Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c:\Program Files\Microsoft
Office\Office10\msaccess.exe") Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE10\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE10\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c:\Program Files\Microsoft Office\Office9\msaccess.exe")
Then
m_sAccessCmdLine = "C:\Program Files\Microsoft
Office\OFFICE9\MSACCESS.EXE " & _
"\\DeptShare\Communications\OutageReport\DevOutage 2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE9\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageRepo rt\DevOutage2002.mdb /x
UpdateHistTbl"

bAccessFound = True
End If

If bAccessFound Then
Shell(m_sAccessCmdLine, , True)
End If

You can see several problems with the code. Each new version of Access is in
a different location meaning that this code will need maintenance with each
release of Access. I really should not have been so lazy as to resort to a
member variable to carry out this task. A select case statement in place of
the compound If statement would be a little clearer. There are much better
ways to carry this out than using a Shell command. The Process Class comes to
mind.

But, like I said, it does work.

"moondaddy" wrote:
I need to start an ms access 2003 app from a vb.net winforms app and didn't
want to load all the interop stuff for office into the .net project. I
thought that using the shell cmd would be a nice clean way to get it
started. However, when I call the shell cmd, I get a "File Not Found"
error. here's my code:
Dim ClientPath As String = Directory.GetCurrentDirectory & "\" &
System.Configuration.ConfigurationSettings.AppSett ings("ClientName")
If File.Exists(ClientPath) Then
'Code hits this line
Console.WriteLine("exists")
Else
Console.WriteLine("exists not")
End If
Dim ProcID As Integer
ProcID = Shell( ClientPath, AppWinStyle.NormalFocus)
'Also tried the line below
'ProcID = Shell("""" & ClientPath & """", AppWinStyle.NormalFocus)

Any ideas how I can get this running?

Thanks.

--
mo*******@nospam.com

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: none | last post by:
Hello all, I wrote a shell program a few years ago in VB6 that needs to be modified. The problem I have is this: The SysAdmin uses this shell in place of Explorer, so there is no taskbar. When...
1
by: ttn | last post by:
Hi, I am using a separately downloaded Eclipse 3M5 on a Debian woody (stable) system. To make Eclipse start at all I had to use the libgtk2 libraries from some backported gnome 2.2 to get a gtk...
0
by: Gardner Pomper | last post by:
Hi, I am pretty new to python, so be gentle :) I have a python script that spawns a number of threads (configurable) on a 12 processor AIX RISC-6000 machine. It works fine, so long as I am...
3
by: MLH | last post by:
I can open WordPad directly (Start, Run...), then open a document & click File, Send... Out goes the email without a hitch. However, if I open WordPad from Access this way... Sub...
9
by: dave m | last post by:
I have a small application that launches an application via the shell function when a listening socket receives data from another PC. This works fine using a WinForms environment. However, I...
4
by: RLN | last post by:
Re: Access 2003/WinXP Pro-SP3 I have a shell command that does not run correctly. I have two programs located on a file server: Pgm1.mdb and Pgm2.mdb Pgm1 launches Pgm2 via a command button...
6
by: bill | last post by:
I have a VB .net 2.0 site that needs to run a dos app upon a button click. I found Shell too unreliable using parameters and so used system.diagnostic.process. simple troubleshooting...
2
by: Paul W | last post by:
Hello, My problem concerns the shell. If there's a better forum for this post, please let me know. I'm trying to create a ListView control that displays the contents of a folder with all the...
3
by: Max Vit | last post by:
I have come across a strange issue whilst trying to use a shell command call from Access and have spent some time trying to figure this out but can't find the cause as yet. The issue is: I need...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.