cancel
Showing results for 
Search instead for 
Did you mean: 

Installation Server package event scripting for services file

Former Member
0 Kudos

We have installed the installation server and packaged up SAP Gui 7.10 with the current patch. we have also made use of the event scripting examples and managed to set the package to delete old saplogon.ini files from various locations and install an new saplogon.ini file. There is also a script for removing and adding entries to the services file or replacing the services file completely. As the services file may be used by other applications we do not want to replace the file.

To ensure the package could cope with being installed on a new machine and over old SAP installations we would like to remove all sapdp, sapgw & sapms entries from the services file and re add them from a text file to ensure all entries are correct. Does anyone know if this is possible and how we would go about this?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

If this is not possible, is there another method I can use, the problem is we don't want to copy over the services file and we don't know that they have the same entries in them.

Former Member
0 Kudos

Hi Mathew,<br>

<br>

I have had the same issue as yourself and it took me a good day and a half to get a solution that works nicely. I used code from a couple of VB scripts I found on the web (Google) eventually having to test them in Excel's Visual Basic Editor as I could not effectively debug this in the SAP Installation Server Admin tool even with extensively writing to the logs it was very time consuming having 1st run the installation and then the uninstall .<br>

<br>

Firstly I added this code to the "On Begin Install" tab to ensure that the services file was backup up before SAPGUI install started:

<br>

'====================================================================================================='<br>

'* variants for services file backup<br>

'====================================================================================================='<br>

'*<br>

strFile = NwEngine.Variables.ResolveString("%WinSysDir%\drivers\etc\services")<br>

strFileNew = NwEngine.Variables.ResolveString("%WinSysDir%\drivers\etc\services.SAPGUIinstall")<br>

'*<br>

'*Backup existing services file before install<br>

'*<br>

NwEngine.Context.Log.Write "Event: Backing up file " & Chr(34) & strFile & Chr(34)<br>

<br>

If NwEngine.Shell.FileExist(strFile) Then<br>

NwEngine.Context.Log.Write "Script Action: Backing up services file"<br>

NwEngine.Shell.CopyFile strFile, strFileNew<br>

NwEngine.Context.Log.Write "Script Action: services file backed up"<br>

Else<br>

NwEngine.Context.Log.Write "Script Action: File does not exist " & Chr(34) & strFile & Chr(34)<br>

End if<br>

'*<br>

'====================================================================================================='<br>

<br>

Then on the "On End Uninstall" tab I added the script below. <br>

<br>

FYI FSO = FileSystemObject & OTF = OpenTextFile

<br>

'====================================================================================================='<br>

'* variants for services file backup<br>

'====================================================================================================='<br>

'*<br>

strFile = NwEngine.Variables.ResolveString("%WinSysDir%\drivers\etc\services")<br>

strFileNew = NwEngine.Variables.ResolveString("%WinSysDir%\drivers\etc\services.SAPGUIUninstall")<br>

'*<br>

'*Backup existing services file before install<br>

'*<br>

NwEngine.Context.Log.Write "Event: Backing up file " & Chr(34) & strFile & Chr(34)<br>

<br>

If NwEngine.Shell.FileExist(strFile) Then<br>

NwEngine.Context.Log.Write "Script Action: Backing up services file"<br>

NwEngine.Shell.CopyFile strFile, strFileNew<br>

NwEngine.Context.Log.Write "Script Action: services file backed up"<br>

Else<br>

NwEngine.Context.Log.Write "Script Action: File does not exist " & Chr(34) & strFile & Chr(34)<br>

End if<br>

'*<br>

'====================================================================================================='<br>

<br>

<br>

'====================================================================================================='<br>

'* Script removes all lines from the services file which start with sap.<br>

'====================================================================================================='<br>

'*<br>

<br>

NwEngine.Context.Log.Write "Event: Removing lines from services file"<br>

<br>

'* Declare Variables<br>

'strFile = services & is declared above<br>

strMatch = "sap"<br>

Dim arrOTF<br>

Dim intOTF<br>

Dim strOTF<br>

