Win32 api, remote admin type stuff

I'm looking at writing some C++ code to help with remote administration of NT servers.  I am familar with C, and not sure if I need to learn more about C++ in order to develope some utilities.  I have some Perl scripts that I would like to replace with custom C/C++ routines for things like:  retrieving a list of drives and free space on a remote NT server; check remote servers services to verify "automatic/started" status.  I know there is a resource kit utility for the service stuff, but I would still like to try to develop some of these for myself.  Sample code would be great, but even some pointers on "read up on rpc", "read up on dcom", "no, you can't do this without some additional tools" would help.  Thank you.
b_crosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
At least regarding the services this can be done easily:

The services API (and 'OpenSCManager()' in particular) take a machine name as a parameter that can be used to specify the target computer.

But I also don't have a clue on the drive space issue...
0
ZizzerCommented:
Here's a C++ snippet you can use to start a service on a remote computer.  Stopping a service or checking status is very similar.

class AutoSCHandle {
public:
      AutoSCHandle(SC_HANDLE handle);
      ~AutoSCHandle();
      operator SC_HANDLE() const;
protected:
      SC_HANDLE m_handle;
};

AutoSCHandle::AutoSCHandle(SC_HANDLE handle)
      : m_handle(handle)
{
}

AutoSCHandle::~AutoSCHandle()
{
      BOOL flag = CloseServiceHandle(m_handle);
      if (!flag)
            THROW(HRESULT_FROM_WIN32(GetLastError()));
}

AutoSCHandle::operator SC_HANDLE() const
{
      return m_handle;
}

void StartService(LPCTSTR computer, LPCTSTR service)
{
            // open service control manager on target machine
      AutoSCHandle hSCM = OpenSCManager((LPCTSTR) computer, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT);
      if (hSCM == NULL)
            THROW(HRESULT_FROM_WIN32(GetLastError()));

            // open the requested service
      AutoSCHandle hService = OpenService(hSCM, service, SERVICE_START | SERVICE_QUERY_STATUS);
      if (hService == NULL)
            THROW(HRESULT_FROM_WIN32(GetLastError()));

            // start the service
      BOOL flag = StartService(hService, 0, NULL);
      if (!flag)
            THROW(HRESULT_FROM_WIN32(GetLastError()));

            // wait until the service is finished starting
      SERVICE_STATUS status;
      do {
            Sleep(100);
            flag = QueryServiceStatus(hService, &status);
            if (!flag)
                  THROW(HRESULT_FROM_WIN32(GetLastError()));
      } while (status.dwCurrentState == SERVICE_START_PENDING);
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
b_crosAuthor Commented:
The information provided was excellent, but I didn't really get an answer to the remote disk information.  Thanx.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.