Mark Minasi's Reader Forum
Mark Minasi's Reader Forum
Home | Profile | Register | Active Topics | Active Polls | Members | Search | FAQ | Minasi Forum RSS Feed
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 HALP! Questions on Windows and Windows Server
 Scripting
 Lotus notes
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Bbacoyiannis
Old Timer

Canada
495 Posts
Status: offline

Posted - 11/25/2011 :  12:25:50 AM  Show Profile  Visit Bbacoyiannis's Homepage  Click to see Bbacoyiannis's MSN Messenger address  Reply with Quote
We are migrating from xp to win7, would anyone know how to transfer the required lotus notes client data files to anew system for an automated install of a new notes client?

Bill Bacoyiannis
Director of Technology
Justaskbill.net

Playwell
Honorable But Hopeless Addict

Netherlands
4822 Posts
Status: offline

Posted - 11/25/2011 :  04:08:48 AM  Show Profile  Visit Playwell's Homepage  Click to see Playwell's MSN Messenger address  Reply with Quote
You have to look in the notes.ini for each user.

You'd typically install lotus notes, point the shortcut to each user's ini file. The ini file probably have to be adapted to fit in the new Win7 environment.

'People who think they know everything are a great annoyance to those of us who do. '
Quote by Isaac Asimov


Go to Top of Page

cj_berlin
Honorable But Hopeless Addict

Germany
3964 Posts
Status: offline

Posted - 11/27/2011 :  02:17:43 AM  Show Profile  Visit cj_berlin's Homepage  Look at the Skype address for cj_berlin  Reply with Quote
USMT claims to migrate Notes settings for certain versions.

Evgenij Smirnov
Go to Top of Page

netmarcos
Honorable But Hopeless Addict

USA
2219 Posts
Status: offline

Posted - 11/28/2011 :  1:08:32 PM  Show Profile  Visit netmarcos's Homepage  Click to see netmarcos's MSN Messenger address  Look at the Skype address for netmarcos  Send netmarcos a Yahoo! Message  Reply with Quote
My experience with Notes supports Evgenij's claim. Often there is a need to "mess with" the Notes.ini file. The following is a script that can create/modify/delete keys or sections in the Notes.ini file. All of the cool setup bits are in the Function LoadNFix(ByRef sFileSpec). The rest of it does the hard work.


'********************************************************************************
'* File: NotesIniFix
'* Created:March 2006
'* Version:1.0
'*
'* Main Functions: Makes changes to several keys in the notes.ini file
'*
'* Required files: Notes.ini
'*
'********************************************************************************
Option Explicit
Dim oIni 'Object representing the ini file class
Set oIni = New clsIniFile
Dim oWshShell
Set oWshShell = CreateObject("WScript.Shell")
Dim objFSO
Set objFSO = CreateObject("Scripting.FilesystemObject")

Dim sFileSpec
Dim sDataPath
Dim sSection
Dim sKey
Dim sFlag

sFileSpec 		= "H:\NotesData\notes.ini"
sDataPath		= "H:\NotesData"
sSection 		= "Notes"
sFlag = False
On Error Resume Next
While Not sFlag
Call LoadNFix(sFileSpec)
Wend


Function LoadNFix(ByRef sFileSpec)
Dim sAction
Dim InitFSearch
Dim objFSearch
Set objFSearch = CreateObject("UserAccounts.CommonDialog")

objFSearch.Filter = "Ini Files|*.ini|All Files|*.*"

objFSearch.FilterIndex = 3

objFSearch.InitialDir = "H:\NotesData"

