Windows Service export in text file

September 13, 2014 6:40 pm Published by

Di seguito uno script che esegue l’export in un file di testo di tutti i servizi Windows. Testato con Windows 7.

Set fso = CreateObject("Scripting.FileSystemObject")

'Costante nome file da generare
file_name = "C:\export_servizi.txt"

If not fso.FileExists (file_name) then 
  
  'Creo il file
  fso.CreateTextFile (file_name)

  'Istanzio l'oggetto OggFile al relativo file creato
  Set OggFile = fso.GetFile (file_name)

  'Istanzion l'oggetto OggTextStream 
  Set OggTextStream = OggFile.OpenAsTextStream(2)

  
  OggTextStream.WriteLine "Export Data: " & Now()


   set objWMIService = GetObject("winmgmts:\\.\root\cimv2") 
   set colItems = objWMIService.ExecQuery("Select * from Win32_Service",,32)
   for each objItem in colItems

        OggTextStream.WriteLine "***********************************************"
        OggTextStream.WriteLine "service_name = " & objItem.Name
	OggTextStream.WriteLine "service_description = " & objItem.Description 
	OggTextStream.WriteLine "service_display_name = " & objItem.DisplayName 	 
	OggTextStream.WriteLine "service_path_name = " & objItem.PathName 
	OggTextStream.WriteLine "service_started = " & objItem.Started 
	OggTextStream.WriteLine "service_start_name = " & objItem.StartName 
	OggTextStream.WriteLine "service_start_mode = " & objItem.StartMode 
	OggTextStream.WriteLine "service_state = " & objItem.State 

   next

   

  'Chiudo il file
  OggTextStream.Close

  Msgbox ("Creato File '" & file_name & "'.")  

else

  Msgbox ("File '" & file_name & "' giĆ  esistente, impossibile crearlo.")  

end if

Categorised in: ,

This post was written by admin

Comments are closed here.