How do I control a service from a web page or web application

I have developed some projects in C# but currently am faced with a posing problem.  I have a windows service developed in C++ and I need to be able to control that service from a web interface (i.e. the user clicks on a button to stop or run the service).  I currently have a control panel developed in C++ but would like to migrate the entire control panel to a web based solution.  Any ideas?  Can ASP.NET do this?  Where do I go to begin learning about how to do it?  Thanks for your help.
0
ccampbell113
1/16/2004 4:31:12 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

6 Replies
650 Views

Similar Articles

[PageSpeed] 50

two issues that I see:

1. re-using your C++ code -- can you port to a C++.NET assembly to make the classes easily available to your asp.net code -- or at least wrap in a COM active-x so that you can call it via interop. On the other hand, the code required to control a service in .NET is really simple, and you can probably throw out your C++ code.
2. permissions -- if your web is running under anonymous access, the process is in the security context of the ASP.NET user who is not likely to be allowed to control services, at least by default.
0
rox
1/16/2004 4:48:49 PM

try
{
System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("YourServiceName");
if(sc.Status == System.ServiceProcess.ServiceControllerStatus.Running)
sc.Stop();
}
catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("Error stopping the service",ex.ToString());
}


Christian Calderon
Need to work in Classic ASP? then do it the right way with CLASP!
Classic ASP Framework
0
ccalderon
1/16/2004 4:50:32 PM
here is code i wrote a long time ago for controlling a service, so i can't say too much about it.

it was a VB.NET winform, not ASP.NET, but should give you the idea of how to control services:
   Private servcon As New System.ServiceProcess.ServiceController()

Private Function UpdateStatus() As System.ServiceProcess.ServiceControllerStatus
servcon.Refresh()
Dim stat As System.ServiceProcess.ServiceControllerStatus = servcon.Status
StatusBar1.Text = servcon.DisplayName + " is: " + stat.ToString
StatusBar1.Invalidate()
Return stat
End Function
Private Sub btnHook_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHook.Click
servcon.ServiceName = TextBox1.Text
servcon.Refresh()
Label1.Text = servcon.DisplayName.ToString()
UpdateStatus()
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Try
If UpdateStatus() <> ServiceProcess.ServiceControllerStatus.Stopped Then Throw New Exception("Service not stopped.")
Enabled = False
servcon.Start()
While UpdateStatus() <> ServiceProcess.ServiceControllerStatus.Running
System.Threading.Thread.Sleep(100)
End While
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show("***ERROR***" + Chr(10) + ex.Message)
If ex.InnerException Is Nothing Then System.Windows.Forms.MessageBox.Show(ex.InnerException.Message)
Finally
Enabled = True
End Try
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
Try
If UpdateStatus() <> ServiceProcess.ServiceControllerStatus.Running Then Throw New Exception("Service not running.")
Enabled = False
servcon.Stop()
While UpdateStatus() <> ServiceProcess.ServiceControllerStatus.Stopped
System.Threading.Thread.Sleep(100)
End While
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show("***ERROR***" + Chr(10) + ex.Message)
If ex.InnerException Is Nothing Then System.Windows.Forms.MessageBox.Show(ex.InnerException.Message)
Finally
Enabled = True
End Try
End Sub
Private Sub btnUntimelyStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUntimelyStop.Click
Try
If UpdateStatus() <> ServiceProcess.ServiceControllerStatus.Running Then Throw New Exception("Service not running.")
Enabled = False
servcon.ExecuteCommand(Integer.Parse(txtCustom.Text))
While UpdateStatus() <> ServiceProcess.ServiceControllerStatus.Stopped
System.Threading.Thread.Sleep(100)
End While
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show("***ERROR***" + Chr(10) + ex.Message)
If ex.InnerException Is Nothing Then System.Windows.Forms.MessageBox.Show(ex.InnerException.Message)
Finally
Enabled = True
End Try
End Sub
0
rox
1/16/2004 4:51:26 PM
Scott is correct regarding the permissions. You may need to impersonate or if you are using Windows Authentication make sure that the user has enough privileges...
Christian Calderon
Need to work in Classic ASP? then do it the right way with CLASP!
Classic ASP Framework
0
ccalderon
1/16/2004 4:51:56 PM
How do i give permissions ?


it is an application in asp.net that wil stop a service.

It's the user asp.net who have the permission?

Other thing: how do i stop the internet access to a machine?which service must stop

