473,395 Members | 1,437 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,395 software developers and data experts.

Calling a batch file in a Web Service using Process object, uses wrong user context.

I have a web service that needs to create a batch file and call it (since
there are no APIs for the functionality I am looking for). I am using the
Process and ProcessStartInfo objects. When I try to call the batch file, it
just returns with a return code of 1. When I call cmd.exe, and pass the
batch file as a parameter it hangs. After much frustration and aggrevation,
I found that CMD IS in fact running, but it is running under the context of
ASPNET user. My web service is running under a domain account, dicatated in
the web.config file.

<authentication mode="Windows" />
<!-- Impersonate: Run as the Build ID -->
<identity impersonate="true" userName="domain\myuser" password="mypassword"
/>

All the code in the web service is using this id, except when I create the
process using the Process.Start() function. Even something as simple as
calling Notepad runs the program as the ASPNET user and I cannot see it on
my screen. The program will hang until I kill it in task manager. (I am
calling WaitForExit() ).

Why won't this run under the context I've defined in the web.config? Is
there a way to run this under that ID without using Windows APIs such as
CreateProcessWithLogonW? I've tried many different options, this is what I
currently am trying.

// Now Execute the script
ProcessStartInfo startInfo = new ProcessStartInfo(strBatchFile);
startInfo.WorkingDirectory = m_strWorkFolder;
startInfo.UseShellExecute = true;
startInfo.CreateNoWindow = false;

Process procIa = Process.Start(startInfo);
if ( null == procIa )
{
strError = "Failed to start process: " + strBatFile;
return false;
}

procIa.WaitForExit();
if ( procIa.ExitCode != 0 )
{
return false;
}

TIA.
Bucky Pollard.
Nov 17 '05 #1
1 5777
Inline

Willy.

"Bucky Pollard" <my***********@ml.com> wrote in message
news:ea**************@TK2MSFTNGP14.phx.gbl...
I have a web service that needs to create a batch file and call it (since
there are no APIs for the functionality I am looking for). I am using the
Process and ProcessStartInfo objects. When I try to call the batch file,
it
just returns with a return code of 1. When I call cmd.exe, and pass the
batch file as a parameter it hangs. After much frustration and
aggrevation,
I found that CMD IS in fact running, but it is running under the context
of
ASPNET user. My web service is running under a domain account, dicatated
in
the web.config file.

Not sure why it returns an error, all I can say is that the behavior is by
design.
The threads executing the request is impersonating the domain account, but
the process is still running as aspnet, a spawned windows process always
inherits the calling process identity not the callers thread identity, so
your cmd.exe runs as aspnet. If your batch program relies on an interactive
user's context, it's certainly the cause of your problem.

<authentication mode="Windows" />
<!-- Impersonate: Run as the Build ID -->
<identity impersonate="true" userName="domain\myuser"
password="mypassword"
/>

All the code in the web service is using this id, except when I create the
process using the Process.Start() function. Even something as simple as
calling Notepad runs the program as the ASPNET user and I cannot see it on
my screen. The program will hang until I kill it in task manager. (I am
calling WaitForExit() ).
The callers process doesn't run in the "interactive logon" session, that
means it has no access to the interactive desktop (it runs in the context of
asp/IIS). That means that web applications should not start interactive
applications and should not consider the presence of an interactive
user/logon context (that is, no profile is loaded the environment is not a
interactive users environment etc...). When starting batch like non
interactive processes from web applications, you need to make sure that no
(error!?) messages are displayed or that no user action is ever required and
that you don't rely on the presence of a specific user's context
(profile/environment).
Why won't this run under the context I've defined in the web.config? Is
there a way to run this under that ID without using Windows APIs such as
CreateProcessWithLogonW? I've tried many different options, this is what
I
currently am trying.

If your application needs a specific users context, you will have to call
CreateProcessWithLogonW and maybe you will have to load/unload the users
profile.
// Now Execute the script
ProcessStartInfo startInfo = new ProcessStartInfo(strBatchFile);
startInfo.WorkingDirectory = m_strWorkFolder;
startInfo.UseShellExecute = true;
startInfo.CreateNoWindow = false;

Process procIa = Process.Start(startInfo);
if ( null == procIa )
{
strError = "Failed to start process: " + strBatFile;
return false;
}

procIa.WaitForExit();
if ( procIa.ExitCode != 0 )
{
return false;
}

TIA.
Bucky Pollard.

Nov 17 '05 #2

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

Similar topics

14
by: Mark C. | last post by:
I'm trying to call a batch file that I've built using the FileSystemObject and CreateObject("Wscript.Shell"), oShell.Run... in an asp script. Naturally, I can get the script to work from a command...
3
by: Chris | last post by:
Hi, How can I execute a batch file form asp.net app. I have a form which a user uploads a text file. after the file is uploaded I want a batch file to then execute and do some work. Thanks
0
by: Cleo | last post by:
Hi, I am trying to call a WebService Method written in Weblogic from VB.NET and I am getting the following error. I am using SOAP Caal s from VB.NET. Please find the wsdl file and my code. ...
3
by: emman_54 | last post by:
Hi every one, I am trying to run a batch file using my asp.net application. I am using the Process class to run the batch file. When I run my web application, In the task manager, i could see...
1
by: steve | last post by:
Hi all, Here's some work in progress that should allow you to run a batch file as a custom action in a VS deployment project. Yup I know you can use js or wsh, but the target may not have...
1
by: sales | last post by:
Hi! I'm newish to writing web services and am trying to deploy a web service on a hosted server on the internet. My web service uses a mysql oledb data provider to get data from a database...
0
by: gabrielk43 | last post by:
Hi to all, I have made a web service which creates a batch file in a folder in web server and tries to execute it (in a Windows Server 2003 web server). So far I have managed to create the batch...
14
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in...
1
by: wanaruk | last post by:
Hi all. I am working on a legacy application written in Classic ASP with VB6 COM+ components running on Windows 2003 Adv Server (32bit). There is one page in the app that uses Secure FTP to send...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...

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.