Maxscript: Checking a remote Service’s Status
by Dave Buchhofer on Aug.11, 2008, under .net, maxscript
here’s a little snippet to check the status of a service on a remote server. used as part of a little farm management utility that I’m updating to run with the 64bit stuff and experimenting with the net framework.
fn checkService ServiceName server =
(
dotnet.loadassembly "System.ServiceProcess"
sc = dotNetObject "System.ServiceProcess.ServiceController"
if (server == "") do server = "." -- if no server is supplied, run the check on the local machine
sc.Machinename = server
try(scServices = sc.GetServices(server))catch(return "Timed Out")
for scTemp in scServices do
(
if (scTemp.ServiceName as string == ServiceName) then
(
--print ( ServiceName + " - " + server + " - " +scTemp.Status.toString() )
return scTemp.Status.ToString()
)
)
return "Service Not found"
)Thanks Chris Evans for the maxscript syntax highlighting!












July 5th, 2010 on 1:35 am
Hello, can you give an example of using this function please. I have some troubles using the code.
Renderfarm is in domain, with login\password
Thanks!
July 6th, 2010 on 7:24 am
I’ve actually had some issues with it also, it works, but the timeout is really long, and it didn’t handle failed connections very well, so I’ve moved on to just using the pstools exe psservice, and calling that with a doscommand instead.
http://buchhofer.com/2009/06/serverutilities-v8/ has one way to do it in there, set up to handle multiple servers at once