473,806 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(obj ect sender, System.EventArg s e)
{
Process procID;
string procName;
ProcessStartInf o psi = new ProcessStartInf o();
procName=System .Configuration. ConfigurationSe ttings.AppSetti ngs["Applicatio n
Name"].ToString();
psi.FileName = procName;
psi.Arguments="-noOp";
psi.WorkingDire ctory=procName. SubString(0,pro cName.LastIndex Of('\\');

procID = Process.Start(p si);

}

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 2253
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(obj ect sender, System.EventArg s e)
{
Process procID;
string procName;
ProcessStartInf o psi = new ProcessStartInf o();
procName=System .Configuration. ConfigurationSe ttings.AppSetti ngs["Applicatio n
Name"].ToString();
psi.FileName = procName;
psi.Arguments="-noOp";
psi.WorkingDire ctory=procName. SubString(0,pro cName.LastIndex Of('\\');

procID = Process.Start(p si);

}

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.UseShellEx ecute = false". This will cause
Process.Start() to use CreateProcess() behind the scenes instead of
ShellExecuteEx( ).

Are you using ConfigurationSe ttings.AppSetti ngs() 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 ConfigurationSe ttings, 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 ConfigurationSe ttings.AppSetti ngs() to read the
configuration string from app.config. I tried setting psi.UseShellExe cute =
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 ConfigurationSe ttings.AppSetti ngs() that doesn't get set
when in the shell.

"mikeb" <ma************ @nospam.mailnul l.com> wrote in message
news:uZ******** ******@TK2MSFTN GP11.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(obj ect sender, System.EventArg s e)
{
Process procID;
string procName;
ProcessStartInf o psi = new ProcessStartInf o();
procName=System .Configuration. ConfigurationSe ttings.AppSetti ngs["Applicatio n Name"].ToString();
psi.FileName = procName;
psi.Arguments="-noOp";
psi.WorkingDire ctory=procName. SubString(0,pro cName.LastIndex Of('\\');
procID = Process.Start(p si);

}

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.UseShellEx ecute = false". This will cause
Process.Start() to use CreateProcess() behind the scenes instead of
ShellExecuteEx( ).

Are you using ConfigurationSe ttings.AppSetti ngs() 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 ConfigurationSe ttings, 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
3497
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, how to handl this My ideas -Adding a mutex on the config file (I don't know how to do it -Running an empty process with the configFile name and then, when the application is started, if a process with the config File name already exists. (But...
1
1663
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 did a little test, wrote a vbs that creats a folder but still nothing happened. it runs in the background doing nothing. no error, no exception. I changed the Web.config to use impersonate="true". after that even added the local Administrator to...
7
1683
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 aspnet_wp.exe process. And that this process, by default, runs under the context of the ASPNET username. I would rather use a trusted connection to connect to SQL Server to avoid having to put a username and password in a config file. However, if...
3
364
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 btnStartApp(object sender, System.EventArgs e) { Process procID; string procName; ProcessStartInfo psi = new ProcessStartInfo();
2
5439
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 recommended by many for web applications. I create the instances of Excel, Workbook and the worksheet. And later on Release the references by “System.Runtime.InteropServices.Marshal.ReleaseComObject(Object)” and making the object as null finally....
3
1982
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 machine.config to operate under other user accounts but our dynamically started process still starts under ASPNET. How do you programatically start a process under a specific Windows User Account? Thanks so much! Christopher
3
1988
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 (legacy) code, I can only have a aspnet_wp.exe worker process service only one web service request. In other words, after aspnet_wp.exe (wp1) serviced User1's web service request, it should not be used to service
2
1145
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: ---------------------------------------------------------------- Process p = new Process(); p.StartInfo.FileName = @"C:\Manager\Manager.exe";
9
3348
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 a W2003 machine w/ IIS6 with 4GB Ram. We have it running in it's own Application Pool with no other websites. The settings we have are: - Recycle worker process after 1440 Minutes - Shut down worker proecess after being idle for 20 minutes
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
1
10370
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6876
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5545
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.