If objFSO.FileExists(sFileSpec) Then
		sFlag = True
		'*** Load the ini file into memory...
		oIni.LoadFile(sFileSpec)
		sKey = "EXTMGR_ADDINS" 
		oIni.DeleteKey sSection,"EXTMGR_ADDINS"
		sKey = "Directory"
		oIni.SetValue sSection,"Directory",sDataPath
		sKey = "FileDlgDirectory"
		oIni.SetValue sSection,"FileDlgDirectory",sDataPath 
		sKey = "SPELL_DIR"
		oIni.SetValue sSection,"SPELL_DIR",sDataPath
		oIni.SaveFile(sFileSpec) 
	oWshShell.Popup sFileSpec & " successfully modified.",,WScript.ScriptName,64
Else 
	sAction = oWshShell.Popup("Script could not locate " & sFileSpec & vbCrLf & _
						 "Please click OK to browse to the correct path: ",,"Notes.ini not found",1+48)
	If sAction = 1 Then
		InitFSearch = objFSearch.ShowOpen
		If InitFSearch = False Then
			BugAssert False, "No valid file name recieved or the operation was cancelled by the user."
		Else
		    sFileSpec = objFSearch.FileName
		End If 
	Else 
		WScript.Quit
	End If
End If		
	
End Function

Function ChooseFile
  Set f = CreateObject("SAFRCFileDlg.FileOpen")
  f.OpenFileOpenDlg
  ChooseFile f.FileName
  Set f = Nothing
End Function 



' ================================================
' ================================================
' A WSH INI (INITIALIZATION) FILE CLASS OBJECT ===
' ================================================
' ================================================
'
' Acknowledgment: vbParadise provided the "model" (as vb Code)
'   for this utility.  However this is not a one-for-one translation
'   of the vbParadise code.  It was almost entirely re-written,
'   to conform with the ideosyncracies of vbScript,
'   (and my own ideosyncracies as well)...
'
' --- Revision History ---------------------------
' 20May02: Initial Attempt.
' 22May02: added code to deal with comments.
' 26May02: revised search pattern, to better detect blank lines,
'    (courtesy sFulton of wsh ng)...
' 03July02: repaired typing mistake...
' 06July02: repaired EnumKeys (was returning comment lines)...
' 04Feb03: allowed for "commenting out" key=value pair.  (thx to: j. ruzewski)
' 11Sept03: repaired DeleteKey (vielen Dank, Herr Doktor Reeg)...
' 20Sept03: added the "tab suppression" feature...
' --- end of revisions ---------------------------

Class clsIniFile

' "class level" variables
Private c_bDebug  ' as boolean
Private c_sMe  ' for debugging messages...
'
Private c_oRE  ' as object (regexp)
Private c_oDB  ' as object (dictionary)
Private c_sLines  ' as collection (ini file lines)
'
Private c_sBuffer  ' as string (holds entire "resource")
Private c_iLine  ' as integer (holds pointer to NEXT line of text)
'
Private ptnIniLine  ' as string (pattern for line split)
Private ptnSecHeader  ' as string (pattern for section header)
Private sEmpty  ' as string
'
Private i,j  ' as integer (for use as loop indexes)
Private c_sComment  ' as string
Private c_sPreamble  ' as string

Dim sFileSpec



