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

Service Login -- API to Change it?

I'd like to write a C# program that can change the login for a service
that's already installed. I'm wondering if there is an API to use for that.
I'm familiar with ServiceController, but I don't see a way to use it.

Is it possible?

If so, how should I approach it?

Thanks,
Steve Harclerode
Nov 15 '05 #1
7 4599
I you talk about Web Service you probably can implement HttpModule with you
login method.

"Camel Software" <Ca***************@hotmail.com> wrote in message
news:eY*************@TK2MSFTNGP12.phx.gbl...
I'd like to write a C# program that can change the login for a service
that's already installed. I'm wondering if there is an API to use for that. I'm familiar with ServiceController, but I don't see a way to use it.

Is it possible?

If so, how should I approach it?

Thanks,
Steve Harclerode

Nov 15 '05 #2
Sorry, I guess I should have said that I'm talking about a Windows Service,
not a web service.

- Steve

"Maxim Kazitov" <mv*****@tut.by> wrote in message
news:eV**************@TK2MSFTNGP11.phx.gbl...
I you talk about Web Service you probably can implement HttpModule with you login method.

"Camel Software" <Ca***************@hotmail.com> wrote in message
news:eY*************@TK2MSFTNGP12.phx.gbl...
I'd like to write a C# program that can change the login for a service
that's already installed. I'm wondering if there is an API to use for

that.
I'm familiar with ServiceController, but I don't see a way to use it.

Is it possible?

If so, how should I approach it?

Thanks,
Steve Harclerode


Nov 15 '05 #3
ChangeServiceConfig (or ChangeServiceConfig2)
AdvApi32.dll

-Rob Teixeira [MVP]

"Camel Software" <Ca***************@hotmail.com> wrote in message
news:eY*************@TK2MSFTNGP12.phx.gbl...
I'd like to write a C# program that can change the login for a service
that's already installed. I'm wondering if there is an API to use for that. I'm familiar with ServiceController, but I don't see a way to use it.

Is it possible?

If so, how should I approach it?

Thanks,
Steve Harclerode

Nov 15 '05 #4
Use the System.Management classes with the WMI Win32_Service class to change
service properties.
Check the Platform SDK -Windows Management Instrumentation for details.

Here's a sample...

public static int ChangeService(string Name, string Password, string
serviceName)
{
ManagementBaseObject inParams = null;
ManagementObject srvc = new ManagementObject("Win32_Service=" + "\"" +
serviceName + "\"");
inParams = srvc.GetMethodParameters("Change");
inParams["StartName"] = Name; //account name .\\localaccount;
domain\\domainaccount (or account@somedomain on XP and up)
inParams["StartPassword"] = Password; // password
ManagementBaseObject outParams = srvc.InvokeMethod("Change", inParams,
null);
return System.Convert.ToInt32(outParams.Properties["ReturnValue"].Value);
}
}

Willy.
"Camel Software" <Ca***************@hotmail.com> wrote in message
news:eY*************@TK2MSFTNGP12.phx.gbl...
I'd like to write a C# program that can change the login for a service
that's already installed. I'm wondering if there is an API to use for
that.
I'm familiar with ServiceController, but I don't see a way to use it.

Is it possible?

If so, how should I approach it?

Thanks,
Steve Harclerode

Nov 15 '05 #5
Thank you! Is WMI the recommended method to do this sort of thing now? Rob
mentioned ChangeServiceConfig(), but I'm guessing that someday it will be
considered the "old" way.

- Steve

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Use the System.Management classes with the WMI Win32_Service class to change service properties.
Check the Platform SDK -Windows Management Instrumentation for details.

Here's a sample...

public static int ChangeService(string Name, string Password, string
serviceName)
{
ManagementBaseObject inParams = null;
ManagementObject srvc = new ManagementObject("Win32_Service=" + "\"" + serviceName + "\"");
inParams = srvc.GetMethodParameters("Change");
inParams["StartName"] = Name; //account name .\\localaccount;
domain\\domainaccount (or account@somedomain on XP and up)
inParams["StartPassword"] = Password; // password
ManagementBaseObject outParams = srvc.InvokeMethod("Change", inParams,
null);
return System.Convert.ToInt32(outParams.Properties["ReturnValue"].Value); }

Nov 15 '05 #6
Thanks, this is exactly what I was looking for.

- Steve

"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:O8**************@TK2MSFTNGP10.phx.gbl...
ChangeServiceConfig (or ChangeServiceConfig2)
AdvApi32.dll


Nov 15 '05 #7
WMI is a framework to provide for unified and remote (and neat scriptable)
system administration and management.
There is overhead in using WMI vs. a native Windows export function, but I
don't think either will entirely supplant the other. They both have their
advantages, and I don't see either going away any time soon.

-Rob Teixeira [MVP]

"Camel Software" <Ca***************@hotmail.com> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
Thank you! Is WMI the recommended method to do this sort of thing now? Rob
mentioned ChangeServiceConfig(), but I'm guessing that someday it will be
considered the "old" way.

- Steve

Nov 15 '05 #8

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

Similar topics

3
by: Stanley J, Mroczek | last post by:
My disk was replaced and i reload all my software. I think that i named my computer best-si-01 instead of BEST-SI-01 and thats my error? Login failed for user 'NT AUTHORITY\NETWORK SERVICE'....
3
by: Jeremy S. | last post by:
On my dev machine (XP/Pro with VS.NET 2003) I have been developing a Windows Service and installing it on the local machine by opening the Visual Studio Command Prompt and then executing . Now I...
8
by: Coy | last post by:
I've added the ASPNET user to my local SQL Server 2000, but I still get an unhandled exception: Login failed for user 'C594891-A\ASPNET'. This is when using a web service. A similiar ASP.NET...
1
by: MAL | last post by:
Hello, I have 2 classes that work great as a windows app to retrieve and process data from an Oracle9i db. When I implement them in a Service program running as Local System, it fails on the...
3
by: Evan Camilleri | last post by:
I have a problem for a Windows Service to login on an SQL server (different machine) - neither Windows Authentication nor SQL Authentication worked. LOGIN FAILED FOR USER sa (for example). If...
3
by: GTDriver | last post by:
I'm trying to connect my application with a web service located on my own web server(localhost). I guess when the solution/proect is built it makes a file called 'Web...
3
by: JL | last post by:
I have a VB.NET desktop program that reads/writes data to a server using a Java-based Web Service. This web service, in identical formats, is located on several servers with each server being a...
0
by: Naveen Kumar Srivastava | last post by:
Hi , I am trying to change the log on property of MSSQLSERVER and restart it. From c# code i change the log on property of this service 1 : I make a new usser account and give it the...
0
by: s.kapitza | last post by:
Hi, try M$S servicebug 3 regards s.kapitza alghaden@alumni.fdu.edu (Ahmad) wrote in message news:<4a75f4b7.0308080649.49105373@posting.google.com>...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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.