'*<br>

Dim objFSO<br>

Set objFSO = CreateObject("Scripting.FileSystemObject")<br>

Dim objOTF<br>

'*<br>

'* Open file for reading<br>

'*<br>

If objFSO.FileExists(strFile) Then<br>

Set objOTF = objFSO.OpenTextFile(strFile, 1)<br>

strOTF = objOTF.ReadAll()<br>

Set objOTF = Nothing<br>

'*<br>

'* Split file into an array by lines CrLF<br>

'*<br>

arrOTF = Split(strOTF, vbCrLf)<br>

strOTF = ""<br>

For intOTF = 0 To UBound(arrOTF)<br>

If Left(arrOTF(intOTF), 3) = strMatch Then 'if string starts with sap remove from file read line into log<br>

NwEngine.Context.Log.Write "Script Action: Removing line "& Chr(34) & arrOTF(intOTF)& Chr(34) <br>

Else<br>

strOTF = strOTF & arrOTF(intOTF) & vbCrLf<br>

End If<br>

Next<br>

'*<br>

'* Write new string (less those starting with sap) back into services file<br>

'*<br>

Set objOTF = objFSO.OpenTextFile(strFile, 2, True)<br>

objOTF.WriteLine (strOTF)<br>

Set objOTF = Nothing<br>

Else<br>

NwEngine.Context.Log.WriteWarning "Event: Could not open the file " & Chr(34) & strFile & Chr(34)<br>

End If<br>

'*<br>

Set objFSO = Nothing<br>

<br>

NwEngine.Context.Log.Write "Event: END Modifying the file " & Chr(34) & strFile & Chr(34)<br>

<br>

'====================================================================================================='

<br>

Hope that this helps, as it frustrated me no end researching and getting this to work as expected from the /nodlg /uninstall command!<br>

<br>

Cheers<br>

Vaughan Rae<br>

Snr Basis Consultant <br>

Melbourne VIC<br>

Australia<br>

Edited by: Vaughan Rae on Aug 25, 2009 8:47 AM

Edited by: Vaughan Rae on Aug 25, 2009 9:08 AM

Edited by: Vaughan Rae on Aug 26, 2009 4:57 AM

Edited by: Vaughan Rae on Aug 26, 2009 5:04 AM

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks for you help

Matt

Former Member
0 Kudos

Hi, This script works perfectly, I just have one query. On install where is it getting the gateway / message server details from? It seems to have missed out some entries that were obsolete.

Thanks

Former Member
0 Kudos

Morning Mathew, <br>

<br>

Sorry, i have re-edited the post above as I copied the wrong portion. Am I not sure why it is not removing the legacy components can't analyse this without seeing the logs, the full script or the orginal services file before and after.<br>

<br>

Please note that i have changed the above script can you re copy it to the "On End Uninstall" and redeploy the SAPEXE? How are you running the uninstall? <br>

<br>

On the front end machine i simply type Z:\GUI_InstServer\Setup\GUI_Deploy\SAPGUI_710_SP13_Vers_0_1.exe /nodlg<br>

then<br>

Z:\GUI_InstServer\Setup\GUI_Deploy\SAPGUI_710_SP13_Vers_0_1.exe /nodlg /uninstall<br>

<br>

Z:\ being a mapped drive to the administering Installation Server<br>

<br>

As you know the sapgui installation automatically adds all the sapdp00-99 & sapms00-99. In my 'On End Install' scripts I appended the sapms "sid" "port"/tcp that are required for this client. The "On End Uninstall" only removes those lines starting with sap as you can tell by the code. Here is what I have for the "On End Install" <br>

<br>

'====================================================================================================='<br>

'* Distributes saplogon.ini<br>

'====================================================================================================='<br>

NwEngine.Context.Log.Write "Event: Copying customized SapLogon.ini Start"<br>

<br>

'*<br>

'* New saplogon.ini to be deployed variables<br>

'*<br>

<br>