' --- end of declarations and constants ----------


  ' ----------------------------------------------
  ' --- ADD / DELETE SECTION ---------------------
  ' ----------------------------------------------

  Public Function AddSection(sSectionName)  ' returns a boolean value
  Dim saBlank(1,0)  ' as string array

    ' if there is an existing section by this name, then punt...
    if c_oDB.Exists(sSectionName) then
      AddSection = False : Exit Function
    End If

    ' this is a new section name, so add it to dic (er, database)...
    saBlank(0,0) = sEmpty : saBlank(1,0) = sEmpty  ' make up dummy key/value pair array
    c_oDB.Add sSectionName, saBlank

    AddSection = True  ' return success value
  End Function

  Public Function DeleteSection(sSectionName)  ' returns a boolean value

    ' if there is NO section by this name, then punt...
    if NOT c_oDB.Exists(sSectionName) then
      DeleteSection = False : Exit Function
    End If

    ' delete this section...
    c_oDB.Remove(sSectionName)

    DeleteSection = True  ' return success value
  End Function



  ' ----------------------------------------------
  ' --- ADD / DELETE KEY (w/corresponding value) -
  ' ----------------------------------------------

  Public Function AddKey(sSection, sKey, sValue)  ' returns a boolean value
  Const sMe = "[cIni:AddKey], "
  Dim saKeyValuePairs  ' as string array (key/value pairs)
  Dim cItems  ' as integer
  Dim saNewKeyValuePairs()  ' as string array
  Dim sLastKey, sLastValue  ' as string(s)

    ' if there is NO section by this name, then punt...
    if NOT c_oDB.Exists(sSection) then
      AddKey = False : Exit Function
    End If

    saKeyValuePairs = c_oDB(sSection)  ' retrieve key/value pairs
    if IsArray(saKeyValuePairs) then  ' test valid array of key/value pairs
      cItems = UBound(saKeyValuePairs, 2) + 1  ' add one to expand array
        if c_bDebug then dbPrint sMe & "cItems in section: " & CStr(cItems-1) & "/" & sSection

      ' create a new string array...
      ReDim saNewKeyValuePairs(1,cItems)

      ' copy the existing key/value pairs...
      For j = 0 to cItems -1
        saNewKeyValuePairs(0,j) = saKeyValuePairs(0,j)
        saNewKeyValuePairs(1,j) = saKeyValuePairs(1,j)
      Next  ' j

      ' add the new key/value pair at end,
      '   (note: if last key/value is comment, then insert AHEAD of the comment)...
      sLastKey = saKeyValuePairs(0,cItems -1)
      sLastValue = saKeyValuePairs(1,cItems -1)
        if c_bDebug then dbPrint sMe & "sLastKey/sLastValue: " & sLastKey & "/" & sLastValue

      ' test for comment line or blank line...
      if sLastKey = c_sComment then  ' test for comment line...

        saNewKeyValuePairs(0,cItems -1) = sKey
        saNewKeyValuePairs(1,cItems -1) = sValue
        ' dbPrint "[], added: " & CStr(cItems -1) & "/" & sKey & "/" & sValue

        saNewKeyValuePairs(0,cItems) = sLastKey  ' tack on the blank/comment
        saNewKeyValuePairs(1,cItems) = sLastValue

      Else  ' last key/value NOT blank/comment...

        saNewKeyValuePairs(0,cItems) = sKey  ' add new key/value to end...
        saNewKeyValuePairs(1,cItems) = sValue
      End If  ' blank/comment test



    Else  ' not a valid array, so make one...

      cItems = 0  ' zero means one, in zero-based arrays
      ReDim saNewKeyValuePairs(1,cItems)

      saNewKeyValuePairs(0,cItems) = sKey  ' add new key/value to end...
      saNewKeyValuePairs(1,cItems) = sValue

    End If  ' valid array test


    ' replace the key/value pairs in the DB...
    c_oDB.Item(sSection) = saNewKeyValuePairs

    AddKey = True
  End Function


  Public Function DeleteKey(sSection, sKey)  ' returns a boolean value
  Const sMe = "[cIni:DeleteKey], "
  Dim saKeyValuePairs  ' as string array (key/value pairs)
  Dim cItems  ' as integer

    ' if there is NO section by this name, then punt...
    if NOT c_oDB.Exists(sSection) then
      DeleteKey = False : Exit Function
    End If

    saKeyValuePairs = c_oDB(sSection)  ' retrieve key/value pairs
    if NOT IsArray(saKeyValuePairs) then  ' test no key/value pairs
      DeleteKey = False : Exit Function
    End If

    cItems = UBound(saKeyValuePairs, 2)
      if c_bDebug then dbPrint sMe & "cItems in section: " & CStr(cItems) & "/" & sSection

    ' search for the sKey entry, in this string array...
    For j = 0 to cItems

      if saKeyValuePairs(0,j) = sKey then  ' found it!

        ' set this key/value to empty (rather than REALLY deleting it)...
        saKeyValuePairs(0,j) = sEmpty
        saKeyValuePairs(1,j) = sEmpty

        ' update the section contents, as held in the DB...
        c_oDB.Item(sSection) = saKeyValuePairs  ' (vielen Dank, Herr Doktor Reeg)

        DeleteKey = True  ' return success value
        Exit Function
      End If
    Next  ' j

    ' at this point you searched through all the keys,
    '   without finding the designated sKey value, so TILT!
    DeleteKey = False
  End Function


  ' ----------------------------------------------
  ' --- ENUM SECTIONS (return string array) ------
  ' ----------------------------------------------

  Public Function EnumSections()

    EnumSections = c_oDB.Keys  ' Keys method returns a string array...
  End Function

  ' ----------------------------------------------
  ' --- ENUM KEYS (return string array) ----------
  ' ----------------------------------------------

  Public Function EnumKeys(sSection)
  Const sMe = "[cInI:EnumKeys], "
  Dim saKeyValuePairs  ' as string array (key/value pairs)
  Dim saReturn()  ' as string array
  Dim cItems, cActual  ' as integer

    saKeyValuePairs = c_oDB(sSection)  ' retrieve key/value pairs
      BugAssert (IsArray(saKeyValuePairs)), sMe & "no key/value pairs for this section: " & sSection
    cItems = UBound(saKeyValuePairs, 2)
      if c_bDebug then dbPrint "[cIni:EnumKeys], cItems in section: " & CStr(cItems) & "/" & sSection

    cActual = 0
    ReDim saReturn(cItems)  ' includes actual items (plus any comment lines)...
    For j = 0 To cItems
      if saKeyValuePairs(0,j) <> c_sComment then
        saReturn(cActual) = saKeyValuePairs(0,j)
        cActual = cActual + 1
      End If
    Next
    ReDim Preserve saReturn(cActual - 1)
    EnumKeys = saReturn  ' set return (string array)
  End Function



  ' ----------------------------------------------
  ' --- GET / SET VALUE --------------------------
  ' ----------------------------------------------

  Public Function GetValue(sSection, sKey)
  Const sMe = "[cIni:GetValue], "
  Dim saKeyValuePairs  ' as string array
  Dim cItems  ' as integer
  Dim sThisKey, sThisValue

    if c_bDebug then dbPrint sMe & "sSection/sKey is: " & sSection & "/" & sKey

    ' get the section's key/value pairs array...
    saKeyValuePairs = c_oDB(sSection)  ' retrieve associated item (a string array)
      BugAssert (IsArray(saKeyValuePairs)), sMe & "no key/value pairs for this section: " & sSection & " / " & sKey

    cItems = UBound(saKeyValuePairs, 2)
      if c_bDebug then dbPrint sMe & "cItems: " & CStr(cItems)
      BugAssert (cItems >= 0), sMe & "internal error: no key/value pairs for this section: " & sSection & " / " & sKey

    ' lookup the value for this key...
    For j = 0 to cItems
      sThisKey = saKeyValuePairs(0,j)
      sThisValue = saKeyValuePairs(1,j)
      ' dbPrint sMe & "sThisKey/sThisValue: " & sThisKey & "/" & sThisValue

      if sThisKey = sKey then  ' found it!
        GetValue = sThisValue  ' set return value
        Exit Function
      End If
    Next  ' j

  ' use bugassert to throw an error...
  BugAssert False, sMe & "could not find value for: " & sSection & "/" & sKey
  End Function


  Public Function SetValue(sSection, sKey, sNewVal)  ' returns a boolean value
  Const sMe = "[cIni:SetValue], "
  Dim saKeyValuePairs  ' as string array
  Dim cItems  ' as integer
  Dim sThisKey, sThisValue

    if c_bDebug then dbPrint sMe & "sSection/sKey is: " & sSection & "/" & sKey

    ' get the section's key/value pairs array...
    saKeyValuePairs = c_oDB(sSection)  ' retrieve associated item (a string array)
      BugAssert (IsArray(saKeyValuePairs)), sMe & "no key/value pairs for this section: " & sSection & " / " & sKey

    cItems = UBound(saKeyValuePairs, 2)
      if c_bDebug then dbPrint sMe & "cItems: " & CStr(cItems)
      BugAssert (cItems >= 0), sMe & "internal error: no key/value pairs for this section: " & sSection & " / " & sKey

    ' lookup the value for this key...
    For j = 0 to cItems
      sThisKey = saKeyValuePairs(0,j)

      ' if c_bDebug then dbPrint sMe & "sThisKey/sThisValue: " & sThisKey

      if sThisKey = sKey then  ' found it!
        saKeyValuePairs(1,j) = sNewVal  ' set new value (in temp array)
        ' replace the key/value pairs in the DB...
        c_oDB.Item(sSection) = saKeyValuePairs
        Exit Function
      End If
    Next  ' j

  ' use bugassert to throw an error...
  BugAssert False, sMe & "could not find matching key for: " & sSection & "/" & sKey
  End Function


  ' ----------------------------------------------
  ' --- LOAD INI FILE INTO "DATABASE" ------------
  ' ----------------------------------------------

  Public Sub LoadFile(sFileSpec)
  Const sMe = "[cIni:LoadFile], "
  '
  Dim c_colSections  ' as collection of sections...
  Dim c_colLines  ' as collection of lines...
  '
  Dim sSectHeader  ' as string (section header, inc brackets)
  Dim cSectHeader  ' as integer (char count of section header)
  Dim sSectKey  ' as string (DB key for this section)
  '
  Dim iHeaderIndex, iKeyValuePairs, iNextHeader, iLength
  Dim sKeyValuePairs  ' as string (all key/value pairs for this section)
  Dim saKeyValueLines  ' as string array
  Dim cKeyValuePairs  ' as integer (count of keyValue lines)
  '
  Dim saKeyValues()  ' as string array (stores key/value pairs in db)
  '
  Dim iBkt, iEq  ' as integer
  Dim sKey, sValue  ' as string
  '
  Const sDummyLine = "#DummyLine#"



    BugAssert (varType(sFileSpec) = vbString), sMe & "Load Arg error (not string)"

    c_sBuffer = ReadFile(sFileSpec)  ' read in the ENTIRE ini file into memory...

    ' add a dummy section header, to allow for finding the end-of-file,
    '  (yes, yes, I know -- it's an UGLY HACK!)...
    c_sBuffer = c_sBuffer & "[dummy_EndOfFile]" & vbCrLf

    ' --------------------------------------------
    ' Use RegExp to "enumerate" the section headers
    ' --------------------------------------------
    ptnSecHeader = "\[(\w+)\]" & vbCrLf
    With c_oRE : .Pattern = ptnSecHeader  ' set search parameters...
      ' set case INsensitive, search for ANY occurance, only THIS line...
      .IgnoreCase = True : .Global = True : .Multiline = False : End With

    Set c_colSections = c_oRE.Execute(c_sBuffer)  ' execute search
      BugAssert (c_colSections.Count >= 1), c_sMe & "Internal Error (no sections in ini file)"

      if c_bDebug then dbPrint sMe & "Found Section Count of: " & CStr(c_colSections.Count)



    ' --------------------------------------------
    ' Deal with "Preamble" if any.  Note: any initial comments
    '   appearing BEFORE the first section header, are given
    '   separate treatment here.  They are NOT processed,
    '   just set aside for later...
    ' --------------------------------------------
    ' MsgBox(CStr(c_colSections(0).FirstIndex))

    ' if the first section header has an index > 0,
    '   then that implies that there IS a "preamble".
    if (c_colSections(0).FirstIndex > 0)  then
      ' extract the "preamble" for later...
      c_sPreamble = Left(c_sBuffer, c_colSections(0).FirstIndex)
    End If



    ' --------------------------------------------
    ' Build a (yes) primitive database, where the "sec" (key)
    '   holds the section name, and the key/value pairs for the
    '   section are stored in a string array...
    ' --------------------------------------------

    ' for each section, make an entry in the database...
    For i = 0 to c_colSections.Count - 2  ' should be -1 (also acct for U.H.)
      ' dbPrint c_sMe & c_colSections(i)  ' sLines(i)
      sSectHeader = c_colSections(i)  ' inc brackets and vbCrLf
      iHeaderIndex = c_colSections(i).FirstIndex
        ' dbPrint sMe & sSectHeader & ", index: " & iHeaderIndex  ' sLines(i)

      ' the section key is surrounded by square brackets, remove them...
      cSectHeader = Len(sSectHeader)

      iBkt = Instr(sSectHeader, "]")
      sSectKey = Mid(sSectHeader, 2, iBkt -2)

      ' advance beyond the section header, to start of keyvalue pairs...
      iKeyValuePairs = iHeaderIndex + cSectHeader + 1

      iNextHeader = c_colSections(i+1).FirstIndex
      iLength = iNextHeader - iHeaderIndex - cSectHeader
        ' if c_bDebug then dbPrint sMe & "iNextHeader/iLength: " & CStr(iNextHeader) & "/" & CStr(iLength)

      ' cut out the key/value pairs for this section...
      sKeyValuePairs = Mid(c_sBuffer, iKeyValuePairs, iLength)
        ' if c_bDebug then dbPrint sMe & sKeyValuePairs

      ' ------------------------------------------
      ' Use (old-fashioned) split here, to separate the lines in this section...
      ' ------------------------------------------
      cKeyValuePairs = -1  ' initialize flag (to indicate empty string)...

      if (sKeyValuePairs <> sEmpty) then  ' if NOT empty, then split it...

        ' ----------------------------------------
        ' Troubles in Splitsville.  Using split with vbCrLf as delimiter
        '   doesn't work -- er, well, it does work but returns an "extra line".
        '   Why is that?  Can't answer that one.  My best guess is that split
        '   if subject to the "csv paradigm", that is, "if-there-is-a-delimiter,
        '   then-it-MUST-BE-followed-by-another-value (even if there is nothing
        '   there).  I came up with a couple of "work arounds".  You could
        '   remove the last vbCrLf.  That works.  Or, you could also add a
        '   "dummy line", which gets removed later.  That works too.
        '   I chose the latter method...
        ' ----------------------------------------
        sKeyValuePairs = sKeyValuePairs & sDummyLine

        saKeyValueLines = Split(sKeyValuePairs, vbCrLf)
          ' if c_bDebug then dbPrint sMe & sKeyValuePairs
        cKeyValuePairs = UBound(saKeyValueLines) -1  ' remove dummy line
          ' if c_bDebug then if c_bDebug thendbPrint sMe & CStr(cKeyValuePairs)
      End If


      if UBound(saKeyValueLines) >= 0 then  ' test for any key/value pairs in this sect...

        ' ----------------------------------------
        ' Create a 2-Dimensional string array,
        '   to hold the key/value pairs for this section...
        ' ----------------------------------------
        ReDim saKeyValues(1, cKeyValuePairs)

        For j = 0 to cKeyValuePairs
          if c_bDebug then dbPrint sMe & "j /line: " & CStr(j) & "/" & saKeyValueLines(j)

          iEq = InStr(saKeyValueLines(j), "=")

          If (Left(saKeyValueLines(j),1) = ";") then  ' test for comment line FIRST

            sKey = c_sComment  ' comment flag
            sValue = saKeyValueLines(j)

            saKeyValues(0,j) = sKey
            saKeyValues(1,j) = sValue
              ' dbPrint sMe & "j /key/value: " & CStr(j) & "/" & sKey & "/" & sValue

          ElseIf iEq > 0 then  ' test for "=", implies key/value pair

            sKey = Left(saKeyValueLines(j), iEq-1)
            sValue = Right(saKeyValueLines(j), Len(saKeyValueLines(j)) - iEq)

            ' since tabs don't get "trimmed-out", replace w/null string...
            saKeyValues(0,j) = Replace(Trim(sKey), vbTab, "")
            saKeyValues(1,j) = Replace(Trim(sValue), vbTab, "")
              if c_bDebug then dbPrint sMe & "j /key/value: " & CStr(j) & "/" & sKey & "/" & sValue

          ElseIf (saKeyValueLines(j) = "") then  ' test for blank line

            sKey = c_sComment  ' treat as comment
            sValue = sEmpty

            saKeyValues(0,j) = sKey
            saKeyValues(1,j) = sValue
              if c_bDebug then dbPrint sMe & "j /key/value: " & CStr(j) & "/" & sKey & "/" & sValue

          ' note: anything else is ignored (for now)...
          End If  ' testing for key/value code, comment, blank...

        Next  ' j

        ' add this section to the database,
        '   (sect heading, and array of key/value pairs)...
        c_oDB.Add sSectKey, saKeyValues
          ' if c_bDebug then dbPrint sMe & "added to DB: " & sSectKey

      Else  ' if NOT any key/value pairs...
        c_oDB.Add sSectKey, sEmpty
      End If

      Erase saKeyValues  ' free memory (to allow for ReDim next time around)...

      ' MsgBox(CStr(UBound(saKeyValues,2)))
    Next  ' i

    c_sBuffer = sEmpty  ' (cleanup) release string buffer memory...

  End Sub


  Public Sub SaveFile(sFile)
  Const sMe = "[cIni:SaveFile], "
  Dim fso, oFile
  Const ForReading = 1, ForWriting = 2
  Const bCreate = True
  Dim cSect, cItems  ' as integer
  '
  Dim saKeyValuePairs  ' as string array
  Dim saKeys  ' as string array
  '
  Dim sThisKey, sThisValue  ' as string


    if c_bDebug then dbPrint sMe & "entered... "

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFile = fso.OpenTextFile(sFile, ForWriting, bCreate)

    ' write a preamble...
