Background: SAP system will be modified and a change is required in the Windows services file on all domain computers. I am not a programmer, but can tinker and understand the basics. Essentially, I am a danger to myself and all around me when I play with code lol
What I would like to accomplish is for this script to search for the following text within the windows services file:
sapmsPUB XXXXXX
sapmsPDB XXXXXX
sapmsUP2 XXXXXX
sapmsQDB XXXXXX
sapmsDDB XXXXXX
Where (xxxxxx) would be any existing services port on that line
If found, I would like to delete those lines and insert these at the bottom of the services file followed by two blank lines
sapmsPUB 3605/tcp
sapmsPDB 3602/tcp
sapmsUP2 3600/tcp
sapmsQDB 3602/tcp
sapmsDDB 3600/tcp
BLANK LINE
BLANK LINE
The script should only run once. I am guessing this can be accomplished through the use of something such as service.ack file. Once script executes, create a new file service.ack. If service.ack exists, go to end type scenario.
What I have below is a horrid abomination of code, but this will search the services file for a single string sapmspub, if found, delete the entire line. It will then insert the necessary services at the end of the file followed by two blank lines. What I am missing is a way to search for the additional lines to be deleted. such as sapmsddb, sapmsqdb, sapup2, and sapmspdb. I am also missing the creation of a service.ack file in C:\Windows\System32\drivers\etc\services which, if exists, will cause the script to exit without modifying.
I am open to any and all suggestions. Thanks!
What I would like to accomplish is for this script to search for the following text within the windows services file:
sapmsPUB XXXXXX
sapmsPDB XXXXXX
sapmsUP2 XXXXXX
sapmsQDB XXXXXX
sapmsDDB XXXXXX
Where (xxxxxx) would be any existing services port on that line
If found, I would like to delete those lines and insert these at the bottom of the services file followed by two blank lines
sapmsPUB 3605/tcp
sapmsPDB 3602/tcp
sapmsUP2 3600/tcp
sapmsQDB 3602/tcp
sapmsDDB 3600/tcp
BLANK LINE
BLANK LINE
The script should only run once. I am guessing this can be accomplished through the use of something such as service.ack file. Once script executes, create a new file service.ack. If service.ack exists, go to end type scenario.
What I have below is a horrid abomination of code, but this will search the services file for a single string sapmspub, if found, delete the entire line. It will then insert the necessary services at the end of the file followed by two blank lines. What I am missing is a way to search for the additional lines to be deleted. such as sapmsddb, sapmsqdb, sapup2, and sapmspdb. I am also missing the creation of a service.ack file in C:\Windows\System32\drivers\etc\services which, if exists, will cause the script to exit without modifying.
I am open to any and all suggestions. Thanks!
Code:
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Windows\System32\drivers\etc\services", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine, "sapmspub")= 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile("C:\Windows\System32\drivers\etc\services", ForWriting)
objFile.Write strNewContents
objFile.Close
set fs = CreateObject("Scripting.FileSystemObject")
set file = fs.opentextfile("C:\Windows\system32\drivers\etc\services.", 8)
file.writeline "sapmsPUB 3605/tcp"
file.writeline "sapmsPDB 3602/tcp"
file.writeline "sapmsUP2 3600/tcp"
file.writeline "sapmsQDB 3602/tcp"
file.writeline "sapmsDDB 3600/tcp"
file.writeline ""
file.writeline ""
file.close