Jump to content
Sign in to follow this  
grimmlock

Array pipe character used for next line

Recommended Posts

grimmlock

I am making an app that will allow the migration of users from one server to another (while changing permissions) easier for anyone and everyone. Below is my code, what I can't seem to figure out is what I am missing in my code so that the _uArray() reads the folder names in the destination folder and then uses them to set some of the permissions settings.

Right now the array pulls the data just fine, but either puts a "|" between the names (which I understand is "normal") or it removes the "|" and puts the folder names together in one long string, which is why I used StringSplit() only now it does not display anything at all.

If anyone has time, would it be possible for someone to look at this and help me solve this issue. I think it would a great app that anyone can use that, like me, needs to migrate users across domains or servers. Thank you in advance.

 
#include <GUIConstantsEx.au3>
#include <AutoItConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <MsgBoxConstants.au3>
#include <Constants.au3>
#include <FileConstants.au3>
#include <ButtonConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <StringConstants.au3>

Global $set = 3

;==========================Main GUI===========================
$hGUI = GUICreate("Complex-Permissions", 250, 350)
;=============================================================

;==========================Inputs=============================
$hOld = GUICtrlCreateInput("", 95, 25, 130)
$hNew = GUICtrlCreateInput("", 95, 50, 130)
$hOldSvr1 = GUICtrlCreateInput("", 95, 75, 25)
GUICtrlSetLimit(-1, $set)
$hOldSvr2 = GUICtrlCreateInput("", 130, 75, 25)
GUICtrlSetLimit(-1, $set)
$hOldSvr3 = GUICtrlCreateInput("", 165, 75, 25)
GUICtrlSetLimit(-1, $set)
$hOldSvr4 = GUICtrlCreateInput("", 200, 75, 25)
GUICtrlSetLimit(-1, $set)
$hNewSvr1 = GUICtrlCreateInput("", 95, 100, 25)
GUICtrlSetLimit(-1, $set)
$hNewSvr2 = GUICtrlCreateInput("", 130, 100, 25)
GUICtrlSetLimit(-1, $set)
$hNewSvr3 = GUICtrlCreateInput("", 165, 100, 25)
GUICtrlSetLimit(-1, $set)
$hNewSvr4 = GUICtrlCreateInput("", 200, 100, 25)
GUICtrlSetLimit(-1, $set)
$hLetter = GUICtrlCreateInput("", 95, 125, 130)
$hShare = GUICtrlCreateInput("", 95, 150, 130)
$hLocal = GUICtrlCreateInput("", 95, 175, 130)
$hFolder = GUICtrlCreateInput("", 95, 200, 130)
$hUID = GUICtrlCreateInput("", 95, 225, 130)
$hExclude = GUICtrlCreateInput("", 95, 250, 130)
;=============================================================

;==========================Buttons============================
$hButton1 = GUICtrlCreateButton("Test", 25, 285, 50)
;~ GUICtrlSetState(-1, $GUI_HIDE)
$hButton2 = GUICtrlCreateButton("Migrate Data / " & @CRLF & "Change Permissions", 100, 285, 120, 50, $BS_MULTILINE)
;=============================================================

;==========================Labels=============================
$hLabel1 = GUICtrlCreateLabel("Old Domain", 10, 28)
$hLabel2 = GUICtrlCreateLabel("New Domain", 10, 53)
$hLabel3 = GUICtrlCreateLabel("Old Server (IP)", 10, 78)
$hLabel4 = GUICtrlCreateLabel("New Server (IP)", 10, 103)
$hLabel5 = GUICtrlCreateLabel("Drive Letter", 10, 128)
$hLabel5 = GUICtrlCreateLabel("Share Folder", 10, 153)
$hLabel6 = GUICtrlCreateLabel("Local Folder", 10, 178)
$hLabel7 = GUICtrlCreateLabel("Folder Name", 10, 203)
$hLabel8 = GUICtrlCreateLabel("User Name", 10, 228)
$hLabel9 = GUICtrlCreateLabel("Exclusions", 10, 253)
;=============================================================

GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMSG()
        Case $GUI_EVENT_CLOSE
            ExitLoop


        Case $hButton1
            _uArray()

        Case $hButton2
;~             _NetUse()
;~             _RoboCopy()
            _Perm()

    EndSwitch

WEnd



;=============================================================
;~                     Functions
;=============================================================