'    oFile.WriteLine "; --- This Ini File Generated by wshIniClass --- "
'    oFile.WriteLine "; " & "Script Generator: " & WScript.ScriptFullName
'    oFile.WriteLine "; " & "Date/Time Generated:   " & Now
'    oFile.WriteLine "; ---------------------------------------------- "
'    oFile.WriteBlankLines 1

    ' if there is any "preamble" deal with it here...
    if c_sPreamble <> sEmpty then
      oFile.Write c_sPreamble
    End If  ' test preamble


    ' "walk the database", a section at a time...
    cSect = c_oDB.Count  ' get number of sections...
    saKeys = c_oDB.Keys

    For i = 0 To cSect -1

      oFile.WriteBlankLines 1
      oFile.WriteLine "[" & saKeys(i) & "]"  ' write out section header (name)

      ' get the section's key/value pairs array...
      saKeyValuePairs = c_oDB(saKeys(i))  ' retrieve associated item (a string array)
      if IsArray(saKeyValuePairs) then  ' "enumerate" the key/value pairs...

        cItems = UBound(saKeyValuePairs, 2)
          ' if c_bDebug then dbPrint sMe & "cItems: " & CStr(cItems)
          BugAssert (cItems >= 0), sMe & "internal error: no key/value pairs for this section: " & saKeys(i)

        For j = 0 to cItems
          sThisKey = saKeyValuePairs(0,j)
          sThisValue = saKeyValuePairs(1,j)
            ' if c_bDebug then dbPrint sMe & "sThisKey/sThisValue: " & sThisKey & "/" & sThisValue

          ' test for blank line (both sThisKey and sThisValue are sEmpty)...
          if sThisKey = c_sComment then  ' test for comment line...
            oFile.WriteLine sThisValue  ' write comment line

          ElseIf (sThisKey = sEmpty AND sThisValue = sEmpty) then  ' test blank line
            oFile.WriteBlankLines 1

          Else  ' assume normal key/value pair...
            oFile.WriteLine sThisKey & "=" & sThisValue  ' write key/value pair

          End If  ' test key/value, comment, blank line...
        Next  ' j

        ' oFile.WriteBlankLines 1  ' separate this section from the next
      End If  ' test key/value array
    Next  ' i

    ' finished with the sections, write an EOF...
