technical architecture.

Maxscript: Checking a remote Service’s Status

by 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!

:, ,

2 Comments for this entry

  • elfin

    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

  • Dave Buchhofer

    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. has one way to do it in there, set up to handle multiple servers at once

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!