Func _NetUse()
    RunWait(@ComSpec & " /c " & "net use \\" & GUICtrlRead($hOldSvr1) & "." & GUICtrlRead($hOldSvr2) & "." & GUICtrlRead($hOldSvr3) & "." & GUICtrlRead($hOldSvr4) & "\c$ /user:" & GUICtrlRead($hOld) & "\axeontech", "", @SW_HIDE)
    RunWait(@ComSpec & " /c " & "net use \\" & GUICtrlRead($hOldSvr1) & "." & GUICtrlRead($hOldSvr2) & "." & GUICtrlRead($hOldSvr3) & "." & GUICtrlRead($hOldSvr4) & "\Admin$ /user:" & GUICtrlRead($hOld) & "\axeontech", "", @SW_HIDE)
    Sleep(2000)
EndFunc    ;= _NetUse


Func _RoboCopy()
    If GUICtrlRead($hExclude) <> "" then
        RunWait(@ComSpec & " /k " & "robocopy /B \\" & GUICtrlRead($hOldSvr1) & "." & GUICtrlRead($hOldSvr2) & "." & GUICtrlRead($hOldSvr3) & "." & GUICtrlRead($hOldSvr4) & "\" & GUICtrlRead($hShare) & "\" & GUICtrlRead($hFolder) & " \\" & GUICtrlRead($hNewSvr1) & "." & GUICtrlRead($hNewSvr2) & "." & GUICtrlRead($hNewSvr3) & "." & GUICtrlRead($hNewSvr4) & "\" & GUICtrlRead($hShare) & "\" & GUICtrlRead($hFolder) & " /E /mir /XD " & GUICtrlRead($hFolder) & "\" & GUICtrlRead($hExclude) & "/w:0 /r:0 /log:c:\users\" & @UserName & "\desktop\migrate_profiles.txt", "", @SW_SHOW)
        MsgBox(0, "", "RoboCopy w/ Exceptions: Complete")
    Else
        RunWait(@ComSpec & " /k " & "robocopy /B \\" & GUICtrlRead($hOldSvr1) & "." & GUICtrlRead($hOldSvr2) & "." & GUICtrlRead($hOldSvr3) & "." & GUICtrlRead($hOldSvr4) & "\" & GUICtrlRead($hShare) & "\" & GUICtrlRead($hFolder) & " \\" & GUICtrlRead($hNewSvr1) & "." & GUICtrlRead($hNewSvr2) & "." & GUICtrlRead($hNewSvr3) & "." & GUICtrlRead($hNewSvr4) & "\" & GUICtrlRead($hShare) & "\" & GUICtrlRead($hFolder) & " /E /mir /w:0 /r:0 /log:c:\users\" & @UserName & "\desktop\migrate_profiles.txt", "", @SW_SHOW)
        MsgBox(0, "", "RoboCopy w/o Exceptions: Complete")
    EndIf

;~     Sleep(2000)
EndFunc    ;= _RoboCopy


Func _Perm()
;~     If GUICtrlRead($hLocal) = "" then
;~         GUICtrlSetData($hLocal, GUICtrlRead($hShare))
;~     EndIf

    Local $hFileOpen = FileOpen("c:\users\" & @UserName & "\desktop\log.txt", $FO_APPEND)

        Local $iPID = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&TAKEOWN /f " & GUICtrlRead($hFolder) & " /r /d y", "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID)
            Local $sOutput = StdoutRead($iPID)
            FileWrite($hFileOpen, $sOutput)
;~         Sleep(1000)
        Local $iPID1 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /reset /T", "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID1)
            Local $sOutput = StdoutRead($iPID1)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID2 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & "\*.* /inheritance:d /c /t", "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID2)
            Local $sOutput = StdoutRead($iPID2)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID3 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /grant " & '"' & 'system":(OI)(CI)F /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID3)
            Local $sOutput = StdoutRead($iPID3)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID4 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /grant " & '"' &  @ComputerName & '\administrator":(OI)(CI)F /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID4)
            Local $sOutput = StdoutRead($iPID4)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID5 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /grant " & '"' &  @ComputerName & '\administrators":(OI)(CI)F /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID5)
            Local $sOutput = StdoutRead($iPID5)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID6 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /grant " & '"' & GUICtrlRead($hNew) & '\domain admins":(OI)(CI)F /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID6)
            Local $sOutput = StdoutRead($iPID6)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID7 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /grant " & '"' & GUICtrlRead($hNew) & '\' & GUICtrlRead($hUID) & '":(OI)(CI)F /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID7)
            Local $sOutput = StdoutRead($iPID7)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID8 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /setowner " & '"' & GUICtrlRead($hNew) & '\' & GUICtrlRead($hUID) & '" /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID8)
            Local $sOutput = StdoutRead($iPID8)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID9 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & "\*.* /remove:g " & '"' & 'everyone" /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID9)
            Local $sOutput = StdoutRead($iPID9)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID10 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & "\*.* /remove:g " & '"' & GUICtrlRead($hNew) & '\axeontech" /c /t', "", @SW_HIDE, $STDERR_MERGED) ;
            ProcessWaitClose($iPID10)
            Local $sOutput = StdoutRead($iPID10)
            FileWrite($hFileOpen, $sOutput)

    FileClose($hFileOpen)
    MsgBox(0, "", "Permissions Change: Complete")