'    oFile.WriteLine "; --- End-OF-File --- "
    oFile.Close

    Set oFile = nothing : Set fso = nothing  ' clean up...
  End Sub


  Private Function ReadFile(sFile)
  Const sMe = "[cIni:ReadFile], "
  Dim fso, oFile
  Const ForReading = 1, ForWriting = 2

    if c_bDebug then dbPrint sMe & "entered... "

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFile = fso.OpenTextFile(sFile, ForReading)
    ReadFile = oFile.ReadAll  ' read the entire file at once...

    Set oFile = nothing : Set fso = nothing  ' clean up...
  End Function


  ' ----------------------------------------------
  ' --- CLASS INITIALIZE / TERMINATE -------------
  ' ----------------------------------------------

  Sub Class_Initialize()

    c_sMe = "[cIni:Initialize], "

    c_bDebug = False  ' True

    if c_bDebug then dbPrint c_sMe & "entered... "

    c_sBuffer = sEmpty  ' initialize to empty string

    Set c_oRE = New RegExp
    Set c_oDB = CreateObject("Scripting.Dictionary")

    sEmpty = ""  ' initialize empty string
    c_sComment = "#Comment#"
    c_sPreamble = sEmpty

    c_iLine = -1  ' initialize pointer (something illegal)
  End Sub

  Sub Class_Terminate()
    ' MsgBox(c_sMe & "terminating now")
    Set c_oRE = nothing
    ' Set c_sLines = nothing
    Set c_oDB = nothing
  End Sub

