#! c:\perl\bin\perl.exe #--------------------------------------------------------- # service.pl # Retrieves information on services from NT/2K systems # # usage: [perl] service.pl [host] [> services.csv] # # Copyright 2000/2001 H. Carvey keydet89@yahoo.com #--------------------------------------------------------- use strict; use Win32::Lanman; my(@state) = ("", "Stopped", "Start_Pending", "Stop_Pending", "Running", "Continue_Pending", "Pause_Pending", "Paused"); my(@startup) = ("", "", "Automatic", "Manual", "Disabled"); my $server = shift || Win32::NodeName; \usage(); my @services; if (Win32::Lanman::EnumServicesStatus("\\\\$server","", &SERVICE_WIN32,&SERVICE_STATE_ALL,\@services)) { foreach my $service (@services) { my %info; if (Win32::Lanman::QueryServiceConfig("\\\\$server","",${$service}{name},\%info)) { # print "Display Name : ${$service}{display}\n"; # print "Service Name : ${$service}{name}\n"; # print "State : ".$state[${$service}{state}]."\n"; # print "Service Account: $info{account}\n"; # print "Filename : $info{filename}\n"; # print "Startup : ".$startup[$info{start}]."\n\n"; print "${$service}{display},${$service}{name},$state[${$service}{state}],"; print "$info{account},$info{filename},$startup[$info{start}]\n"; } else { my $err = Win32::FormatMessage Win32::Lanman::GetLastError(); $err = Win32::Lanman::GetLastError() if ($err eq ""); print "Error in QueryServiceConfig: $err\n"; } } } else { my $err = Win32::FormatMessage Win32::Lanman::GetLastError(); $err = Win32::Lanman::GetLastError() if ($err eq ""); print "Error in EnumServicesStatus: $err\n"; } sub usage { print "\nService -- retrieve service information from an NT system.\n\n"; print "Usage: service.pl [system] \n"; print "System is optional...defaults to localhost.\n"; print "Output is comma-delimited text, suitable for opening in Excel.\n"; print "Example usage: service.pl > services.csv print "\n"; }