VBScript to edit txt based files.
Let me start by saying this is obviously not directly a DSM.OPT file, but a script that modify's our notes.ini file. I could be easily modified, however to edit any text based file.
##############################################
'Declare Var
on error resume next
Const ForReading = 1
Const ForWriting = 2
dim strFileName
dim strOldText
dim strNewText
dim strtext
dim count
dim strUserName
'Set network object: Only needed because we are using editing files in the user profile.
Set objNetwork = WScript.CreateObject("WScript.Network")
strUserName = objNetwork.UserName
'wscript.echo strUserName
'1st instance
'Checks to see if file we want to modify exist. In our case we are looking in multiple locations and trying to find the file. In your case one check will probably be good unless you don't know where your DSM.OPT file is; which is a different problem.
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\documents and settings\" & strUserName & "\local settings\application data\lotus\notes\data\notes.ini") Then
'wscript.echo "The file exists."
strFileName = "C:\documents and settings\" & strUserName & "\local settings\application data\lotus\notes\data\notes.ini"
'wscript.echo strFileName
Else
'Wscript.Echo "The file does not exist, notes.ini not found!"
End If
If objFSO.FileExists("C:\documents and settings\" & strUserName & ".arthur\local settings\application data\lotus\notes\data\notes.ini") Then
'wscript.echo "The file exists."
strFileName = "C:\documents and settings\" & strUserName & ".arthur\local settings\application data\lotus\notes\data\notes.ini"
'wscript.echo strFileName
Else
'Wscript.Echo "The file does not exist, notes.ini not found!"
End If
If objFSO.FileExists("c:\program files\IBM\Lotus\Notes\notes.ini") Then
'wscript.echo "The file exists."
strFileName = "c:\program files\IBM\Lotus\Notes\notes.ini"
Else
'Wscript.Echo "The file does not exist."
End If
If objFSO.FileExists("c:\Lotus\Notes\notes.ini") Then
'wscript.echo "The file exists."
strFileName = "c:\Lotus\Notes\notes.ini"
Else
'Wscript.Echo "The file does not exist, notes.ini not found!"
End If
If objFSO.FileExists("C:\Program Files (x86)\IBM\Lotus\Notes\notes.ini") Then
'wscript.echo "The file exists."
strFileName = "C:\Program Files (x86)\IBM\Lotus\Notes\notes.ini"
Else
'Wscript.Echo "The file does not exist, notes.ini not found!"
End If
if strFileName = "" then
Wscript.Echo "The file does not exist, notes.ini not found!"
wscript.quit
End if
'If the file does exist here we open the file and read the entire file into memory.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
'Here I define what strings I want to replace. As you can see we are commenting out certain strings in this example.
strOldText1 = "AddInMenus=NCMenu"
strNewText1 = ";AddInMenus=NCMenu"
strOldText2 = "EXTMGR_ADDINS=NCExtMgr"
strNewText2 = ";EXTMGR_ADDINS=NCExtMgr"
strOldText3 = "EXTMGR_ADDINS=adpwdextad"
strNewText3 = ";EXTMGR_ADDINS=adpwdextad"
strOldText4 = "NSF_HOOKS=NLNVP"
strNewText4 = ";NSF_HOOKS=NLNVP"
'This step is where all the magic happens, and we replace the first defined string. I'm also doing a quick check to see if the file has already been commented out. In that case I do nothing. Else I replace the text. (obviously w/o this check every time it runs it would find the string and add another semicolon) I repeat this process 4 times for each of the defined strings that I want to replace. This could be done as many times as needed.
If InStr(strText, strNewText1) Then
'wscript.echo ("Found " & strNewText1)
else
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText1 = Replace(strText, strOldText1, strNewText1)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.WriteLine strNewText1
objFile.Close
end if
If InStr(strText, strNewText2) Then
'wscript.echo ("Found " & strNewText2)
else
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText2 = Replace(strText, strOldText2, strNewText2)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.WriteLine strNewText2
objFile.Close
end if
If InStr(strText, strNewText3) Then
'wscript.echo ("Found " & strNewText3)
else
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText3 = Replace(strText, strOldText3, strNewText3)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.WriteLine strNewText3
objFile.Close
end if
If InStr(strText, strNewText4) Then
'wscript.echo ("Found " & strNewText4)
else
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText4 = Replace(strText, strOldText4, strNewText4)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.WriteLine strNewText4
objFile.Close
end if
##########################################################
Thats it, Hope this helps.