End Class

' ------------------------------------------------
' --- end of ini class ---------------------------
' ------------------------------------------------


'*****************************************************************
'*****************************************************************
'***
'*** Sub BUGASSERT (yes, it's for debugging)
'***
'*****************************************************************
'*****************************************************************

Sub BugAssert (bTest, sErrMsg)
Dim sDblSpace : sDblSpace = vbCrLf & vbCrLf

  ' BugAssert is a Bruce McKinney creation.
  '   It is used to test for valid intermediate results...

  if  bTest  then  Exit Sub  ' normally (hopefully) test returns true...


'  WScript.Echo "Error Message reported by BugAssert: "  & sErrMsg
'  WScript.Echo "script will terminate NOW"
'  WScript.Echo  " << BugAssert FAILED in Script: " & Wscript.ScriptName & " >> "
  MsgBox "Error Message reported by BugAssert: " & sDblSpace _
    & sErrMsg & sDblSpace & " Please ensure that a valid ini file is provided. ", _
    vbCritical, " << BugAssert FAILED in Script: " & Wscript.ScriptName & " >> "
  WScript.Quit

End Sub

Mark M. Webster

Genius may have its limitations, but stupidity is not thus handicapped. - Elbert Hubbard


Edited by - netmarcos on 11/28/2011 1:09:01 PM
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Mark Minasi's Reader Forum © 2002-2011 Mark Minasi Go To Top Of Page
This page was generated in 0.38 seconds. Snitz Forums 2000