/build/static/layout/Breadcrumb_cap_w.png

Services File

Hi all,

Currently I am trying to get to vbscripts one to amend to the Service file, but to check to see if the entry is there first. Then the other to remove the entry on an uninstall.

So far I have the following to amend to it, not sure if its the best way. But seems to work.

'On Error Resume Next
Const ForRead = 1 '*Opens file for reading
Const ForWriting = 2 '*Opens file for writing, overwriting file
Const ForAppend = 8 '*Opens file for Appending

strComputer = "." '* This computer
'* Connect to the WMI Service
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'* Open the host File
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO.OpenTextFile("C:\winnt\System32\Drivers\Etc\services", ForRead)
Set objFile2 = objFSO.CreateTextFile("C:\winnt\System32\Drivers\Etc\tempservices")
Dim boolFound
boolFound = False

objFSO.Copyfile "C:\winnt\System32\Drivers\Etc\services", "C:\winnt\System32\Drivers\Etc\services.BKUP"

Do Until objFile1.AtEndOfStream
'* Read line from input file
strLine = objFile1.ReadLine
If instr(strLine, "gds_db") then
strLine=Replace("strLine, strLine, # InterBase Server")
boolFound = True
End If
objFile2.Writeline strLine
Loop

If boolFound = False then
objFile2.Writeline "gds_db 3050/tcp # InterBase Server"
End If
objFSO.Copyfile "C:\winnt\System32\Drivers\Etc\tempservices", "C:\winnt\System32\Drivers\Etc\services"
objFile1.Close
objFile2.Close



If someone could point me in the right direction that would be great, the remove of the entry is the main thing I am having a problem with.

Cheers all

0 Comments   [ + ] Show comments

Answers (2)

Posted by: anonymous_9363 15 years ago
Red Belt
0
You could use the script you have as a template for your removing script. Better yet, you could have one script with both functions, but I digress.

The essential difference is that you would read each line from the source file and, if the searched for text isn't found, write the line to the temporary file. If it is found, ignore that line.

BTW, in scripting as with any development, learn to be paranoid: assume nothing will work, even your object creation. The most important thing on that note here is that when you've finished writing the file, open it up again and make sure the text got entered/removed.
Posted by: aogilmor 15 years ago
9th Degree Black Belt
0
there have been a number of scripts posted over the past few years dealing with this task, you may want to have a look at the search.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