Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear All,

I'm quite new to C#. I made a Windows Form that makes some network changes on a computer. I would like to use it in a Domain env. and would like the domain users to be able to use it without any 'runas'. This is the problem. Domain users don't have privileges to make (for example) IP address changes, but they need to.

My idea is:

- create a Windows Service that makes the IP changes
- the service can run as local system
- I'd like to pass some IP addresses from my Form to Service (ip, mask, gw, dns)


My form works perfectly running with admin privileges. What should I do to be able to use in the mentioned way?

Maybe I should copy all my code to the 'protected override void OnStart(string[] args)' part of the service.cs? But how?

And how can I pass back some args to the Form to inform the user that the changes have been made?

Please help me what to do. A step by step help would be really helpful.

Thanks a lot

Cheers
Posted
Comments
F-ES Sitecore 8-Jun-15 10:07am    
Your best bet is probably to have the windows service host a WCF service and your form will communicate with that WCF service via a service reference. Look into how you create a wcf service, then google how to have a wcf service hosted by a Windows Service.

To pre-empt your next question, no I won't write the code for you, it should all be easily available via google.
DoomMaker79 9-Jun-15 2:02am    
thanks, but if I had found any solution for my problem on Google I'd have used that way... :(
F-ES Sitecore 9-Jun-15 4:02am    
Break it down to its parts then put the parts together, find out how to do a WCF service, find out how to do a Windows Service, then find out how to get a windows service to host a WCF service.

1 solution

I'm writing an example as you requested above.

1. Before adding two numbers we have to create method for adding two numbers in webservice.

Write the following code in Service1.asmx.cs (My webservice name is WebService1).

C#
[WebMethod]

Public int Sum(int a,int b)
       {
           int a,b;
           int sum=a+b;
           return sum;
       }


the above method returning sum, so we get the sum value in Form1.

After that run the WebService1 and copy the service URL from browser. Create the form application then follow the below steps.

1.Solution Explorer>Right Click> Add Service Refrence> Paste the service url> click Ok.
2.Then write the below code in the button click event.

C#
private void ButtonLogin_Click(object sender, EventArgs e)
        {
           int a,b;
           a=Convert.ToInt(textBox1.Text);
           b=Convert.ToInt(textBox2.Text);
           myService.Service1SoapClient client = new Service1SoapClient(); //I renamed the WebService to myService1, while adding in the reference.
          client.ValidateQueryCompleted += new EventHandler<validatequerycompletedeventargs>(client_ValidateQueryCompleted); 
          client.ValidateQueryAsync(a,b);
        }

void client_ValidateQueryCompleted(object sender, ValidateQueryCompletedEventArgs e)
        {
           MessageBox.Show(sum.ToString());
        }

</validatequerycompletedeventargs>
 
Share this answer
 
Comments
johannesnestler 8-Jun-15 10:41am    
OP is talking about a Windows-Service not a Web-Service...
DoomMaker79 9-Jun-15 2:01am    
yes, I gotta use Windows Service w/ Windows Form. So your solution is not working for me... :( by the way, many thanks Sarath

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900