Link

This is an example vbscript to add entries to C:\Windows\System32\drivers\etc\Services

And to also remove just those entries with a deinstall(and no other, even if they were added after the msi was installed).

It's really easy to adjust it so it works with other files.

The idea is that during installation you also install a file called "AdditionsToServicesTable" in C:\Windows\System32\drivers\etc\ that holds all the info that you want added to the services file.

Than make sure that after the installation the AppendToServicesTable.vbs is run, and that at uninstall the RestoreServicesTable.vbs is run.

------------AppendToServicesTable.vbs------------

Option Explicit

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim targetfile

Dim input

Dim objFSO

Dim objTextFile

Dim target

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set targetfile = objFSO.GetFile("C:\WINDOWS\system32\drivers\etc\services")

Set input = objFSO.GetFile("C:\WINDOWS\system32\drivers\etc\AdditionsToServicesTable")

' Voeg de inhoud van SapAdditionsToServicesTable toe aan Services.

' Er dient aan het eind van Services of aan het begin van

' SapAdditionsToServicesTable een lege regel te staan.

Set objTextFile = objFSO.OpenTextFile (input, ForReading)

Set target = CreateObject("Scripting.FileSystemObject")

Set targetFile = target.OpenTextFile (targetfile, ForAppending, True)

Do Until objTextFile.AtEndOfStream

input = objTextFile.Readline

targetFile.WriteLine(input)

Loop

targetFile.Close

ObjTextFile.close

------------AppendToServicesTable.vbs------------

------------RestoreServicesTable.vbs------------

Option Explicit

Dim ServicesTabel, ServicesFile

Dim AddOn, AddOnFile

Dim Dest, DestFile

Dim Input, Input2

Dim objFSO

Set objFSO = CreateObject("Scripting.FileSystemObject")

'de huidige services file

Set ServicesTabel = CreateObject("Scripting.FileSystemObject")

Set ServicesFile = ServicesTabel.OpenTextFile("C:\WINDOWS\system32\drivers\etc\services", 1)

'het toegevoegde deel aan de originele services file

Set AddOn = CreateObject("Scripting.FileSystemObject")

Set AddOnFile = AddOn.OpenTextFile("C:\WINDOWS\system32\drivers\etc\AdditionsToServicesTable", 1)

'Het resultaat komt in de nieuwe services tabel.

Const ForAppending = 8

Set Dest = CreateObject("Scripting.FileSystemObject")

Set DestFile = Dest.OpenTextFile("C:\WINDOWS\system32\drivers\etc\result.txt",ForAppending, True)

Input2 = AddOnFile.ReadLine

Do Until ServicesFile.AtEndOfStream

Input = ServicesFile.ReadLine

'We lopen door het services bestand totdat we een match tegenkomen.

Do Until AddOnFile.AtEndOfStream

if not(Input=Input2) then

'Wegschrijven van de regel.

destfile.WriteLine(Input)

else

Input2 = AddOnFile.ReadLine

end if

Input = ServicesFile.ReadLine

loop

'Wanneer we door de AddOn lijst zijn gelopen, weten we dat de rest later aan de

'Services tabel is toegevoegd,... dus alles wegschrijven naar Dest.

if not(Input=Input2) then

'Wegschrijven van de regel.

DestFile.WriteLine(Input)

end if

Loop

DestFile.Close

servicesFile.Close

AddOnFile.Close

Set ServicesFile = objFSO.GetFile("C:\WINDOWS\system32\drivers\etc\services")

Set DestFile = objFSO.GetFile("C:\WINDOWS\system32\drivers\etc\result.txt")

Set AddOnFile = objFSO.GetFile("C:\WINDOWS\system32\drivers\etc\AdditionsToServicesTable")

'verwijder de oude Servicestabel.

ServicesFile.delete

'Hernoem result.txt naar Services.

DestFile.move ("C:\WINDOWS\system32\drivers\etc\services")

'verwijder de AdditionsToServicesTable file, deze is niet meer nodig.

AddOnFile.delete

FILES=110 in CONFIG.NT zetten

ConfigNT.vbs

Option Explicit

'Dit bestand zet FILES=110 in CONFIG.NT

Const ForReading = 1, ForWriting = 2

Dim Gedaan

Dim fso

Dim RdLineTextFile

Dim f1

Dim f2

Set fso = CreateObject("Scripting.FileSystemObject")

Set f1 = fso.OpenTextFile("c:\windows\system32\config.nt", ForReading)

Set f2 = fso.CreateTextFile("c:\windows\system32\config.bak", True)

Gedaan = False

RdLineTextFile = f1.ReadLine

do while not f1.AtEndOfStream

if left(ucase(rdLinetextfile),5) = "FILES" then

if trim(mid(rdLinetextfile, Instr(rdLinetextfile, "=") +1,100)) < 110 then

rdlinetextfile = "FILES = 110"

Gedaan = True

end if

end if

f2.WriteLine(rdLinetextfile)

RdLineTextFile = f1.ReadLine

loop

if not Gedaan then

f2.WriteLine("FILES = 110")

end if

f1.close

f2.close

set f1 = fso.GetFile("c:\windows\system32\config.nt")

f1.delete

set f2 = fso.GetFile("c:\windows\system32\config.bak")

f2.copy ("c:\windows\system32\config.nt")

------------RestoreServicesTable.vbs------------

source: http://www.repackaging.nl/html/overigen.html