EndFunc    ;= _Perm


Func _uArray()

    $fFileList = _FileListToArray(GUICtrlRead($hLetter) & ":\" & GUICtrlRead($hLocal), "*", 2)
;~     _ArrayDisplay($fFileList, "$fFileList")
    $fFolder = _ArrayToString($fFileList, "|")
    $fSplit = StringSplit($fFolder, "|", $STR_ENTIRESPLIT)
    Run("Notepad")
    Sleep(1000)

For    $i = 1 To $fSplit[0]
    Send($fSplit[$i])

Next

EndFunc
 

Thanks

Grimm

Share this post


Link to post
Share on other sites
Melba23

grimmlock,

As you do not specify precisely, I presume it is this section that is causing you problems:

$fFileList = _FileListToArray(GUICtrlRead($hLetter) & ":\" & GUICtrlRead($hLocal), "*", 2)
;~     _ArrayDisplay($fFileList, "$fFileList")
    $fFolder = _ArrayToString($fFileList, "|")
    $fSplit = StringSplit($fFolder, "|", $STR_ENTIRESPLIT)
    Run("Notepad")
    Sleep(1000)

For    $i = 1 To $fSplit[0]
    Send($fSplit[$i])

Next
Firstly, the code is working exactly as the Help file describes. If you want to Send the result to Notepad as separate lines then you need to add a line delimiter like this: :)

Send($fSplit[$i] & @CR)
But better still would be to convert the array directly into a string containing the line delimiter and then send it in one: ;)

$fFolder = _ArrayToString($fFileList, @CR)
Run("Notepad")
Sleep(1000)
Send($fFolder)
All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
grimmlock

Very clear thank you for the help and explination, as always I am humbled :bye:

But now the hard part for me, I need to somehow take the data from the array and use it set some of the variables :sweating:.


Thanks

Grimm

Share this post


Link to post
Share on other sites
Melba23

grimmlock,

As always, glad I could help. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • nooneclose
      By nooneclose
      I need help turning this string "20180913221626" into a formatted time string.
      I need to go from this: 20180913221626
      to this: 09/13/2018 10:16 PM
      I do not always know what the date will be so I can not just use a variable I need to actually convert/format. 
      I did see an older post in the forms that was basically the same question only the other guy did not post the working code and I can not figure out how to use _AD_GetObjectProperties properly to get what I want. 
      As always any help would be appreciated. 
      Here is the code I use to find the date, but it always gives me the unformatted version. 
      ;retrieve the items object $oItem = $oOutlook.Session.GetItemFromID($aItems[1][0], Default) $oItem.GetInspector $eSentOn = $oItem.SentOn ; When was the email sent? MsgBox("", "Sent On of the email", $eSentOn) ;******************************************************************************* ; Formats the date and time from the email ;******************************************************************************* ;Local $fDatenTime = _DateTimeFormat($eSentOn, 1) ;MsgBox("", "Formatted email time", $fDatenTime) $aProperties = _AD_GetObjectProperties($eSentOn) _ArrayDisplay($aProperties, "Did the conversion work?")  
    • Emmhor1
      By Emmhor1
      Hi All,

      MAIN QUESTION:
      Is it possible to Call specific function within a GUI

      So I have a script with multiple functions although I don't want to use every function every time.
      My Idea is to create a simple GUI which allows me to select what functions I want to use then run the funtions by clicking a button.
      I have already made a GUI which allows me to select specific .exe's I would like to run after selection it runs the .exe one by one.
      This script is on my work laptops and cannot access it right now.
       
      Who can help me with this?
      GUIcreate
      Func1 
      Func2
      Func3
      Then have a boxes which allows me to select the specif Func.(I used GUIChecked and Unchecked in my other script)
      Then a button which executes/calls the selected functions
    • Skeletor
      By Skeletor
      Hi Virtual People,
      My array works perfectly fine. However, what is the best practice if the line in the array doesn't have the correct amount of columns and if I can add a placeholder?

       
      For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") Next  
    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
×