VBA to perform commands on remote servers

G

GLT

Hi,

This is probably going to require some extremely complicated programming,
but here goes:

I have a list of servers and workstations (and Services) which require a
start command issued every morning. I currently log into each system and
perform this task manually.

I have now put this data into a table and run a query on it, I wanted to
know if there is a VBA way to:

(a) issue this command for each server/workstation and the associated
services in my table - the command is as follows:

sc //myServer Start myServicename

(b) record the results that (ie successful start or failure) into a seperate
table.

Any assistance is always greatly appreciated. Note the sc command is
normally issued via the cmd window.

Cheers,
GLT.
 
S

Stefan Hoffmann

hi,

This is probably going to require some extremely complicated programming,
but here goes:
See

http://msdn.microsoft.com/en-us/library/ms685141(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms686315(VS.85).aspx

or

http://msdn.microsoft.com/en-us/library/aa393960(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa393263(VS.85).aspx

E.g. using early binding:

Public Sub TestWMI()

Dim Locator As WbemScripting.SWbemLocator
Dim Services As WbemScripting.SWbemServices
Dim Service As WbemScripting.SWbemObject

Set Locator = New WbemScripting.SWbemLocator
Set Services = Locator.ConnectServer

Services.Security_.ImpersonationLevel = _
wbemImpersonationLevelImpersonate

For Each Service In Services.Get("Win32_Service").Instances_
Debug.Print "Name:" & vbTab & vbTab & vbTab & Service.Name
Debug.Print "DisplayName:" & vbTab & Service.DisplayName
Debug.Print "StartMode:" & vbTab & vbTab & Service.StartMode
Debug.Print "State:" & vbTab & vbTab & vbTab & Service.State
Debug.Print "---"
Next Service

End Sub
sc //myServer Start myServicename
Why don't you use an autostarting service?



mfG
--> stefan <--
 
G

GLT

Hi Stefan,

Thanks for you reply - these services are automatically started - we check
them every morning and them start them if they have stopped.

There is a report generated that i have found that lists these services
accross different servers that are not running, so my DB imports this file
and now I'd like to automate the restart process.

I'm not quite sure how the code works below, but I will ask around at work
tomorrow and see if anyone can help me understand it a little better...

Cheers,
GLT.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top