Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

windows services for to import the file? 1

Status
Not open for further replies.

bonsky

MIS
Apr 23, 2001
280
US
to all, i have disabled and defined some of the service to auto run. i tried to export these services so that i can import to other machines, yet theres no option to import.. how to do this?

thanks@!
 
Well, thanks for this idea. It was fun to create a script for this and I have added it to the pending release of my Admin Script Pack for my subscribers.

Run the script once on a server to create the master configuration file, then copy that file and the script to the second server and run the script again to duplicate the service Start Modes. The config file will be created wherever you run the script from.

Code:
'==========================================================================
'
' NAME: CloneServices.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.TheSpidersParlor.com[/URL]
' COPYWRITE (c) 2006 All Rights Reserved
' DATE  : 6/3/2006
'
' COMMENT: Run on a server to export/import Service startup modes
' 		 This script and many more are available in the Admin Script Pack
'          by The Spider's Parlor.  [URL unfurl="true"]http://www.TheSpidersParlor.com/vbscript[/URL]
'==========================================================================

Const ForAppending = 8
Const ForReading = 1
Const strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")

Prompt = GetAction()

Select Case Prompt
	Case "1","Import","import","IMPORT"
	    ImportServices
	Case "2","Export","export","EXPORT"
		ExportServices
End Select		

Function ImportServices()
Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
'open the data file
Set oTextStream = objFSO.OpenTextFile("service_list.csv",ForReading)
'make an array from the data file
ServiceList = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each ServiceStr In ServiceList
	On Error Resume Next
	ServiceInfo = Split(ServiceStr,",")
    ServiceName = ServiceInfo(0)
    ServiceStartState = ServiceInfo(1)
    Set objServiceResults = objSWbemServices.Get("Win32_Service.Name=""" & ServiceName & """")
	errReturnCode = objServiceResults.ChangeStartMode(ServiceStartState)
Next
WScript.Echo "Services Configuration Imported"
End Function

Function ExportServices()
	Set objLogFile = objFSO.OpenTextFile("service_list.csv", _ 
	    ForAppending, True)
	strComputer = "."
	Set objWMIService = GetObject("winmgmts:" _
	    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set colListOfServices = objWMIService.ExecQuery _
	        ("Select * from Win32_Service")
	For Each objService in colListOfServices
	    objLogFile.Write(objService.Name) & "," 
	    objLogFile.Write(objService.StartMode) & "," 
	    objLogFile.writeline
	Next
	objLogFile.Close
WScript.Echo "Services Configuration Exported"
End Function

Function GetAction()
	GetAction = InputBox("Do you wish to Import or Export Service Information?" & vbCrLf _ 
         & "1 = Import" & vbCrlf & "2 = Export","Import or Export Service Info?")
End Function

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top