Problem using shell cmd to start MS Access app

M

moondaddy

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.AppSettings("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.
 
G

Guest

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\DevOutage2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE12\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageReport\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\DevOutage2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE11\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageReport\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\DevOutage2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE10\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageReport\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\DevOutage2002.mdb /x
PrintOutageReports"

m_sAccessCmdLine2 = "C:\Program Files\Microsoft
Office\OFFICE9\MSACCESS.EXE " & _
"\\Fec\EngOps\#DeptShare\Communications\OutageReport\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.
 
G

Guest

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

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top