strSrcFile = NwEngine.Variables.ResolveString("
"host"\sapmnt\GUI_InstServer\Setup\CustomerFiles\saplogon.ini")<br>

strDstFile = NwEngine.Variables.ResolveString("%WinDir%\saplogon.ini")<br>

<br>

'*<br>

'* Existing saplogon.ini to be backed up<br>

'*<br>

<br>

strFile = NwEngine.Variables.ResolveString("%WinDir%\saplogon.ini")<br>

strFileNew = NwEngine.Variables.ResolveString("%WinDir%\saplogon.ini.SAPGUIinstall")<br>

<br>

'*<br>

'* backup existing saplogon.ini file if it exists<br>

'*<br>

<br>

If NwEngine.Shell.FileExist(strFile) Then<br>

NwEngine.Context.Log.Write "Script Action: Backing up existing saplogon.ini file"<br>

NwEngine.Shell.CopyFile strFile, strFileNew<br>

NwEngine.Context.Log.Write "Script Action: Existing saplogon.ini file backed up"<br>

Else<br>

NwEngine.Context.Log.Write "Script Action: An existing File does not exist " & Chr(34) & strFile & Chr(34) & "!"<br>

End If<br>

<br>

'*<br>

'* Copy changed ini file from installation server location<br>

'*<br>

<br>

If NwEngine.Shell.FileExist(strSrcFile) Then<br>

NwEngine.Shell.CopyFile strSrcFile, strDstFile<br>

Else<br>

NwEngine.Context.Log.WriteWarning "WARNING Event: Unable to copy source saplogon.ini"<br>

End If<br>

'*<br>

<br>

NwEngine.Context.Log.Write "Event: Copying customized SapLogon.ini Finished"<br>

<br>

'====================================================================================================='<br>

'* appends message servers to c:\windows\system32\drivers\etc\services file<br>

'====================================================================================================='<br>

<br>

NwEngine.Context.Log.Write "Event: START appending lines in the services file"<br>

'*<br>

'* Set Variable for appending sapms entries in services file<br>

'*<br>

Set objTextFile = CreateObject("NwSapSetupATLCommon.TextFileParser")<br>

strServFile = NwEngine.Variables.ResolveString("%WinSysDir%\drivers\etc\services")<br>

'*<br>

If objTextFile.Parse(strServFile) Then<br>

NwEngine.Context.Log.Write "Event: Modify the file " & Chr(34) & strServFile & Chr(34)<br>

If objTextFile.DoesStringExist("sapmsR1E 3600/tcp") Then<br>

NwEngine.Context.Log.Write "Script Action: sapmsR1E exists"<br>

Else<br>

NwEngine.Context.Log.Write "Script Action: sapmsR1E 3600/tcp appended"<br>

objTextFile.AppendLine "sapmsR1E 3600/tcp"<br>

End If<br>

'*<br>

'* Next sapms entry<br>

'*<br>

If objTextFile.DoesStringExist("sapmsE1E 3600/tcp") Then<br>

NwEngine.Context.Log.Write "Script Action: sapmsE1E exists"<br>

Else<br>

NwEngine.Context.Log.Write "Script Action: sapmsE1E 3600/tcp appended"<br>

objTextFile.AppendLine "sapmsE1E 3600/tcp"<br>

End If<br>

objTextFile.Save (strServFile)<br>

Else<br>

NwEngine.Context.Log.WriteWarning "Event: Could not open the file " & Chr(34) & strServFile & Chr(34)<br>

End If<br>

<br>

NwEngine.Context.Log.Write "Event: FINISHED editing services file"<br>

<br>

'====================================================================================================='<br>

From these scripts you effective write all essentail actions to the logs in C:\Program Files\SAP\SapSetup\LOGs Makes analysing issues much more simplier. All files are backed up before they are changed for versioning and preservation of data BEFORE any changes are made. <br>

<br>

Let me know if you have any further questions.<br>

<br>

Cheers<br>

Vaughan<br>

Edited by: Vaughan Rae on Aug 26, 2009 4:07 AM

Edited by: Vaughan Rae on Aug 26, 2009 5:05 AM