Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

INSERT_LINES_SERVICES


1 reply to this topic

sk_jain2000

sk_jain2000
  • Members
  • 8 posts

Posted 10 July 2003 - 13:41

VB Script for INSERTING LINES IN SERVICES FILE.......



Dim varLine1 'Variable to store the current value to be written
Dim varLine2 'Variable to store the current value to be written
Dim varLine3 'Variable to store the current value to be written
Dim varLine4 'Variable to store the current value to be written

'Defining the value of each line to be searched and written
varLine1="gds_db 3050/tcp"
call InsertValues(varLine1)

varLine2="hds_db 3050/tcp"
call InsertValues(varLine2)

varLine3="ids_db 3050/tcp"
call InsertValues(varLine3)

varLine4="kds_db 3050/tcp"
call InsertValues(varLine4)


'InsertValues function will search value passed as varibale and if not found it will write this variable at end of file.
Sub InsertValues(varLine)

Dim varFileLines 'Variable to store the curretly read line
Dim sFlag 'Varaiable to store the flag value
Dim WshShell 'Object pointing to the WScript

'Initializing the WScript object
Set WshShell = CreateObject("WScript.shell")
'System root
SysRoot = WshShell.ExpandEnvironmentStrings("%SystemRoot%")
'File Path
sFileName = SysRoot & "\system32\drivers\etc\services"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(sFileName, 1)

sFlag = "False" 'Assumption the search string is not found

'looping through the services file
Do Until objFile.AtEndOfStream
varFileLines = objFile.ReadLine
If Trim(varFileLines) = varLine Then
sFlag = "True" 'Search string is found
Exit Do 'Quiting the loop
End If
Loop

'Closing the object
Set objFile = Nothing

'Checking for the flag
If Trim(sFlag) = "False" Then
'Writing the line since the search string is not found in the file
Set objFile = objFSO.OpenTextFile(sFileName, 8)
objFile.WriteLine varLine
End If

Set objFile = Nothing

End Sub


Cheers
Sunil Jain

ewwallace

ewwallace
  • Members
  • 20 posts

Posted 06 February 2004 - 16:24

Nice, thanks for the example script.

However, it might be a bit of overkill. Either you could trim the script down a little bit, or just create a file with the values you want to add and append it to the original (e.g. "
CODE
type append.txt >>C:\WINDOWS\system32\drivers\etc\services
").

~ewall