Regards
zulurl
0
zulurl
3/10/2004 2:49:12 PM
If your web is configured for anonymous access, it will run as ASPNET user.

IIS runs under the "World Wide Web Publishing Service", shortname W3SVC.
e.g. from command-line "net stop w3svc"
0
rox
3/11/2004 9:36:49 PM
Reply:

Similar Artilces:

Can you return .net web controls in a .net page from a web service?
I've got a problem with a project. I've got to compile an entire .net page and return it as part of a Web Service for display. The problem I have is that I need to add WebControls and functionality to the page so that not only the html content and images are displayed (which I've managed) but that textboxes, labels, buttons and datasets can be displayed also. Essentially I need to make a call from one site for a page, populate the page and return it in a state as though it resided on the same server/webspace as the calling page. Code is currently built as follows into a string: strOpenHT...

How to get the HREF value of the Anchor tag in a web page using the web browser control in vb.net
Hi Friends,               i have a webserver control in my application.i load the web browser control on a button click using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click                AxWebBrowser1.Navigate("http://www.rateitall.com/i-322335-.aspx", False) End sub once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has ...

how to navigate the url page in one web application page to another web application page
In my project one solution have 2 web apllications in one folder.like 1.webapplication1 2.webapplication2. in firt webapplication1 i created one aspx page like sample.axpx. in second webapplication2 i created one aspx page like sample2.aspx... in sample2.aspx page have hyperlinl. I need to navigate this hyperlink when i click it go to the sample.axpx. how can i write navigate url for this...help me. ..thanks  As i understand u, you need Multi Project soltuionsee this link, http://community.rainbowportal.net/blogs/jonathans_rainbow_blog/archive/2006/02/19...

How to call a .net web service from another .net web service?
Hi all,I have developed two asp .net web services using visual studio .net 2003.I wish to call one web service from another web service.I tried adding a web reference of the web service in another web service and was able to do so.but i m not able to access the web methods provided by the web servicecould you please suggest a way to go about itExpecting quick replyThanxCharmy try to make sure that you reference it in the web reference and call it properly this is sample  [WebMethod()] public double CalcDistance(int x1, int y1, int x2, int y2) { Calculator.Service1 calc = new...

How to call .net web service from Java web application?
Hi all,  I have a vb .net web service.How do i call .net web service from Java web application?What all resources I need?Can you please provide a sample application where a java application is invoking methods of .net web service? Thank you Hi, First I am not familiar with java language, but web services are universal operating system and language independent. It doesn't matter where the services is or in what language is written you just invoke it  and it gives you "replay".  Probably you must reffer to java consuming web services.   Regard...

Encrypt web application/ web site (all web pages)
Hello, I want to encrypt (secure) the whole web site when it is deployed on a remote server. Is there a way in ASP.NET 2.0 / IIS / 3rd party tool to encrypt all web pages that will render it useless for a competitor if they get it?I did look up this forum and google and did not find anything (though I will keep looking). Please respond if you know anything about it. Thanks,vp Please click "Mark as Answer" if you think this post answers your question Yes and no.  First, you can't encrypt web pages.  Those are HTML and displayed in the client's brow...

controlling an object in a web control from the page the web control is placed in
I have created a web control in vb.net that has an image button and an image. when it loads the image button is visible and the image is not. I want to be able from the page which "includes" the web control to set the image button to invisible and the image to visible. When I tried this, the main page didn't recognise the image button or the image (both < asp: objects). help would be gratefully appreciated. oh yeah, it's inline code so any code behind stuff will just confuse me ;) Some code please.-- Justin Lovell...

Do not get expected WEb page on secondary
netware 6.5 sp2 Have setup a web page on a seconary IP address Load appache with the following command line LOAD ADDRESS SPACE = CSMI APACHE2 -f SYS:APACHE2\CSMI\SERVER\HTTPD.CONF Where HTTPD.CONF is set up to Listen 172.16.212.2:80 which is a secondary ip address A display secondary ipaddress at the server lists the seconary ipaddress I can ping the secondary ip address from the client in Remote manager using IP Address management the secondary IP addresses are not listed When I attempt to brose to the HTTP://172.16.212.2 address I do not see the web page I...

Web service in .NET from Java Web Service
Hi there,I'm pretty new to .net (although i have years of experience with the old vb 6, access 2k, as well as java)... and need some with perhaps either some syntax or something.Here is the wsdl.<wsdl:definitions targetNamespace="http://www.dynix.com/schema/book">−<wsdl:types>−<schema targetNamespace="GetBookInfoByISBN">−<complexType name="BookInfoType">−<sequence><element maxOccurs="1" minOccurs="0" name="Title" nillable="true" type="xsd:string"/><element maxOccurs=&quo...

want to allow create new web page and edit exiting web page using my web application?
 I am using asp.net 2.0 VS 2005 pro edition. I want to make web application(web form)  where my uses can go and create simple web page or can create page , so then can add page/edit features let me know if some one know , how to do this , any idea, I want to allow my user to create web page and edit web page using my web applications. some one tell me how to do that Note : I dont want to use HTMl editor or any third party software tools thank you maxmax Hello, There is many ways you can implement this. And to build your application you to need to understand the exact ou...

Creating Web Service
Hello everyone, I am creating a new web service, and was wondering what you all thought the advantages and disadvantages of creating it using a Web Site vs using a Web Application Project...thoughts?  Is one better than the other in terms of deployment?  Is one better for development and debugging? Thanks! Hi d_helland, To understand which one is prefer to your situation, please read the following two articles. What's New in Web Projectshttp://msdn2.microsoft.com/en-us/library/f7fb46ye(VS.80).aspx Introduction to Web Application Projectshttp://msdn2.microsoft.com/en...

Web services added as web applications are being converted to web sites
We have a somewhat large solution that we are converting from VS.NET 2003 to 2005 (using web application projects).The conversion has been going very well until recently.  Basically, one of the other developers converted a number of web services to 2005 web services as web applications.  When he loads the solution that contains these projects, it loads and builds fine. Other developers can load the solution successfully and build as well.  When I try to load this solution, VS.NET 2005 checks out the .sln file as well as all of the folders these web service projects reside in.&...

web web web
Name: bahadir Email: sensiz_olmuyor_t1_at_hotmail.com Product: Firefox 2 Beta 2 Summary: web web web Comments: web sayfası yapmak Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; tr; rv:1.8.1b2) Gecko/20060821 Firefox/2.0b2 ...

