473,698 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hidden process started by web method

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.Diagnost ics 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.Componen tModel;
using System.Diagnost ics;
using System.Web.Serv ices;
namespace WebService_cust om
{
/// <summary>
/// Summary description for Service1.
/// </summary>
///
[WebService(Name space="http://localhost/WebService/",Description=" XML Web
Service")]
public class ControlService : System.Web.Serv ices.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_DE NIED = 5;

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

#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 InitializeCompo nent()
{

}

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

#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.NativeErro rCode == ERROR_FILE_NOT_ FOUND)
{
Console.WriteLi ne(e.Message + ". Check the path.");
}
else if (e.NativeErrorC ode == ERROR_ACCESS_DE NIED)
{
// Note that if your word processor might generate exceptions
// such as this, which are handled first.
Console.WriteLi ne(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.WriteLi ne(e.Message + ". error killing process.");
}
return -1;
}
}
}
Nov 23 '05 #1
1 3321
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**@discussio ns.microsoft.co m> 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.Diagnost ics 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.Componen tModel;
using System.Diagnost ics;
using System.Web.Serv ices;
namespace WebService_cust om
{
/// <summary>
/// Summary description for Service1.
/// </summary>
///
[WebService(Name space="http://localhost/WebService/",Description=" XML Web
Service")]
public class ControlService : System.Web.Serv ices.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_DE NIED = 5;

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

#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 InitializeCompo nent()
{

}

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

#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.NativeErro rCode == ERROR_FILE_NOT_ FOUND)
{
Console.WriteLi ne(e.Message + ". Check the path.");
}
else if (e.NativeErrorC ode == ERROR_ACCESS_DE NIED)
{
// Note that if your word processor might generate exceptions
// such as this, which are handled first.
Console.WriteLi ne(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.WriteLi ne(e.Message + ". error killing process.");
}
return -1;
}
}
}


Nov 23 '05 #2

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

Similar topics

1
2598
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
12
2936
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am starting is that it has a welcome window first which gets displayed and then the real windows after a while,in other words it means that the process name is the same, but the handle I need to retrive is the one from the final window and not the...
3
5807
by: DAMAR | last post by:
Hello Is it possible to know when a particular process started? For example: I have such situation: I need to know when a notepad.exe is started - i need to get an event of starting this process. Can anyone help me?
3
5931
by: Manfred Braun | last post by:
Hi All, the Process.Start method returns a boolean value to indicate, if a process was started or not. Where can I obtain more detailed error information, if the process could not be started ??? It seems to be possible, that a Win32Exception will be thrown. Will this give me this reason , if the process cannot be started? The docs looks a little vage for me. Thanks in advance, Manfred Braun
1
3069
by: AS | last post by:
Hi, I am opening an exe from my C# windows application, through system.diagnostics.process.start() - process.StartInfo.FileName = "c:\\windows\\system32\\vkey.exe"; ] process.StartInfo.WorkingDirectory = "c:\\"; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start();
22
3402
by: Alison Givens | last post by:
Hi there, I have a small app, that copies some files to the server for backup, as soon as the user exits Windows. I want this form to startup hidden, so for the user it is not visible and he/she can't close it. How do I do this? thanx, Alison
5
2683
by: pbd22 | last post by:
Hi. I am trying to poll a long-running process via a hidden IFrame. I am noticing that the online errata gives advice for handling a server response: window.parent.handleServerResponse(); The problem I am having with this is that the above function gets called ***after*** the long-running response is completed.
11
6010
by: geoffbache | last post by:
Hi, As part of my efforts to write a test tool that copes with GUIs nicely, I'm trying to establish how I can start a GUI process on Windows that will not bring up the window. So I try to hide the window as follows: info = subprocess.STARTUPINFO() info.dwFlags |= subprocess.STARTF_USESHOWWINDOW info.wShowWindow = subprocess.SW_HIDE
12
6536
by: Dilip | last post by:
Hi All I have a server based C# console application. This application must hide its console window when its launched out on the field. So I dutifully P/Invoke'd FindWindow/ShowWindow combination to hide the console window at launch time. The application (for legacy reasons) hangs around by waiting on an old- fashioned Console.ReadLine() statement.
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9166
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
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
8871
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
7737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6525
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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

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.