Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win32 Services Question 1

Status
Not open for further replies.

soy4soy

IS-IT--Management
May 22, 2000
100
US
Is there a way I am alter the "Log On As" feature of a Win32 service via Perl?

Goal: I have a couple hundred servers that run SQL service as an account in my domain. That account has become corrupt and I must change all of my servers to reflect this new account and password.

Ideally, I'd like to utilize Perl to run through these services and change the "Log On As" account for all the SQL-related services.

I have found nothing that speaks to this thus far. Any help would be GREATLY appreciated!

Thanks in advance!
 
I don't know of a pure perl implementation to configure winows services, but I have successfully embedded a windows utility into a perl script to accomplish this. The utility is called sc.exe. It is actually very useful and has lots of features. It will create, delete, start, stop, and configure services among a few things.


system("sc.exe config Ingres_Database obj= LocalSystem password= VENUS");

Just call it with the system command. You can embed it any way you like in perl. I combined it with the win32::spawn command so that I could get a pid on the configure and wait for it to finish configuring before executing the next line in the script. Here is a snippet of how I used it:

$app = "c:\\temp\\scnt.exe";
$cmd = "c:\\temp\\scnt.exe config Ingres_Database obj= LocalSystem password= VENUS";
if(Win32::Spawn($app,$cmd,$Pid2)) {
print "Configuring Ingres Service...\n\n";
} else {
print "Installation aborted because of ";
die "error:" . Win32::FormatMessage(Win32::GetLastError());
}
waitpid($Pid2,0)


One thing to be aware of. There are two different versions that go by the same name. One is found on Windows NT. The other is found on Windows 2000 and Windows XP. The 2k/xp version will not work on NT, but I have found that the NT version will work on 2k/xp. So I just rounded up an old NT copy and use that exclusively for all my boxes.
 
Wow, this looks like a very cool util. I don't have the scnt.exe that you reference, but I do have sc.exe on my W2k machine (in a resource kit that *might* be for NT 4.0). But I am trying to config services on NT 4.0 systems and you said that this would not work. Is there a way I can tell which one I have?

When I try to run this line from the command line:

sc \\remote_server config SQLServerAgent obj=DOMAIN\sqlsvc password=sqlsvcpass

I get this back:

Modifies a service entry in the registry and Service Database.
SYNTAX:
sc config [service name] <option1> <option2>...
CONFIG OPTIONS:
NOTE: The option name includes the equal sign.
type= <own|share|interact|kernel|filesys|rec|adapt|error>
start= <boot|system|auto|demand|disabled|error>
error= <normal|severe|critical|error|ignore>
binPath= <BinaryPathName>
group= <LoadOrderGroup>
tag= <yes|no>
depend= <Dependencies(separated by / (forward slash))>
obj= <AccountName|ObjectName>
DisplayName= <display name>
password= <password>

Any ideas here? I really do appreciate this. I once thought I was pretty sharp, but Windows seems to have that knack of taking me down a few pegs! lol
 
BAH!!! I hate that syntax! i just needed a space to the right of the = signs!

Thanks raklet!
 
Sorry, I forgot to rename scnt.exe It is actually only sc.exe but is the Windows NT version. I needed to have both NT and 2K versions available in the same folder for testing, so I renamed one to scnt.exe.

Here is the version information for each file. You can find this by right clicking on the file and viewing properties.

sc.exe (Windows NT) version 4.0.1371.1 (This is the one I named scnt.exe)
sc.exe (Windows 2K,XP) version 5.1.2600.0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top