Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stopping and starting Windows Services?
Message
 
À
09/12/2004 14:05:37
Scott Malinowski
Arizona Fox Software LLC
Arizona, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00968069
Message ID:
00968085
Vues:
24
>Greetings!
>
>Has anyone ever stopped and started a windows service from inside their VFP application? We have a need to do this with a service developed in C#/dotnet and my search has drawn a blank so far.
>
>Thanks for any information you can provide!

You can use WMI or LDAP, the WMI code would look like this:

I will separate this into two functions, the first one to get the Service Object
function getServiceObject(tcService)
local lcService, loService, loLocator, loWMI

if Vartype(tcService) # 'C' or Empty(tcService)
	return null
endif

lcService	= Alltrim(tcService)

try
	loLocator	= createObject("wbemScripting.SwbemLocator")
	loWMI		= loLocator.ConnectServer()
	loService	= loWMI.Get("Win32_Service.Name='" + lcService + "'")
catch
	loService	= null
endtry

return loService
Now we can do a small program to manage the service
local loService

loService	= getServiceObject('IISAdmin')
if not isnull(loService)

	* Now we can send commands to it
	* for starting IIS:
	loService.StartService()

	* for stopping IIS
	loService.StopService()

	* for pausing IIS
	loService.PauseService()

	* and for resuming IIS
	loService.ResumeService()
endif
* Of course you will need to test the status and check for errors, but this is the basic code you need using WMI
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform