I just want to check whether the following line
sqlserv 118/tcp #SQL Services has in my service file or not. if the line exists i need to close the file.if the line doesn't exist then need to add the line. i can suceesfully add the line. but if line exists i'm not suppose to do that. any help will be really appreciated...
0 Comments   [ + ] Show Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.


Write a VB Script to read the lines and search for sqlserv (if unique in the entire text file)

Dim objFSO, objTextFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("<FilePath>", 1)

strLines = objTextFile.ReadAll

If instr(1, strLines, "sqlserv") <> 0 then
Set objTextFile = objFSO.OpenTextFile("<FilePath>", 8)
objTextFile.Write ("sqlserv 118/tcp")
End If

Set objFSO = Nothing
Answered 05/10/2011 by: murali.bhat
Purple Belt

Please log in to comment
- As usual in these things, there is no error-trapping at all in the script
- It won't perform the required operation if it encounters text like "# Remind SQL DBAs to set correct port for 'sqlserv' machine"

@OP, change the 'ReadAll' usage into a loop that uses 'ReadLine' and then add a check that the first 7 characters are 'sqlserv' and then check that the trailing characters are 'TCP/118'. Or, better, avoid re-inventing the wheel and download one of the quadzillion scripts which have already been written for this express purpose.
Answered 05/11/2011 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity