PC Review


Reply
Thread Tools Rate Thread

Adding text to Service file

 
 
Sunil Jain
Guest
Posts: n/a
 
      9th Jul 2003
Hello Everybody,

Any body knows how to add line to service file in etc
folder, if it is not there.

Sample VB Script for custom action or any other suggestion
are welcomed...

Thanks a lot for your help in advance

Cheers
Sunil
 
Reply With Quote
 
 
 
 
Sunil Jain
Guest
Posts: n/a
 
      10th Jul 2003
Got the VB Script for the same....



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

>-----Original Message-----
>Hello Everybody,
>
>Any body knows how to add line to service file in etc
>folder, if it is not there.
>
>Sample VB Script for custom action or any other

suggestion
>are welcomed...
>
>Thanks a lot for your help in advance
>
>Cheers
>Sunil
>.
>

 
Reply With Quote
 
Sunil Jain
Guest
Posts: n/a
 
      11th Jul 2003
Got the VB Script for the same...


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
>-----Original Message-----
>Hello Everybody,
>
>Any body knows how to add line to service file in etc
>folder, if it is not there.
>
>Sample VB Script for custom action or any other

suggestion
>are welcomed...
>
>Thanks a lot for your help in advance
>
>Cheers
>Sunil
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a record from a text file dhstein Microsoft Access 2 5th Dec 2008 01:54 AM
Adding text to a jpeg file Jerry Spence1 Microsoft VB .NET 1 16th Jun 2006 07:20 AM
Adding text To An Existing Text file................ =?Utf-8?B?TVJM?= Microsoft Access External Data 2 9th May 2005 08:21 PM
Adding text file to CD-R along with the BIN & CUE files Dingo Windows XP General 5 22nd Sep 2004 01:38 AM
Adding text to a text file using an inputbox Proedrsmith Microsoft Excel Programming 3 12th Sep 2003 01:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:54 AM.