Jump to content

Array pipe character used for next line


Go to solution Solved by Melba23,

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators
  • Solution

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

grimmlock,

As always, glad I could help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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
 Share

×
×
  • Create New...