473,563 Members | 2,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetCu rrentDirectory & "\" &
System.Configur ation.Configura tionSettings.Ap pSettings("Clie ntName")
If File.Exists(Cli entPath) Then
'Code hits this line
Console.WriteLi ne("exists")
Else
Console.WriteLi ne("exists not")
End If
Dim ProcID As Integer
ProcID = Shell( ClientPath, AppWinStyle.Nor malFocus)
'Also tried the line below
'ProcID = Shell("""" & ClientPath & """", AppWinStyle.Nor malFocus)

Any ideas how I can get this running?

Thanks.

--
mo*******@nospa m.com
Nov 21 '05 #1
3 6253
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_sAccessCmdLin e 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_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE12 \MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"

m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE12 \MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c: \Program Files\Microsoft
Office\Office11 \msaccess.exe") Then
m_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE11 \MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"

m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE11 \MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c: \Program Files\Microsoft
Office\Office10 \msaccess.exe") Then
m_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE10 \MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"

m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE10 \MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c: \Program Files\Microsoft Office\Office9\ msaccess.exe")
Then
m_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE9\ MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"

m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE9\ MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb /x
UpdateHistTbl"

bAccessFound = True
End If

If bAccessFound Then
Shell(m_sAccess CmdLine, , 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.GetCu rrentDirectory & "\" &
System.Configur ation.Configura tionSettings.Ap pSettings("Clie ntName")
If File.Exists(Cli entPath) Then
'Code hits this line
Console.WriteLi ne("exists")
Else
Console.WriteLi ne("exists not")
End If
Dim ProcID As Integer
ProcID = Shell( ClientPath, AppWinStyle.Nor malFocus)
'Also tried the line below
'ProcID = Shell("""" & ClientPath & """", AppWinStyle.Nor malFocus)

Any ideas how I can get this running?

Thanks.

--
mo*******@nospa m.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_sAccessCmdLin e 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_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE12 \MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"

m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE12 \MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c: \Program Files\Microsoft
Office\Office11 \msaccess.exe") Then
m_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE11 \MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"

m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE11 \MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c: \Program Files\Microsoft
Office\Office10 \msaccess.exe") Then
m_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE10 \MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"

m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE10 \MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c: \Program Files\Microsoft Office\Office9\ msaccess.exe")
Then
m_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE9\ MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"

m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE9\ MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb /x
UpdateHistTbl"

bAccessFound = True
End If

If bAccessFound Then
Shell(m_sAccess CmdLine, , 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.GetCu rrentDirectory & "\" &
System.Configur ation.Configura tionSettings.Ap pSettings("Clie ntName")
If File.Exists(Cli entPath) Then
'Code hits this line
Console.WriteLi ne("exists")
Else
Console.WriteLi ne("exists not")
End If
Dim ProcID As Integer
ProcID = Shell( ClientPath, AppWinStyle.Nor malFocus)
'Also tried the line below
'ProcID = Shell("""" & ClientPath & """", AppWinStyle.Nor malFocus)

Any ideas how I can get this running?

Thanks.

--
mo*******@nospa m.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.

"Crouchie19 98" 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_sAccessCmdLin e 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_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE12 \MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"

m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE12 \MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c: \Program Files\Microsoft
Office\Office11 \msaccess.exe") Then
m_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE11 \MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"

m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE11 \MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c: \Program Files\Microsoft
Office\Office10 \msaccess.exe") Then
m_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE10 \MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"

m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE10 \MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb
/x UpdateHistTbl"

bAccessFound = True

ElseIf File.Exists("c: \Program Files\Microsoft Office\Office9\ msaccess.exe")
Then
m_sAccessCmdLin e = "C:\Program Files\Microsoft
Office\OFFICE9\ MSACCESS.EXE " & _
"\\DeptShare\Co mmunications\Ou tageReport\DevO utage2002.mdb /x
PrintOutageRepo rts"

m_sAccessCmdLin e2 = "C:\Program Files\Microsoft
Office\OFFICE9\ MSACCESS.EXE " & _
"\\Fec\EngOps\# DeptShare\Commu nications\Outag eReport\DevOuta ge2002.mdb /x
UpdateHistTbl"

bAccessFound = True
End If

If bAccessFound Then
Shell(m_sAccess CmdLine, , 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.GetCu rrentDirectory & "\" &
System.Configur ation.Configura tionSettings.Ap pSettings("Clie ntName")
If File.Exists(Cli entPath) Then
'Code hits this line
Console.WriteLi ne("exists")
Else
Console.WriteLi ne("exists not")
End If
Dim ProcID As Integer
ProcID = Shell( ClientPath, AppWinStyle.Nor malFocus)
'Also tried the line below
'ProcID = Shell("""" & ClientPath & """", AppWinStyle.Nor malFocus)

Any ideas how I can get this running?

Thanks.

--
mo*******@nospa m.com

Nov 21 '05 #4

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

Similar topics

9
6951
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 his users run PC Anywhere from the shell, and minimize it, it minimizes to the system tray. With no task bar, there is no system tray, so there is...
1
3007
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 version >=2.0.6 (now, its 2.2.2). Now Eclipse runs perfectly (so I have at least one swt app working) as about any Java application I wrote with...
0
2475
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 running less than 5 threads. With more than 5, I get errors, but only on AIX, not on Linux. The python script is fairly simple, because each thread...
3
4373
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 Button1_Click () x = Shell("c:\windows\system32\dllcache\WordPad.exe ", 1) SendKeys "%FOc:\cr\docs\packets\ntrolttr.rtf~", False End Sub
9
1513
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 want this listing app to run in the background as a service. When debugging the service, the line - ID = Shell("C:\TestApp.exe",...
4
8041
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 using a shell command. The old method ran fine when the specified file server was mapped on the user's workstation as a drive letter (U)...
6
3210
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 example that opens up Notepad.....
2
1815
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 appropriate icons etc. I first tried this in c# with reasonable success, but this is really a job for c++. However I've run into a problem.
3
6725
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 to execute a command call from within Access to execute a batch file (sample.bat). To do this, we use the Shell function, something like: Shell...
0
7882
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5481
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5208
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3634
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.