Split .txt file at Tab for registry values. Please help!!!

Author Message
Cant_Code

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 11/17/2011
  • Status: offline
Split .txt file at Tab for registry values. Please help!!! Thursday, November 17, 2011 6:56 PM (permalink)
0
Hi,
Pretty please can someone help?
 
I am merging several drives on a Windows Server. There are hundreds of shares with individual permissions.
I have exported the values from HKLM\system\currentcontrolset\Services\lanmanserver\shares to a text file.
The result is
    VBS      REG_MULTI_SZ    CSCFlags=0\0MaxUses=4294967295\0Path=C:\VBS\0Permissions=9\0ShareName=VBS\0Type=0
    TSUP    REG_MULTI_SZ    CSCFlags=0\0MaxUses=4294967295\0Path=C:\TSUP\0Permissions=9\0ShareName=TSUP\0Type=0
3 colums of data. First column is Value, Second is Type and Third is the Data.
I've updated the Path= to my new share and am attempting to split the lines at the tab. I only need the Value and the Data.
Ideally it would be something like this
 
 FlHndl = FileOpen(“ShareFromReg.txt”, READ) While NotEOF do X=ReadFile(FlHndl)   Val=Split(x,@TAB)[0] Data=Split(x,@TAB)[1]   Run(“reg add HKLM\System\currentcontrolset\services\lanmanserver\shares /v $Val /t REG_MULTI_SZ /d $Data ”) Endwhile FileClose(FlHndl) Print(“Check the registry to see if it all works.”) 

 
I've tried to script splitting the data at the tabs but am stuck. Here is what I have
 
 Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\ShareFromReg1.txt", ForReading) Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    arrFields = Split(strLine, vbTab)
    arrValue = Split(arrFields(0), "=")
    strValue = arrValue(0)
    arrType = Split(arrFields(1), "=")
    strType = arrType(1)
    arrData = Split(arrFields(2), "=")
    strData = arrData(2)
    strNewContent = strNewContent & Chr(34) & strName & Chr(34) &  "," & Chr(34) & strAddress & Chr(34) & _
        "," & Chr(34) & strPhone & Chr(34) & vbCrLf
Loop objFile.Close Set objFile = objFSO.CreateTextFile("C:\Scripts\Test.txt") objFile.WriteLine "Value,Type,Data"
objFile.Write strNewContent objFile.Close 

I've tried to Dim arrValue etc. but I'm lost. I'd really appreaciate any advice. Thank you!
 
#1
    59cobalt

    • Total Posts : 981
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:Split .txt file at Tab for registry values. Please help!!! Friday, November 18, 2011 10:07 AM (permalink)
    0
    Cant_Code
    Ideally it would be something like this
    FlHndl = FileOpen("ShareFromReg.txt", READ)
    While NotEOF do
     X=ReadFile(FlHndl)
     Val=Split(x,@TAB)[0]
     Data=Split(x,@TAB)[1]
     Run("reg add HKLM\System\currentcontrolset\services\lanmanserver\shares /v $Val /t REG_MULTI_SZ /d $Data ")
    Endwhile
    FileClose(FlHndl)
    Print("Check the registry to see if it all works.")
    Use the SetMultiStringValue() method to write REG_MULTI_SZ values to the registry with a VBScript.

    Cant_Code
    I've tried to script splitting the data at the tabs but am stuck. Here is what I have
    Let's take a closer look at what you're doing here, and what actual values that generates:
    strLine = objFile.ReadLine
    REM strLine = "VBS    REG_MULTI_SZ    CSCFlags=0\0MaxUses=4294967295\0Path=..."
    arrFields = Split(strLine, vbTab)
    REM arrFields = Array("VBS", "REG_MULTI_SZ", "CSCFlags=0\0MaxUses=4294967295\0Path=...")
    So far, so good. At this point you have split your TSV line into an array.
    arrValue = Split(arrFields(0), "=")
    REM arrValue = Array("VBS")
    strValue = arrValue(0)
    REM strValue = "VBS"
    However, now you're trying to split a string that most likely never will contain a "=" character at that non-existing "=" character. The split will succeed regardless, but it will produce an array with just a single string element. Assigning this element to another variable will produce the exact same result as dropping the split altogether and simply assigning "strValue = arrFields(0)".
    arrType = Split(arrFields(1), "=")
    REM arrType = Array("REG_MULTI_SZ")
    strType = arrType(1)
    Just like above you split a string at a value that will never be present in that string. However, in this case you try to assign the second element of an array that contains only one element, which will raise an "Index out of bounds" error.
    arrData = Split(arrFields(2), "=")
    REM arrData = Array("CSCFlags", "0\0MaxUses", "4294967295\0Path", ...)
    strData = arrData(2)
    REM strData = "4294967295\0Path"
    arrFields(2) does contain "=" characters for a change, so this time you do get an array with multiple elements. However, the string in arrFields(2) consists of multiple key-value pairs separated by Null characters ("\0"). Merely splitting the string at "=" means that most elements in the resulting array will contain the value of the previous key-value pair, the separating "\0", and the key of the current key-value pair. I somehow doubt that this is what you actually want.

    One additional note: the following line is rather pointless, because you never assign values to strName, strAddress or strPhone, so all you'll get is a bunch of "","","" lines.
    Cant_Code
    strNewContent = strNewContent & Chr(34) & strName & Chr(34) &  "," & Chr(34) & strAddress & Chr(34) & _
    "," & Chr(34) & strPhone & Chr(34) & vbCrLf

     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9