By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,722 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,722 IT Pros & Developers. It's quick & easy.

Hidden process started by web method

P: n/a
Good Morning and Happy Wednesday!

I've got a web service that exposes a method that takes
an string input parameter that specifies an executable
on the server that starts a process. These processes
should runs in a Windows window. The process loads
and runs under the ASPNET user account fine but the
window is hidden. The Windows task manager shows
that the process has loaded and the code performs
the intended task (just deletes some files for now).

I'd like to have the window show on the server for
diagonistics purposes. I'm using the Process class
of the System.Diagnostics namespace.

By the way, the code works "as advertised" if it's
used in the context of a Windows .NET application
(i.e. the Window associated with the process(s) show).

I understand that one typically wouldn't open windows
associated with a web service but this is a special requirement
for a system that runs in it's isolated domain.
Here's the sample web method that I'm currently using:

Any pointers or help is greatly appreciated.

See code sample below.

Kind Regards
Ben

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
namespace WebService_custom
{
/// <summary>
/// Summary description for Service1.
/// </summary>
///
[WebService(Namespace="http://localhost/WebService/",Description="XML Web
Service")]
public class ControlService : System.Web.Services.WebService
{
private Process m_process;

// These are the Win32 error code for file not found or access denied.
const int ERROR_FILE_NOT_FOUND =2;
const int ERROR_ACCESS_DENIED = 5;

public ControlService()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion
[WebMethod]
public int StartProcess( string ProcessName )
{
try
{
Process.Start( ProcessName );
Process.Start("IExplore.exe");
Process.Start("Notepad.exe");
return 0;

}
catch (Win32Exception e)
{
if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
Console.WriteLine(e.Message + ". Check the path.");
}
else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
{
// Note that if your word processor might generate exceptions
// such as this, which are handled first.
Console.WriteLine(e.Message + ". You do not have permission to launch
this process.");
return -1;
}
}
return 1;
}

[WebMethod]
public int KillProcess()
{
try
{
m_process.Kill();
}
catch (Win32Exception e)
{
Console.WriteLine(e.Message + ". error killing process.");
}
return -1;
}
}
}
Nov 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

I think the ASP user account does not have the "Interact with desktop"
privilege....

On the other hand, I know you said this is an exception, but accepting
user input which will be 'executed in a shell' is really really really
.....
snip (about a 1000 lines)
.....
really really dangerous. ;)

Hope this helps,

Marvin Smit.
On Wed, 31 Aug 2005 08:30:11 -0700, "BenS"
<Be**@discussions.microsoft.com> wrote:
Good Morning and Happy Wednesday!

I've got a web service that exposes a method that takes
an string input parameter that specifies an executable
on the server that starts a process. These processes
should runs in a Windows window. The process loads
and runs under the ASPNET user account fine but the
window is hidden. The Windows task manager shows
that the process has loaded and the code performs
the intended task (just deletes some files for now).

I'd like to have the window show on the server for
diagonistics purposes. I'm using the Process class
of the System.Diagnostics namespace.

By the way, the code works "as advertised" if it's
used in the context of a Windows .NET application
(i.e. the Window associated with the process(s) show).

I understand that one typically wouldn't open windows
associated with a web service but this is a special requirement
for a system that runs in it's isolated domain.
Here's the sample web method that I'm currently using:

Any pointers or help is greatly appreciated.

See code sample below.

Kind Regards
Ben

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
namespace WebService_custom
{
/// <summary>
/// Summary description for Service1.
/// </summary>
///
[WebService(Namespace="http://localhost/WebService/",Description="XML Web
Service")]
public class ControlService : System.Web.Services.WebService
{
private Process m_process;

// These are the Win32 error code for file not found or access denied.
const int ERROR_FILE_NOT_FOUND =2;
const int ERROR_ACCESS_DENIED = 5;

public ControlService()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion
[WebMethod]
public int StartProcess( string ProcessName )
{
try
{
Process.Start( ProcessName );
Process.Start("IExplore.exe");
Process.Start("Notepad.exe");
return 0;

}
catch (Win32Exception e)
{
if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
Console.WriteLine(e.Message + ". Check the path.");
}
else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
{
// Note that if your word processor might generate exceptions
// such as this, which are handled first.
Console.WriteLine(e.Message + ". You do not have permission to launch
this process.");
return -1;
}
}
return 1;
}

[WebMethod]
public int KillProcess()
{
try
{
m_process.Kill();
}
catch (Win32Exception e)
{
Console.WriteLine(e.Message + ". error killing process.");
}
return -1;
}
}
}


Nov 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.