Way, way easier to do it in the
registry.
Small subroutine to do it on a remote
machine.
use Win32::Registry; # Use
the Registry module
#****************************************************************************************************
#* *
#* StopChnage( Host, Service) Subroutine. This subroutine will change the start condition *
#* of Serive on the Host to SERVICE_DEMAND_START, 3, from whatever it was at before *
#* *
#****************************************************************************************************
sub StopChange
{
my $host=shift(); # Host name passed as argument.
my $service=shift(); # Sevice name passed as argument.
my $status=0; # Status initialized to zero.
my $registryobject=0; # Registryobject initialized to zero.
my $keypath="System\\CurrentControlSet\\Services\\".$service; # Keypath initialized.
my $keyobject; # Keyobject declared.
my $data="" Data initialized to zero.
my $datatype=0; # Datatype initialized.
#* *
#* StopChnage( Host, Service) Subroutine. This subroutine will change the start condition *
#* of Serive on the Host to SERVICE_DEMAND_START, 3, from whatever it was at before *
#* *
#****************************************************************************************************
sub StopChange
{
my $host=shift(); # Host name passed as argument.
my $service=shift(); # Sevice name passed as argument.
my $status=0; # Status initialized to zero.
my $registryobject=0; # Registryobject initialized to zero.
my $keypath="System\\CurrentControlSet\\Services\\".$service; # Keypath initialized.
my $keyobject; # Keyobject declared.
my $data="" Data initialized to zero.
my $datatype=0; # Datatype initialized.
if($HKEY_LOCAL_MACHINE->Connect( $host, $registryobject)){ # Connect to registry on host to get object registryobject.
if($registryobject->Open($keypath, $keyobject)){ # Open the registry at keypath and get keyobject.
if($keyobject->QueryValueEx("Start", $datatype, $data)){ # Get the value of START registry entry
if($data!=3){ # If the value is NOT 3(NOT demand_start).
if($keyobject->SetValueEx("Start", 0, $datatype, 3)){ # Set the value to 3.
print("$keypath\\Start updated to SERVICE_DEMAND_START\n"); # If successful, print to console.
$status=1; # Set the return value to 1.
}else{
print("Unable to update $keypath\\Start to SERVICE_DEMAND_START\n"); # If unsuccessful, write to console.
}
}
}else{
print("Could not read from registry $keypath\\Statr\n"); # If QueryValueEx failed, write to console.
}
$keyobject->Close(); # Close keyobject.
}else{
print("Error opening registry key $keypath on $host\n"); # If the registry at keypath could not be opened, write to console.
}
$registryobject->Close(); # Close registryobject.
}else{
print( "Error connecting to registry of $host\n"); # If connect to registry on host failes, write to console.
}
return $status; # Return from subroutine.
}
-----Original Message-----
From: Dave Roth [mailto:[EMAIL PROTECTED]
Sent: Friday, July 25, 2003 11:54 AM
To: Patrick J. LoPresti; John Serink
Cc: [EMAIL PROTECTED]
Subject: RE: stop service, reschedule start after rebootWMI may be a bit much to do this but I agree...don't even try doing this in the registry!!You could try using Win32::Lanman or Win32::Daemon. They both have functions to do exactly this.
From: [EMAIL PROTECTED] on behalf of Patrick J. LoPresti
Sent: Thu 7/24/2003 8:28 PM
To: John Serink
Cc: [EMAIL PROTECTED]
Subject: Re: stop service, reschedule start after reboot"John Serink" <[EMAIL PROTECTED]> writes:
> Go directly to the registry and change the service start parameter
> to auto start.
It is cleaner to use WMI than to hack the registry directly. See
<http://unattended.sourceforge.net/apps.html#startup-type> for a Perl
script which does this.
Run it as "startup-type.pl automatic MyService" to set the startup
type of MyService to automatic.
- Pat
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
