472,797 Members | 1,095 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Process.Run and App.Config

I'm trying to execute a stand-alone console application from an aspx page
when a use clicks a button on that page. On the aspx page is the following
lines of pertinent code:

private void btnStartApp(object sender, System.EventArgs e)
{
Process procID;
string procName;
ProcessStartInfo psi = new ProcessStartInfo();
procName=System.Configuration.ConfigurationSetting s.AppSettings["Application
Name"].ToString();
psi.FileName = procName;
psi.Arguments="-noOp";
psi.WorkingDirectory=procName.SubString(0,procName .LastIndexOf('\\');

procID = Process.Start(psi);

}

In the console application that starts, it starts in the correct directory,
starts as user ASPNET, and gets the command line parameters fine, but
there's a line of code in the console app where it tries to read a
configuration string from the App.Config file. And it always fails on the
read and subsequently the application will fail because it doesn't have this
string value. I checked and the permissions on the working directory are
full for user ASPNET.

Where would the shell be looking for the App.Config file if not in the
working directory?
Does anyone have any experience with this to tell me why the console app is
not looking for the App.Config file in the working directory when it's run
like this as user ASPNET? It works fine when run from the command line in
"normal" mode.

Any thoughts/comments/help would be greatly appreciated ... I would hate to
have to just hard code the config string, it seems like you should still be
able to use the App.Config file for this time of run.

Nov 18 '05 #1
2 2161
PMac wrote:
I'm trying to execute a stand-alone console application from an aspx page
when a use clicks a button on that page. On the aspx page is the following
lines of pertinent code:

private void btnStartApp(object sender, System.EventArgs e)
{
Process procID;
string procName;
ProcessStartInfo psi = new ProcessStartInfo();
procName=System.Configuration.ConfigurationSetting s.AppSettings["Application
Name"].ToString();
psi.FileName = procName;
psi.Arguments="-noOp";
psi.WorkingDirectory=procName.SubString(0,procName .LastIndexOf('\\');

procID = Process.Start(psi);

}

In the console application that starts, it starts in the correct directory,
starts as user ASPNET, and gets the command line parameters fine, but
there's a line of code in the console app where it tries to read a
configuration string from the App.Config file. And it always fails on the
read and subsequently the application will fail because it doesn't have this
string value. I checked and the permissions on the working directory are
full for user ASPNET.
Just taking some stabs at this (no time to test this right now):

Try setting "psi.UseShellExecute = false". This will cause
Process.Start() to use CreateProcess() behind the scenes instead of
ShellExecuteEx().

Are you using ConfigurationSettings.AppSettings() to read the app.config
file or some other method? Is the item you're reading in a user-defined
configuration section, or is it in <appSettings>?

If you're using ConfigurationSettings, try reading the file using
System.IO classes (ie., as a stream) and see if you get an access denied
error (or some other error).

Where would the shell be looking for the App.Config file if not in the
working directory?
As far as I know, the 'working directory' should not be a factor - the
framework doesn't look in the 'working directory', it looks in the
application's base directory. The config file should be in the exact
same location as the .exe file (which looks to be the case in your
example, since your code sets the working directory to the .exe's
directory).
Does anyone have any experience with this to tell me why the console app is
not looking for the App.Config file in the working directory when it's run
like this as user ASPNET? It works fine when run from the command line in
"normal" mode.

Any thoughts/comments/help would be greatly appreciated ... I would hate to
have to just hard code the config string, it seems like you should still be
able to use the App.Config file for this time of run.

--
mikeb
Nov 18 '05 #2
Mikeb - Thanks for your help ...

yes, I am using ConfigurationSettings.AppSettings() to read the
configuration string from app.config. I tried setting psi.UseShellExecute =
false and that didn't help. I also did my own reading from the app.config
file and was able to open and read it as ASPNET. Apparently there's
something in the ConfigurationSettings.AppSettings() that doesn't get set
when in the shell.

"mikeb" <ma************@nospam.mailnull.com> wrote in message
news:uZ**************@TK2MSFTNGP11.phx.gbl...
PMac wrote:
I'm trying to execute a stand-alone console application from an aspx page when a use clicks a button on that page. On the aspx page is the following lines of pertinent code:

private void btnStartApp(object sender, System.EventArgs e)
{
Process procID;
string procName;
ProcessStartInfo psi = new ProcessStartInfo();
procName=System.Configuration.ConfigurationSetting s.AppSettings["Application Name"].ToString();
psi.FileName = procName;
psi.Arguments="-noOp";
psi.WorkingDirectory=procName.SubString(0,procName .LastIndexOf('\\');
procID = Process.Start(psi);

}

In the console application that starts, it starts in the correct directory, starts as user ASPNET, and gets the command line parameters fine, but
there's a line of code in the console app where it tries to read a
configuration string from the App.Config file. And it always fails on the read and subsequently the application will fail because it doesn't have this string value. I checked and the permissions on the working directory are full for user ASPNET.


Just taking some stabs at this (no time to test this right now):

Try setting "psi.UseShellExecute = false". This will cause
Process.Start() to use CreateProcess() behind the scenes instead of
ShellExecuteEx().

Are you using ConfigurationSettings.AppSettings() to read the app.config
file or some other method? Is the item you're reading in a user-defined
configuration section, or is it in <appSettings>?

If you're using ConfigurationSettings, try reading the file using
System.IO classes (ie., as a stream) and see if you get an access denied
error (or some other error).

Where would the shell be looking for the App.Config file if not in the
working directory?


As far as I know, the 'working directory' should not be a factor - the
framework doesn't look in the 'working directory', it looks in the
application's base directory. The config file should be in the exact
same location as the .exe file (which looks to be the case in your
example, since your code sets the working directory to the .exe's
directory).
Does anyone have any experience with this to tell me why the console app is not looking for the App.Config file in the working directory when it's run like this as user ASPNET? It works fine when run from the command line in "normal" mode.

Any thoughts/comments/help would be greatly appreciated ... I would hate to have to just hard code the config string, it seems like you should still be able to use the App.Config file for this time of run.

--
mikeb

Nov 18 '05 #3

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

Similar topics

0
by: william | last post by:
Hi, I have an application which uses XML config file This application can be run twice or more on different config files There can't be parallel execution on the same config file My question is,...
1
by: Aviad C | last post by:
Hello I created a web service that runs a new process whice is a vbscript. It all works well, i can see the wscript.exe running in the Task Manager under the user ASPNET but nothing happened. I...
7
by: Dave Mehrtens | last post by:
I am trying to configure my ASP.NET application and have come across something unexpected. First, I understand that all ASP.NET applications running on a single server will utilize a single...
3
by: PMac | last post by:
I'm trying to execute a stand-alone console application from an aspx page when a use clicks a button on that page. On the aspx page is the following lines of pertinent code: private void...
2
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been...
3
by: Christopher | last post by:
One of our ASP.NET Pages is starting a new Process using the Process object. When the process starts, it is started under the ASPNET User. We tried editing the web.config file and the...
3
by: CG | last post by:
I have a VS .NET 2003 web service project which references a Managed C++ assembly. The managed C++ assembly in turn uses some unmanaged code. Because of some restriction in the unmanaged...
2
by: Trond | last post by:
I am trying to start a console program from an event in a ASP.NET page. In the folder where the EXE is there is a config file. Here is some code i wrote that should start the exe file: ...
9
by: woolley.dean | last post by:
The problem we are having is with the worker process restarting after one minute of being started up. We had a website running in .Net 1.1 and switched it over to .Net 2.0. The site is running on...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.