Web service or Web page?
One client want to communicate with our server. The data is simple. So I think that there are the following solutions to solve this problem. 1. the client use httpwebrequest to send data by get or post method. The server side is a web page. It can parse the request and retrieve data from query. After processing these data, the server send back a response objec to the client. This solution can be used whatever the client is a window application or a web application. The problem is that the server send the whole web page to the client. In order to solve this problem, I use in-line se...

Web resources about - How do I control a service from a web page or web application - asp.net.getting-started

Application - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Pre-Christmas job application rush hits Australian public service
Speed required for pre-Christmas job window opening for public servants. Check out who is hiring.

Cloud application adoption increases 71 percent in 2015
The adoption of cloud applications is soaring, up by 71 percent in the last year according to the results of a new survey. The latest Cloud ...

NASA is accepting astronaut applications, and this quiz will tell you if you qualify
... gone before, then you might want to sign up to be a NASA astronaut. On Dec. 14, for the first time in four years, NASA began accepting applications. ...

MBA: Mortgage Applications Decrease in Latest MBA Weekly Survey, Purchase Applications up 34% YoY
From the MBA: Mortgage Applications Decrease in Latest MBA Weekly Survey Mortgage applications decreased 1.1 percent from one week earlier, ...

German-Based Spirea Promotes Decentralized PV Applications In Uruguay
... Its technical operations specialist, Laurie Lawrence, pointed out that Uruguay [&hellip German-Based Spirea Promotes Decentralized PV Applications ...

Visa application of San Bernardino shooter released
CNN Visa application of San Bernardino shooter released CNN (CNN) The visa application of one of the San Bernardino shooters was released ...

ZTE to develop smartphone application processors in house
ZTE has stepped up its efforts to internally develop smartphone chipset solutions, aiming to re-capture the title as one of the top-three smartphone ...

Pre-K Applications Begin Jan 25, a Month Earlier Than Last Year, City Says
The DOE has moved the process up to Jan. 25 on the heels of a similar schedule shift for kindergarten. MANHATTAN — The application period for ...

NASA accepting applications for the position of 'astronaut'
Wanted ads aren't usually newsworthy, unless the company is NASA and the job is "going to space." The US space agency has started recruiting ...

Resources last updated: 12/23/2015 6:07:50 AM