Sign in to follow this  
Followers 0
surreal

ListView Help

8 posts in this topic

#1 ·  Posted (edited)

I have gotten pretty far with this program but have once again hit a point that is beyond my coding knowledge and looking for some assistance.

Here is the new code with all the needed files: Download

When you test this script you will want to use the file – backup, option. That way it will place anything you select in a folder that you choose. This is best for testing.

The mapped drives and printers part is what I’m having trouble with. I have the code working to create an array that will export the information to a text file (c:\temp). What I would like to do is have it to where it would pop up a listview with each device the array gathered. Within that listview have a checkbox so the the user can select what printers or mapped drives they want to install.

to run the mapped drives or printers script it is located within the toolbar (programs)

I did notice that maybe the problem with this is that the text file does not populate the array info tell you exit the program.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <HKCUReg.au3>
#include <Surreal.au3>
#include <GuiStatusBar.au3>

;===Checks Local OSVersion Create Var User Friendly================================================
$OS = @OSVersion
$OS = StringReplace($OS, "WIN_VISTA", "Windows Vista")
$OS = StringReplace($OS, "WIN_XP", "Windows XP")
$OS = StringReplace($OS, "WIN_2000", "Windows 2000")
;===Determines Documents Location According To OS++================================================
$OSDOC = @OSVersion
If $OSDOC = "WIN_VISTA" Then $DOC = "\Users\"
If $OSDOC = "WIN_XP" Then
    $DOC = "\Documents and Settings\"
EndIf
$OSDF = @OSVersion
If $OSDF = "WIN_VISTA" Then $DF = "Documents"
If $OSDF = "WIN_XP" Then
    $DF = "My Documents"
EndIf

Global $Lotus_Location
Local $sTitle = 'eMigrate'
Local $backup = "\Migrate_Backup\"
Local $network = "c:\Temp\Migrate_Network\"
Local $restore = "\Migrate_Restore\"
Local $LogFile = "c:\Temp\LogFile.txt"
Local $Separator = "------------------------------"
Local $LogFileLocation = @ProgramFilesDir & "\" & $sTitle & "\eMigrate.txt"

;===GUI Start and File Menu========================================================================
$ParentWin = GUICreate("", 330, 185, -1, -1)

$FileMenu = GUICtrlCreateMenu("&File")
$BKItem = GUICtrlCreateMenuItem("Backup Only", $FileMenu)
$RSItem = GUICtrlCreateMenuItem("Restore Only", $FileMenu)
$ExitItem = GUICtrlCreateMenuItem("Exit", $FileMenu)
$ViewMenu = GUICtrlCreateMenu("&View")
$LogItem = GUICtrlCreateMenuItem("Log File", $ViewMenu)
$ProMenu = GUICtrlCreateMenu("&Programs")
$RDItem = GUICtrlCreateMenuItem("Remote Desktop", $ProMenu)
$CMItem = GUICtrlCreateMenuItem("Computer Management", $ProMenu)
$PRItem = GUICtrlCreateMenuItem("Migrate Printers", $ProMenu)
$MDItem = GUICtrlCreateMenuItem("Migrate Mapped Drives", $ProMenu)
$CPItem = GUICtrlCreateMenuItem("Command Prompt", $ProMenu)
$HelpMenu = GUICtrlCreateMenu("&Help")
$HelpItem = GUICtrlCreateMenuItem($sTitle & " Help", $HelpMenu)
GUICtrlSetState($BKItem, $GUI_UNCHECKED)
GUICtrlSetState($RSItem, $GUI_UNCHECKED)

;===GUI Network Computer To Tranfer From===========================================================
GUICtrlCreateGroup("System", 10, 10, 190, 75)
GUICtrlCreateLabel("Computer Name:", 20, 25)
$cnTarget = GUICtrlCreateInput(@ComputerName, 20, 40, 120, 20)
$cnMessage = GUICtrlCreateLabel("Enter computer name or ip address", 20, 64, 175, 15)
$cnButton = GUICtrlCreateButton("Connect", 145, 35, 50, 25, $WS_GROUP)

;===GUI Network User Profile=======================================================================
GUICtrlCreateGroup("Profile:", 10, 90, 190, 45)
$prCombo = GUICtrlCreateCombo("", 20, 105, 175, 20)

;===GUI Group What To Migrate======================================================================
GUICtrlCreateGroup("Tranfer", 210, 10, 110, 80)
$Box_Documents = GUICtrlCreateCheckbox("My Documents", 220, 25)
$Box_IEFav = GUICtrlCreateCheckbox("IE Favorites", 220, 45)
$Box_Notes = GUICtrlCreateCheckbox("Lotus Notes", 220, 65)
GUICtrlSetState($Box_Documents, $GUI_CHECKED)
GUICtrlSetState($Box_IEFav, $GUI_CHECKED)
GUICtrlSetState($Box_Notes, $GUI_UNCHECKED)

;===GUI Start Function=============================================================================
$StartButton = GUICtrlCreateButton("Start", 230, 100, 65, 30, $WS_GROUP)
$StatusBar = _GUICtrlStatusBar_Create($ParentWin)
_GUICtrlStatusBar_SetMinHeight($StatusBar, 5)
GUISetState(@SW_SHOW)

;===Start Of GUIGetMsg=============================================================================
While 1
    $msg = GUIGetMsg()
    Select

        ;===Case For Exit GUI==============================================================================
        Case $msg = $ExitItem Or $msg = $GUI_EVENT_CLOSE
            $FormClose = MsgBox(36, "", "Are you sure you want to exit?")
            If $FormClose = 6 Then
                GUIDelete()
                Exit
            EndIf

            ;===Case For File Menu Items=======================================================================
        Case $msg = $BKItem
            If BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($BKItem, $GUI_UNCHECKED)
                _GUICtrlStatusBar_SetText($StatusBar, "")
            Else
                GUICtrlSetState($BKItem, $GUI_CHECKED)
                Local $BKtarget = FileSelectFolder("Choose the location you want to back up to:" & @CRLF & "A backup folder (eMigrate) will be created", "", 1)
                _GUICtrlStatusBar_SetText($StatusBar, " Backup Mode Enabled")
                GUICtrlSetData($cnTarget, @ComputerName)
                GUICtrlSetState($RSItem, $GUI_UNCHECKED)
                Connect()
            EndIf
            If $BKtarget = '' Then
                GUICtrlSetState($BKItem, $GUI_UNCHECKED)
                _GUICtrlStatusBar_SetText($StatusBar, "")
            EndIf
        Case $msg = $RSItem
            If BitAND(GUICtrlRead($RSItem), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($RSItem, $GUI_UNCHECKED)
                _GUICtrlStatusBar_SetText($StatusBar, "")
            Else
                GUICtrlSetState($RSItem, $GUI_CHECKED)
                Local $RStarget = FileSelectFolder("Choose the location you want to restore from:" & @CRLF & "Select the (eMigrate) folder you created", "")
                _GUICtrlStatusBar_SetText($StatusBar, " Restore Mode Enabled")
                GUICtrlSetData($cnTarget, @ComputerName)
                GUICtrlSetState($BKItem, $GUI_UNCHECKED)
                Connect()
            EndIf
            If $RStarget = '' Then
                GUICtrlSetState($RSItem, $GUI_UNCHECKED)
                _GUICtrlStatusBar_SetText($StatusBar, "")
            EndIf
        Case $msg = $HelpItem
            MsgBox(64, $sTitle, "Help File Coming Soon")
        Case $msg = $RDItem
            Run('mstsc.exe', @SystemDir)
        Case $msg = $CMItem
            ShellExecute('compmgmt.msc', @SystemDir, @SW_MAXIMIZE)
        Case $msg = $LogItem
            If FileExists($LogFileLocation) Then
                ShellExecute($LogFileLocation, "")
            Else
                MsgBox(48, $sTitle, "A Log File has not been created yet.")
            EndIf
        Case $msg = $CPItem
            Run('cmd.exe', @SystemDir)
            ;===Case For Mapped Drives and Printers not working yet============================================
        Case $msg = $MDItem
            If GUICtrlRead($cnTarget) = '' Then
                MsgBox(16, "", 'Target machine must be entered')
            Else
                Drives()
                MsgBox(64, $sTitle, "File has been created (c:\Temp\Drives)")
            EndIf
        Case $msg = $PRItem
            If GUICtrlRead($cnTarget) = '' Then
                MsgBox(16, "", 'Target machine must be entered')
            Else
                Printers()
                FileClose("c:\Temp\Printers\Printers.txt")
                MsgBox(64, $sTitle, "File has been created (c:\Temp\Printers)")
            EndIf

            ;===Case For Lotus Notes CheckBox==================================================================
        Case $msg = $Box_Notes
            If GUICtrlRead($cnTarget) = '' Or GUICtrlRead($prCombo) = '' Then
                MsgBox(16, "", 'Target machine and a profile must be entered')
                GUICtrlSetState($Box_Notes, $GUI_UNCHECKED)
            EndIf

            If BitAND(GUICtrlRead($Box_Notes), $GUI_UNCHECKED) = $GUI_UNCHECKED Then
                GUICtrlSetState($Box_Notes, $GUI_UNCHECKED)
            Else
                Lotus()
                GUICtrlSetState($Box_Notes, $GUI_CHECKED)
            EndIf
            ;===Case For Connect===============================================================================
        Case $msg = $cnButton
            If GUICtrlRead($cnTarget) = '' Then
                GUICtrlSetData($cnMessage, 'Target machine must be entered')
                GUICtrlSetColor($cnMessage, 0xFF0000)
                ContinueLoop
            EndIf
            $Log = FileOpen($LogFile, 10)
            FileWriteLine($LogFile, "Started: " & @MON & "/" & @MDAY & "/" & @YEAR & " at " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF & @CRLF & "System Info" & @CRLF & $Separator & @CRLF)
            FileWriteLine($LogFile, "Operating System: " & $OS & @CRLF & "Computer Name: " & @ComputerName & @CRLF)
            FileClose($LogFile)
            Connect()

        Case $msg = $StartButton
            If GUICtrlRead($cnTarget) = '' Or GUICtrlRead($prCombo) = '' Then
                MsgBox(16, "", 'Target machine and a profile must be entered')
            Else
                StartButton()
            EndIf
    EndSelect
WEnd

;===Function For Remote System InfoBox=============================================================
Func Connect()
    SplashTextOn("", "Querying Network", 165, 40, -1, -1, 2, "", 9)
    Sleep(1000)
    If Ping(GUICtrlRead($cnTarget)) Then
        $strComputer = GUICtrlRead($cnTarget)
        $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
        SplashOff()
        If Not IsObj($objWMIService) Then
            GUICtrlSetData($cnMessage, 'Failed to connect to system')
            GUICtrlSetColor($cnMessage, 0xFF0000)
            Return
        EndIf
        ;===WMI BIOS
        $colItems1 = $objWMIService.ExecQuery("SELECT * FROM Win32_Bios")
        $message = "System Info for " & $strComputer & @CRLF & $Separator & @CRLF & @CRLF
        For $objItem In $colItems1
            $message &= "Dell Asset Number: " & $objItem.SerialNumber & @CRLF & _
                    "Manufacturer: " & $objItem.Manufacturer & @CRLF & @CRLF
            Global $surreal = $objItem.SerialNumber
            Global $RemoteName = $strComputer
        Next
        ;===WMI NETWORK
        $colItems2 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
        For $objItem In $colItems2
            $message &= "IP Address: " & $objItem.IPAddress(0) & @CRLF & _
                    "IP Subnet: " & $objItem.IPSubnet(0) & @CRLF & @CRLF
        Next
        ;===WMI SYSTEM
        $colItems3 = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
        For $objItem In $colItems3
            $message &= "Model: " & $objItem.Model & @CRLF & _
                    "Computer Name: " & $objItem.Name & @CRLF & _
                    "Last User: " & $objItem.UserName & @CRLF
            Global $RemoteUser = $objItem.UserName
        Next
        GUICtrlSetData($cnMessage, 'Connected, select user profile')
        GUICtrlSetColor($cnMessage, 0x008000)
        MsgBox(64, "System Information", $message)
    Else
        SplashOff()
        GUICtrlSetData($cnMessage, 'Target system could not be contacted')
        GUICtrlSetColor($cnMessage, 0xFF0000)
        Return
    EndIf
    Profile()
EndFunc   ;==>Connect

;===Function For Remote Profile Load===============================================================
Func Profile()
    Local $combo_string = ""
    $FolderList = _FileListToArray("\\" & GUICtrlRead($cnTarget) & "\c$" & $DOC, "*", 2)
    For $i = 1 To $FolderList[0]
        Switch $FolderList[$i]
            Case "All Users", "Default User", "LocalService", "NetworkService"
                ContinueLoop
            Case Else
                If $i = $FolderList[0] Then
                    $combo_string &= $FolderList[$i]
                Else
                    $combo_string &= $FolderList[$i] & "|"
                EndIf
        EndSwitch
    Next
    GUICtrlSetData($prCombo, $combo_string)
EndFunc   ;==>Profile

;===Function For Checkbox Actions==================================================================
Func StartButton()
    Local $Path = "\\" & GUICtrlRead($cnTarget)
    Local $rmdocs = $Path & "\c$" & $DOC & GUICtrlRead($prCombo) & "\" & $DF
    Local $rmfavs = $Path & "\c$" & $DOC & GUICtrlRead($prCombo) & "\Favorites"
    Local $LotusProgram = @ProgramFilesDir & "\Lotus\Notes\Data"
    ;====================My Documents
    If GUICtrlRead($Box_Documents) = $GUI_CHECKED And BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        ;-----Backup
        _GUICtrlStatusBar_SetText($StatusBar, " Backing Up My Documents")
        DirCreate($BKtarget & $backup & $DF & "\" & GUICtrlRead($prCombo))
        _CopyWithProgress($rmdocs & "\*.*", $BKtarget & $backup & $DF & "\" & GUICtrlRead($prCombo))
        FileWriteLine($LogFile, "My Documents" & @TAB & "(Backup Successful)" & @CRLF)
    ElseIf GUICtrlRead($Box_Documents) = $GUI_CHECKED And BitAND(GUICtrlRead($RSItem), $GUI_CHECKED) = $GUI_CHECKED Then
        ;-----Restore
        _GUICtrlStatusBar_SetText($StatusBar, " Restoring My Documents")
        _CopyWithProgress($RStarget & $DF & "\" & GUICtrlRead($prCombo) & "\*.*", "c:" & $DOC & GUICtrlRead($prCombo) & "\" & $DF)
        FileWriteLine($LogFile, "My Documents" & @TAB & "(Restore Successful)" & @CRLF)
    ElseIf GUICtrlRead($Box_Documents) = $GUI_CHECKED Then
        ;-----Network
        _GUICtrlStatusBar_SetText($StatusBar, " Transferring My Documents")
        _CopyWithProgress($rmdocs & "\*.*", "c:" & $DOC & GUICtrlRead($prCombo) & "\" & $DF)
        FileWriteLine($LogFile, "My Documents" & @TAB & "(Network Successful)" & @CRLF)
    EndIf
    ;====================Favorites
    If GUICtrlRead($Box_IEFav) = $GUI_CHECKED And BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        ;-----Backup
        _GUICtrlStatusBar_SetText($StatusBar, " Backing Up Favorites")
        GUICtrlSetColor($cnMessage, 0x008000)
        DirCreate($BKtarget & $backup & "Favorites")
        _CopyWithProgress($rmfavs & "\*.*", $BKtarget & $backup & "Favorites")
        FileWriteLine($LogFile, "Favorites" & @TAB & "(Backup Successful)" & @CRLF)
    ElseIf GUICtrlRead($Box_IEFav) = $GUI_CHECKED And BitAND(GUICtrlRead($RSItem), $GUI_CHECKED) = $GUI_CHECKED Then
        ;-----Restore
        _GUICtrlStatusBar_SetText($StatusBar, " Restoring Favorites")
        _CopyWithProgress($RStarget & "Favorites" & "\*.*", "c:" & $DOC & GUICtrlRead($prCombo) & "\Favorites")
        FileWriteLine($LogFile, "Favorites" & @TAB & "(Restore Successful)" & @CRLF)
    ElseIf GUICtrlRead($Box_IEFav) = $GUI_CHECKED Then
        ;-----Network
        _GUICtrlStatusBar_SetText($StatusBar, " Transferring Favorites")
        _CopyWithProgress($rmfavs & "\*.*", "c:" & $DOC & GUICtrlRead($prCombo) & "\Favorites")
        FileWriteLine($LogFile, "Favorites" & @TAB & "(Network Successful)" & @CRLF)
    EndIf
    ;====================Lotus Notes
    If GUICtrlRead($Box_Notes) = $GUI_CHECKED And BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        ;-----Backup
        _GUICtrlStatusBar_SetText($StatusBar, " Backing Up Lotus Notes")
        DirCreate($BKtarget & $backup & "Notes")
        _CopyWithProgress($Lotus_Location & "\*.id", $BKtarget & $backup & "Notes")
        _CopyWithProgress($Lotus_Location & "\Desktop6.ndk", $BKtarget & $backup & "Notes")
        _CopyWithProgress($Lotus_Location & "\Names.nsf", $BKtarget & $backup & "Notes")
        _CopyWithProgress($Lotus_Location & "\User.dic", $BKtarget & $backup & "Notes")
        DirCreate($BKtarget & $backup & "Notes\Archive")
        _CopyWithProgress($Lotus_Location & "\Archive\*.*", $BKtarget & $backup & "Notes\Archive")
        FileWriteLine($LogFile, "Lotus Notes" & @TAB & "(Backup Successful)" & @CRLF)
    ElseIf GUICtrlRead($Box_Notes) = $GUI_CHECKED And BitAND(GUICtrlRead($RSItem), $GUI_CHECKED) = $GUI_CHECKED Then
        ;-----Restore
        _GUICtrlStatusBar_SetText($StatusBar, " Restoring Lotus Notes")
        _CopyWithProgress($RStarget & "Notes" & "\*.*", $LotusProgram)
        FileWriteLine($LogFile, "Lotus Notes" & @TAB & "(Restore Successful)" & @CRLF)
    ElseIf GUICtrlRead($Box_Notes) = $GUI_CHECKED Then
        ;-----Network
        _GUICtrlStatusBar_SetText($StatusBar, " Transferring Lotus Notes")
        _CopyWithProgress($Lotus_Location & "\*.id", $LotusProgram)
        _CopyWithProgress($Lotus_Location & "\Desktop6.ndk", $LotusProgram)
        _CopyWithProgress($Lotus_Location & "\Names.nsf", $LotusProgram)
        _CopyWithProgress($Lotus_Location & "\User.dic", $LotusProgram)
        DirCreate($LotusProgram & "\Archive")
        _CopyWithProgress($Lotus_Location & "\Archive\*.*", $LotusProgram & "\Archive")
        FileWriteLine($LogFile, "Lotus Notes" & @TAB & "(Network Successful)" & @CRLF)
    EndIf
    SoundPlay(@WindowsDir & "\media\tada.wav", 1)
    $Success = MsgBox(4, "", "Migration Was Successful. Do You Want To Exit?")
    If $Success = 6 Then Exit
EndFunc   ;==>StartButton

;===Function For Save Printer Info File============================================================
Func Printers()
    If GUICtrlRead($cnTarget) = '' Then
        MsgBox(16, "", 'Target machine must be entered')
    Else
        SplashTextOn($sTitle, "Transfering Printers", 165, 40, -1, -1, 2, "", 9)
        Local $passet = GUICtrlRead($cnTarget)
        DirCreate("c:\Temp\Printers")
        Local $pLocation = "c:\Temp\Printers\Printers.txt"

        Local $pFile = FileOpen($pLocation, 10)
        For $i = 1 To 25
            $p = _HKCU_EnumVal("\\\" & $passet & "\Software\Microsoft\Windows NT\CurrentVersion\Devices", $i)
            $iProdp = 1
            For $n = 1 To $p[0][0]
                $iProdp *= $p[$n][2]
                If $p[$n][2] = 0 Then
                    $ppath = _HKCU_Read("\\\" & $passet & "\\" & $p[$n][1], "Devices")
                EndIf
                If StringRegExp($p[$n][1], "^\\\\(?!\\)") Then
                    FileWriteLine($pFile, $p[$n][1] & "," & $ppath[1][1])
                EndIf
            Next
            If $iProdp <> 0 Then ExitLoop
        Next
        SplashOff()

    EndIf
    Return
EndFunc   ;==>Printers

;===Function For Mapped Drives=====================================================================
Func Drives()
    If GUICtrlRead($cnTarget) = '' Then
        MsgBox(16, "", 'Target machine must be entered')
    Else
        SplashTextOn($sTitle, "Transfering Mapped Drives", 165, 40, -1, -1, 2, "", 9)
        Local $masset = GUICtrlRead($cnTarget)
        DirCreate("c:\Temp\Drives")
        Local $mapLocation = "c:\Temp\Drives\Drives.txt"

        Local $mapFile = FileOpen($mapLocation, 10)
        For $i = 1 To 25
            $b = _HKCU_EnumKey("\\\" & $masset & "\Network", $i)
            $iProdm = 1
            For $j = 1 To $b[0][0]
                $iProdm *= $b[$j][2]
                If $b[$j][2] = 0 Then
                    $Path = _HKCU_Read("\\\" & $masset & "\\" & $b[$j][0] & "\Network\" & $b[$j][1], "RemotePath")
                    FileWriteLine($mapFile, $b[$j][1] & "," & $Path[1][1])
                EndIf
            Next
            If $iProdm <> 0 Then ExitLoop
        Next
        SplashOff()
        FileClose("c:\Temp\Drives\Drives.txt")
    EndIf
    Return
EndFunc   ;==>Drives

;===Function For Lotus Notes Child Window==========================================================
Func Lotus()
    $ChildWin = GUICreate("", 135, 110, -1, -1, $WS_EX_TOPMOST)
    GUISetBkColor(0xFFFFFF)
    GUISwitch($ChildWin)
    $Box_Single = GUICtrlCreateRadio("Single User Install", 10, 10)
    $Box_Multi = GUICtrlCreateRadio("Multi User Install", 10, 30)
    $Box_System = GUICtrlCreateRadio("Root System Install", 10, 50)
    GUISetState()
    While 1
        $lnmsg = GUIGetMsg()
        Select
            Case $lnmsg = $Box_Single And BitAND(GUICtrlRead($Box_Single), $GUI_CHECKED) = $GUI_CHECKED
                $Lotus_Location = "\\" & GUICtrlRead($cnTarget) & "\c$\Program Files\Lotus\Notes\Data"
                Sleep(200)
                GUIDelete($ChildWin)
                ExitLoop
                GUISwitch($ParentWin)
                GUISetState(@SW_SHOW, $ParentWin)
            Case $lnmsg = $Box_Multi And BitAND(GUICtrlRead($Box_Multi), $GUI_CHECKED) = $GUI_CHECKED
                $Lotus_Location = "\\" & GUICtrlRead($cnTarget) & "\c$" & $DOC & GUICtrlRead($prCombo) & "\Local Settings\Application Data\Lotus\Notes\Data"
                Sleep(200)
                GUIDelete($ChildWin)
                ExitLoop
                GUISwitch($ParentWin)
                GUISetState(@SW_SHOW, $ParentWin)
            Case $lnmsg = $Box_System And BitAND(GUICtrlRead($Box_System), $GUI_CHECKED) = $GUI_CHECKED
                $Lotus_Location = "\\" & GUICtrlRead($cnTarget) & "\c$\Lotus\Notes\Data"
                Sleep(200)
                GUIDelete($ChildWin)
                ExitLoop
                GUISwitch($ParentWin)
                GUISetState(@SW_SHOW, $ParentWin)
        EndSelect
    WEnd
EndFunc   ;==>Lotus

Thanks everyone

d@ve

Edited by surreal

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

been trying a few things, im still not sure if this is not working cause of how im create the array. below is where i am so far, but not sure if i am even on the right track. thanks for the help.

;===Function For Mapped Drives=====================================================================
Func Drives()
    If GUICtrlRead($cnTarget) = '' Then
        MsgBox(16, "", 'Target machine must be entered')
    Else
        SplashTextOn($sTitle, "Transfering Mapped Drives", 165, 40, -1, -1, 2, "", 9)
        Local $masset = GUICtrlRead($cnTarget)
        DirCreate("c:\Temp\Drives")
        Local $mapLocation = "c:\Temp\Drives\Drives.txt"

        Local $mapFile = FileOpen($mapLocation, 10)
        For $i = 1 To 25
            $b = _HKCU_EnumKey("\\\" & $masset & "\Network", $i)
            $iProdm = 1
            For $j = 1 To $b[0][0]
                $iProdm *= $b[$j][2]
                If $b[$j][2] = 0 Then
                    $Path = _HKCU_Read("\\\" & $masset & "\\" & $b[$j][0] & "\Network\" & $b[$j][1], "RemotePath")
                    FileWriteLine($mapFile, $b[$j][1] & "," & $Path[1][1])
                EndIf
            Next
            If $iProdm <> 0 Then ExitLoop
        Next
        SplashOff()
        FileClose("c:\Temp\Drives\Drives.txt")
    EndIf

    GUICreate("Network Drives", 520, 125)
    $listview = GUICtrlCreateListView("", 10, 10, 495, 100)
    GUISetState()

    _GUICtrlListView_AddColumn($listview, "Drive Letter", 100)
    _GUICtrlListView_AddColumn($listview, "Mapped Path", 100)
    _GUICtrlListView_AddArray($listview, $Path)
EndFunc   ;==>Drives
Edited by surreal

Share this post


Link to post
Share on other sites

thanks to everyone that has looked over this so far. im still not able to get this to work. maybe GUICtrlCreateListView is not the correct format to accomplish what i need?

d@ve

Share this post


Link to post
Share on other sites

any help would be great, is this maybe in the wrong part of the forum?

d@ve

Share this post


Link to post
Share on other sites

any help would be great, is this maybe in the wrong part of the forum?

d@ve

If other people are like me then I can explain why you haven't had any help so far. What I would prefer is

1) a consise explanation of your problem

2) a simple sample script which shows the problem or difficulty you have without any changes. Preferably without needing extra downloads.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

At this point it's beyond me until I have time to sit and learn the code to see what's going on.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

thx kaotkbliss!

martin, i have included the code, the only reason for the download as well is cause of the extra #includes. trying to have the gathered array information port into some kinda of popup that a user can select via checkbox what to or what not to install. the gathered information is from a remote system or local if you enter in the current computer name, the arrays gather the printers and mapped drives.

thanks everyone!

d@ve

Edited by surreal

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

i now have the array working with the GUICtrlCreateListView with checkboxes. was wondering if anyone could point me in the right direction on how to now get the map drives button to work. i would like it to take the listitem that is checked or the items and install the mapped drives on the local system, using something like DriveMapAdd. just not sure how to code this with the gathered info. thanks...

added: when trying to use DriveMapAdd("X:", "\\myserver\stuff") my problem comes in with the array grabbing the pipe "|". also im not sure if DriveMapAdd can handel more then one from the array?

below is the working code

updated fuction

;===Function For Mapped Drives=====================================================================
Func Drives()
    Local $masset = GUICtrlRead($cnTarget)
    If GUICtrlRead($cnTarget) = '' Then
        MsgBox(16, "", 'Target machine must be entered')
        Return
    Else
        $List_Drives = GUICreate("Mapped Drives (" & $masset & ")", 320, 250, 350, 250, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
        GUISetBkColor(0xD4D0C8)
        $View = GUICtrlCreateListView("Drive | Path", 0, 0, 320, 200, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES))
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 250)
        GUISetState()
        $MDButton = GUICtrlCreateButton("Map Drive(s)", 120, 210, 75, 30, $WS_GROUP)
    EndIf
    For $i = 1 To 25
        $b = _HKCU_EnumKey("\\\" & $masset & "\Network", $i)
        $iProdm = 1
        For $j = 1 To $b[0][0]
            $iProdm *= $b[$j][2]
            If $b[$j][2] = 0 Then
                $Path = _HKCU_Read("\\\" & $masset & "\\" & $b[$j][0] & "\Network\" & $b[$j][1], "RemotePath")
                GUICtrlCreateListViewItem(" " & $b[$j][1] & " | " & $Path[1][1] & "", $View)
            EndIf
        Next
        If $iProdm <> 0 Then ExitLoop
    Next
    GUISetState(@SW_SHOW)
    While 1
        $mdmsg = GUIGetMsg()
        Select
            Case $mdmsg = $MDButton
                Local $item_count = _GUICtrlListView_GetItemCount($View)
                Local $is_checked, $items_checked, $file_array[1]
                For $i = 0 To $item_count - 1
                    $is_checked = _GUICtrlListView_GetItemChecked($View, $i)
                    If Not @error Then
                        $items_checked += $is_checked
                        If ($is_checked) Then
                            If ($items_checked = 1) Then
                                _ArrayInsert($file_array, 0, _GUICtrlListView_GetItemTextString($View, $i))
                                _ArrayDelete($file_array, 1)
                            Else
                                _ArrayAdd($file_array, _GUICtrlListView_GetItemTextString($View, $i))
                            EndIf
                        EndIf
                    EndIf
                Next
                If ($items_checked <> 0) Then
                    If Not @error Then
                        For $i = 0 To $items_checked - 1
                            MsgBox(0, "Mapped Drive", $file_array[$i])
                        Next
                    EndIf
                Else
                    MsgBox(0, "Mapped Drive", "ERROR")
                EndIf
            Case $mdmsg = $GUI_EVENT_CLOSE
                GUIDelete($List_Drives)
                ExitLoop
                GUISwitch($ParentWin)
                GUISetState(@SW_SHOW, $ParentWin)
        EndSelect
    WEnd
EndFunc   ;==>Drives

full code

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <HKCUReg.au3>
#include <Array.au3>
#include <Surreal.au3>
#include <GuiStatusBar.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>

;===Checks Local OSVersion Create Var User Friendly================================================
$OS = @OSVersion
$OS = StringReplace($OS, "WIN_VISTA", "Windows Vista")
$OS = StringReplace($OS, "WIN_XP", "Windows XP")
$OS = StringReplace($OS, "WIN_2000", "Windows 2000")
;===Determines Documents Location According To OS++================================================
$OSDOC = @OSVersion
If $OSDOC = "WIN_VISTA" Then $DOC = "\Users\"
If $OSDOC = "WIN_XP" Then
    $DOC = "\Documents and Settings\"
EndIf
$OSDF = @OSVersion
If $OSDF = "WIN_VISTA" Then $DF = "Documents"
If $OSDF = "WIN_XP" Then
    $DF = "My Documents"
EndIf

Global $Lotus_Location
Local $sTitle = 'eMigrate'
Local $backup = "\Migrate_Backup\"
Local $network = "c:\Temp\Migrate_Network\"
Local $restore = "\Migrate_Restore\"
Local $LogFile = "c:\Temp\LogFile.txt"
Local $Separator = "------------------------------"
Local $LogFileLocation = @ProgramFilesDir & "\" & $sTitle & "\eMigrate.txt"

;===GUI Start and File Menu========================================================================
$ParentWin = GUICreate("", 330, 185, -1, -1)

$FileMenu = GUICtrlCreateMenu("&File")
$BKItem = GUICtrlCreateMenuItem("Backup Only", $FileMenu)
$RSItem = GUICtrlCreateMenuItem("Restore Only", $FileMenu)
$ExitItem = GUICtrlCreateMenuItem("Exit", $FileMenu)
$ViewMenu = GUICtrlCreateMenu("&View")
$LogItem = GUICtrlCreateMenuItem("Log File", $ViewMenu)
$ProMenu = GUICtrlCreateMenu("&Programs")
$RDItem = GUICtrlCreateMenuItem("Remote Desktop", $ProMenu)
$CMItem = GUICtrlCreateMenuItem("Computer Management", $ProMenu)
$PRItem = GUICtrlCreateMenuItem("Migrate Printers", $ProMenu)
$MDItem = GUICtrlCreateMenuItem("Migrate Mapped Drives", $ProMenu)
$CPItem = GUICtrlCreateMenuItem("Command Prompt", $ProMenu)
$HelpMenu = GUICtrlCreateMenu("&Help")
$HelpItem = GUICtrlCreateMenuItem($sTitle & " Help", $HelpMenu)
GUICtrlSetState($BKItem, $GUI_UNCHECKED)
GUICtrlSetState($RSItem, $GUI_UNCHECKED)

;===GUI Network Computer To Tranfer From===========================================================
GUICtrlCreateGroup("System", 10, 10, 190, 75)
GUICtrlCreateLabel("Computer Name:", 20, 25)
$cnTarget = GUICtrlCreateInput(@ComputerName, 20, 40, 120, 20)
$cnMessage = GUICtrlCreateLabel("Enter computer name or ip address", 20, 64, 175, 15)
$cnButton = GUICtrlCreateButton("Connect", 145, 35, 50, 25, $WS_GROUP)

;===GUI Network User Profile=======================================================================
GUICtrlCreateGroup("Profile:", 10, 90, 190, 45)
$prCombo = GUICtrlCreateCombo("", 20, 105, 175, 20)

;===GUI Group What To Migrate======================================================================
GUICtrlCreateGroup("Tranfer", 210, 10, 110, 80)
$Box_Documents = GUICtrlCreateCheckbox("My Documents", 220, 25)
$Box_IEFav = GUICtrlCreateCheckbox("IE Favorites", 220, 45)
$Box_Notes = GUICtrlCreateCheckbox("Lotus Notes", 220, 65)
GUICtrlSetState($Box_Documents, $GUI_CHECKED)
GUICtrlSetState($Box_IEFav, $GUI_CHECKED)
GUICtrlSetState($Box_Notes, $GUI_UNCHECKED)

;===GUI Start Function=============================================================================
$StartButton = GUICtrlCreateButton("Start", 230, 100, 65, 30, $WS_GROUP)
$StatusBar = _GUICtrlStatusBar_Create($ParentWin)
_GUICtrlStatusBar_SetMinHeight($StatusBar, 5)
GUISetState(@SW_SHOW)

;===Start Of GUIGetMsg=============================================================================
While 1
    $msg = GUIGetMsg()
    Select

        ;===Case For Exit GUI==============================================================================
        Case $msg = $ExitItem Or $msg = $GUI_EVENT_CLOSE
            $FormClose = MsgBox(36, "", "Are you sure you want to exit?")
            If $FormClose = 6 Then
                GUIDelete()
                Exit
            EndIf

            ;===Case For File Menu Items=======================================================================
        Case $msg = $BKItem
            If BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($BKItem, $GUI_UNCHECKED)
                _GUICtrlStatusBar_SetText($StatusBar, "")
            Else
                GUICtrlSetState($BKItem, $GUI_CHECKED)
                Local $BKtarget = FileSelectFolder("Choose the location you want to back up to:" & @CRLF & "A backup folder (eMigrate) will be created", "", 1)
                _GUICtrlStatusBar_SetText($StatusBar, " Backup Mode Enabled")
                GUICtrlSetData($cnTarget, @ComputerName)
                GUICtrlSetState($RSItem, $GUI_UNCHECKED)
                Connect()
            EndIf
            If $BKtarget = '' Then
                GUICtrlSetState($BKItem, $GUI_UNCHECKED)
                _GUICtrlStatusBar_SetText($StatusBar, "")
            EndIf
        Case $msg = $RSItem
            If BitAND(GUICtrlRead($RSItem), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($RSItem, $GUI_UNCHECKED)
                _GUICtrlStatusBar_SetText($StatusBar, "")
            Else
                GUICtrlSetState($RSItem, $GUI_CHECKED)
                Local $RStarget = FileSelectFolder("Choose the location you want to restore from:" & @CRLF & "Select the (eMigrate) folder you created", "")
                _GUICtrlStatusBar_SetText($StatusBar, " Restore Mode Enabled")
                GUICtrlSetData($cnTarget, @ComputerName)
                GUICtrlSetState($BKItem, $GUI_UNCHECKED)
                Connect()
            EndIf
            If $RStarget = '' Then
                GUICtrlSetState($RSItem, $GUI_UNCHECKED)
                _GUICtrlStatusBar_SetText($StatusBar, "")
            EndIf
        Case $msg = $HelpItem
            MsgBox(64, $sTitle, "Help File Coming Soon")
        Case $msg = $RDItem
            Run('mstsc.exe', @SystemDir)
        Case $msg = $CMItem
            ShellExecute('compmgmt.msc', @SystemDir, @SW_MAXIMIZE)
        Case $msg = $LogItem
            If FileExists($LogFileLocation) Then
                ShellExecute($LogFileLocation, "")
            Else
                MsgBox(48, $sTitle, "A Log File has not been created yet.")
            EndIf
        Case $msg = $CPItem
            Run('cmd.exe', @SystemDir)
            ;===Case For Mapped Drives and Printers not working yet============================================
        Case $msg = $MDItem
            If GUICtrlRead($cnTarget) = '' Then
                MsgBox(16, "", 'Target machine must be entered')
            Else
                Drives()
            EndIf
        Case $msg = $PRItem
            If GUICtrlRead($cnTarget) = '' Then
                MsgBox(16, "", 'Target machine must be entered')
            Else
                Printers()
                FileClose("c:\Temp\Printers\Printers.txt")
                MsgBox(64, $sTitle, "File has been created (c:\Temp\Printers)")
            EndIf

            ;===Case For Lotus Notes CheckBox==================================================================
        Case $msg = $Box_Notes
            If GUICtrlRead($cnTarget) = '' Or GUICtrlRead($prCombo) = '' Then
                MsgBox(16, "", 'Target machine and a profile must be entered')
                GUICtrlSetState($Box_Notes, $GUI_UNCHECKED)
            EndIf

            If BitAND(GUICtrlRead($Box_Notes), $GUI_UNCHECKED) = $GUI_UNCHECKED Then
                GUICtrlSetState($Box_Notes, $GUI_UNCHECKED)
            Else
                Lotus()
                GUICtrlSetState($Box_Notes, $GUI_CHECKED)
            EndIf
            ;===Case For Connect===============================================================================
        Case $msg = $cnButton
            If GUICtrlRead($cnTarget) = '' Then
                GUICtrlSetData($cnMessage, 'Target machine must be entered')
                GUICtrlSetColor($cnMessage, 0xFF0000)
                ContinueLoop
            EndIf
            $Log = FileOpen($LogFile, 10)
            FileWriteLine($LogFile, "Started: " & @MON & "/" & @MDAY & "/" & @YEAR & " at " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF & @CRLF & "System Info" & @CRLF & $Separator & @CRLF)
            FileWriteLine($LogFile, "Operating System: " & $OS & @CRLF & "Computer Name: " & @ComputerName & @CRLF)
            FileClose($LogFile)
            Connect()

        Case $msg = $StartButton
            If GUICtrlRead($cnTarget) = '' Or GUICtrlRead($prCombo) = '' Then
                MsgBox(16, "", 'Target machine and a profile must be entered')
            Else
                StartButton()
            EndIf
    EndSelect
WEnd

;===Function For Remote System InfoBox=============================================================
Func Connect()
    SplashTextOn("", "Querying Network", 165, 40, -1, -1, 2, "", 9)
    Sleep(1000)
    If Ping(GUICtrlRead($cnTarget)) Then
        $strComputer = GUICtrlRead($cnTarget)
        $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
        SplashOff()
        If Not IsObj($objWMIService) Then
            GUICtrlSetData($cnMessage, 'Failed to connect to system')
            GUICtrlSetColor($cnMessage, 0xFF0000)
            Return
        EndIf
        ;===WMI BIOS
        $colItems1 = $objWMIService.ExecQuery("SELECT * FROM Win32_Bios")
        $message = "System Info for " & $strComputer & @CRLF & $Separator & @CRLF & @CRLF
        For $objItem In $colItems1
            $message &= "Dell Asset Number: " & $objItem.SerialNumber & @CRLF & _
                    "Manufacturer: " & $objItem.Manufacturer & @CRLF & @CRLF
            Global $surreal = $objItem.SerialNumber
            Global $RemoteName = $strComputer
        Next
        ;===WMI NETWORK
        $colItems2 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
        For $objItem In $colItems2
            $message &= "IP Address: " & $objItem.IPAddress(0) & @CRLF & _
                    "IP Subnet: " & $objItem.IPSubnet(0) & @CRLF & @CRLF
        Next
        ;===WMI SYSTEM
        $colItems3 = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
        For $objItem In $colItems3
            $message &= "Model: " & $objItem.Model & @CRLF & _
                    "Computer Name: " & $objItem.Name & @CRLF & _
                    "Last User: " & $objItem.UserName & @CRLF
            Global $RemoteUser = $objItem.UserName
        Next
        GUICtrlSetData($cnMessage, 'Connected, select user profile')
        GUICtrlSetColor($cnMessage, 0x008000)
        MsgBox(64, "System Information", $message)
    Else
        SplashOff()
        GUICtrlSetData($cnMessage, 'Target system could not be contacted')
        GUICtrlSetColor($cnMessage, 0xFF0000)
        Return
    EndIf
    Profile()
EndFunc   ;==>Connect

;===Function For Remote Profile Load===============================================================
Func Profile()
    Local $combo_string = ""
    $FolderList = _FileListToArray("\\" & GUICtrlRead($cnTarget) & "\c$" & $DOC, "*", 2)
    For $i = 1 To $FolderList[0]
        Switch $FolderList[$i]
            Case "All Users", "Default User", "LocalService", "NetworkService"
                ContinueLoop
            Case Else
                If $i = $FolderList[0] Then
                    $combo_string &= $FolderList[$i]
                Else
                    $combo_string &= $FolderList[$i] & "|"
                EndIf
        EndSwitch
    Next
    GUICtrlSetData($prCombo, $combo_string)
EndFunc   ;==>Profile

;===Function For Checkbox Actions==================================================================
Func StartButton()
    Local $Path = "\\" & GUICtrlRead($cnTarget)
    Local $rmdocs = $Path & "\c$" & $DOC & GUICtrlRead($prCombo) & "\" & $DF
    Local $rmfavs = $Path & "\c$" & $DOC & GUICtrlRead($prCombo) & "\Favorites"
    Local $LotusProgram = @ProgramFilesDir & "\Lotus\Notes\Data"
    ;====================My Documents
    If GUICtrlRead($Box_Documents) = $GUI_CHECKED And BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        ;-----Backup
        _GUICtrlStatusBar_SetText($StatusBar, " Backing Up My Documents")
        DirCreate($BKtarget & $backup & $DF & "\" & GUICtrlRead($prCombo))
        _CopyWithProgress($rmdocs & "\*.*", $BKtarget & $backup & $DF & "\" & GUICtrlRead($prCombo))
        FileWriteLine($LogFile, "My Documents" & @TAB & "(Backup Successful)" & @CRLF)
    ElseIf GUICtrlRead($Box_Documents) = $GUI_CHECKED And BitAND(GUICtrlRead($RSItem), $GUI_CHECKED) = $GUI_CHECKED Then
        ;-----Restore
        _GUICtrlStatusBar_SetText($StatusBar, " Restoring My Documents")
        _CopyWithProgress($RStarget & $DF & "\" & GUICtrlRead($prCombo) & "\*.*", "c:" & $DOC & GUICtrlRead($prCombo) & "\" & $DF)
        FileWriteLine($LogFile, "My Documents" & @TAB & "(Restore Successful)" & @CRLF)
    ElseIf GUICtrlRead($Box_Documents) = $GUI_CHECKED Then
        ;-----Network
        _GUICtrlStatusBar_SetText($StatusBar, " Transferring My Documents")
        _CopyWithProgress($rmdocs & "\*.*", "c:" & $DOC & GUICtrlRead($prCombo) & "\" & $DF)
        FileWriteLine($LogFile, "My Documents" & @TAB & "(Network Successful)" & @CRLF)
    EndIf
    ;====================Favorites
    If GUICtrlRead($Box_IEFav) = $GUI_CHECKED And BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        ;-----Backup
        _GUICtrlStatusBar_SetText($StatusBar, " Backing Up Favorites")
        GUICtrlSetColor($cnMessage, 0x008000)
        DirCreate($BKtarget & $backup & "Favorites")
        _CopyWithProgress($rmfavs & "\*.*", $BKtarget & $backup & "Favorites")
        FileWriteLine($LogFile, "Favorites" & @TAB & "(Backup Successful)" & @CRLF)
    ElseIf GUICtrlRead($Box_IEFav) = $GUI_CHECKED And BitAND(GUICtrlRead($RSItem), $GUI_CHECKED) = $GUI_CHECKED Then
        ;-----Restore
        _GUICtrlStatusBar_SetText($StatusBar, " Restoring Favorites")
        _CopyWithProgress($RStarget & "Favorites" & "\*.*", "c:" & $DOC & GUICtrlRead($prCombo) & "\Favorites")
        FileWriteLine($LogFile, "Favorites" & @TAB & "(Restore Successful)" & @CRLF)
    ElseIf GUICtrlRead($Box_IEFav) = $GUI_CHECKED Then
        ;-----Network
        _GUICtrlStatusBar_SetText($StatusBar, " Transferring Favorites")
        _CopyWithProgress($rmfavs & "\*.*", "c:" & $DOC & GUICtrlRead($prCombo) & "\Favorites")
        FileWriteLine($LogFile, "Favorites" & @TAB & "(Network Successful)" & @CRLF)
    EndIf
    ;====================Lotus Notes
    If GUICtrlRead($Box_Notes) = $GUI_CHECKED And BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        ;-----Backup
        _GUICtrlStatusBar_SetText($StatusBar, " Backing Up Lotus Notes")
        DirCreate($BKtarget & $backup & "Notes")
        _CopyWithProgress($Lotus_Location & "\*.id", $BKtarget & $backup & "Notes")
        _CopyWithProgress($Lotus_Location & "\Desktop6.ndk", $BKtarget & $backup & "Notes")
        _CopyWithProgress($Lotus_Location & "\Names.nsf", $BKtarget & $backup & "Notes")
        _CopyWithProgress($Lotus_Location & "\User.dic", $BKtarget & $backup & "Notes")
        DirCreate($BKtarget & $backup & "Notes\Archive")
        _CopyWithProgress($Lotus_Location & "\Archive\*.*", $BKtarget & $backup & "Notes\Archive")
        FileWriteLine($LogFile, "Lotus Notes" & @TAB & "(Backup Successful)" & @CRLF)
    ElseIf GUICtrlRead($Box_Notes) = $GUI_CHECKED And BitAND(GUICtrlRead($RSItem), $GUI_CHECKED) = $GUI_CHECKED Then
        ;-----Restore
        _GUICtrlStatusBar_SetText($StatusBar, " Restoring Lotus Notes")
        _CopyWithProgress($RStarget & "Notes" & "\*.*", $LotusProgram)
        FileWriteLine($LogFile, "Lotus Notes" & @TAB & "(Restore Successful)" & @CRLF)
    ElseIf GUICtrlRead($Box_Notes) = $GUI_CHECKED Then
        ;-----Network
        _GUICtrlStatusBar_SetText($StatusBar, " Transferring Lotus Notes")
        _CopyWithProgress($Lotus_Location & "\*.id", $LotusProgram)
        _CopyWithProgress($Lotus_Location & "\Desktop6.ndk", $LotusProgram)
        _CopyWithProgress($Lotus_Location & "\Names.nsf", $LotusProgram)
        _CopyWithProgress($Lotus_Location & "\User.dic", $LotusProgram)
        DirCreate($LotusProgram & "\Archive")
        _CopyWithProgress($Lotus_Location & "\Archive\*.*", $LotusProgram & "\Archive")
        FileWriteLine($LogFile, "Lotus Notes" & @TAB & "(Network Successful)" & @CRLF)
    EndIf
    SoundPlay(@WindowsDir & "\media\tada.wav", 1)
    $Success = MsgBox(4, "", "Migration Was Successful. Do You Want To Exit?")
    If $Success = 6 Then Exit
EndFunc   ;==>StartButton

;===Function For Save Printer Info File============================================================
Func Printers()
    If GUICtrlRead($cnTarget) = '' Then
        MsgBox(16, "", 'Target machine must be entered')
    Else
        SplashTextOn($sTitle, "Transfering Printers", 165, 40, -1, -1, 2, "", 9)
        Local $passet = GUICtrlRead($cnTarget)
        DirCreate("c:\Temp\Printers")
        Local $pLocation = "c:\Temp\Printers\Printers.txt"

        Local $pFile = FileOpen($pLocation, 10)
        For $i = 1 To 25
            $p = _HKCU_EnumVal("\\\" & $passet & "\Software\Microsoft\Windows NT\CurrentVersion\Devices", $i)
            $iProdp = 1
            For $n = 1 To $p[0][0]
                $iProdp *= $p[$n][2]
                If $p[$n][2] = 0 Then
                    $ppath = _HKCU_Read("\\\" & $passet & "\\" & $p[$n][1], "Devices")
                EndIf
                If StringRegExp($p[$n][1], "^\\\\(?!\\)") Then
                    FileWriteLine($pFile, $p[$n][1] & "," & $ppath[1][1])
                EndIf
            Next
            If $iProdp <> 0 Then ExitLoop
        Next
        SplashOff()

    EndIf
    Return
EndFunc   ;==>Printers

;===Function For Mapped Drives=====================================================================
Func Drives()
    Local $masset = GUICtrlRead($cnTarget)
    If GUICtrlRead($cnTarget) = '' Then
        MsgBox(16, "", 'Target machine must be entered')
        Return
    Else
        $List_Drives = GUICreate("Mapped Drives (" & $masset & ")", 320, 250, 350, 250, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
        GUISetBkColor(0xD4D0C8)
        $View = GUICtrlCreateListView("Drive | Path", 0, 0, 320, 200, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES))
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
        GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 250)
        GUISetState()
        $MDButton = GUICtrlCreateButton("Map Drive(s)", 120, 210, 75, 30, $WS_GROUP)
    EndIf
    For $i = 1 To 25
        $b = _HKCU_EnumKey("\\\" & $masset & "\Network", $i)
        $iProdm = 1
        For $j = 1 To $b[0][0]
            $iProdm *= $b[$j][2]
            If $b[$j][2] = 0 Then
                $Path = _HKCU_Read("\\\" & $masset & "\\" & $b[$j][0] & "\Network\" & $b[$j][1], "RemotePath")
                GUICtrlCreateListViewItem(" " & $b[$j][1] & " | " & $Path[1][1] & "", $View)
            EndIf
        Next
        If $iProdm <> 0 Then ExitLoop
    Next
    GUISetState(@SW_SHOW)
    While 1
        $mdmsg = GUIGetMsg()
        Select
            Case $mdmsg = $MDButton
                Local $item_count = _GUICtrlListView_GetItemCount($View)
                Local $is_checked, $items_checked, $file_array[1]
                For $i = 0 To $item_count - 1
                    $is_checked = _GUICtrlListView_GetItemChecked($View, $i)
                    If Not @error Then
                        $items_checked += $is_checked
                        If ($is_checked) Then
                            If ($items_checked = 1) Then
                                _ArrayInsert($file_array, 0, _GUICtrlListView_GetItemTextString($View, $i))
                                _ArrayDelete($file_array, 1)
                            Else
                                _ArrayAdd($file_array, _GUICtrlListView_GetItemTextString($View, $i))
                            EndIf
                        EndIf
                    EndIf
                Next
                If ($items_checked <> 0) Then
                    If Not @error Then
                        For $i = 0 To $items_checked - 1
                            MsgBox(0, "Mapped Drive", $file_array[$i])
                        Next
                    EndIf
                Else
                    MsgBox(0, "Mapped Drive", "ERROR")
                EndIf
            Case $mdmsg = $GUI_EVENT_CLOSE
                GUIDelete($List_Drives)
                ExitLoop
                GUISwitch($ParentWin)
                GUISetState(@SW_SHOW, $ParentWin)
        EndSelect
    WEnd
EndFunc   ;==>Drives

;===Function For Lotus Notes Child Window==========================================================
Func Lotus()
    $ChildWin = GUICreate("", 135, 110, -1, -1, $WS_EX_TOPMOST)
    GUISetBkColor(0xFFFFFF)
    GUISwitch($ChildWin)
    $Box_Single = GUICtrlCreateRadio("Single User Install", 10, 10)
    $Box_Multi = GUICtrlCreateRadio("Multi User Install", 10, 30)
    $Box_System = GUICtrlCreateRadio("Root System Install", 10, 50)
    GUISetState()
    While 1
        $lnmsg = GUIGetMsg()
        Select
            Case $lnmsg = $Box_Single And BitAND(GUICtrlRead($Box_Single), $GUI_CHECKED) = $GUI_CHECKED
                $Lotus_Location = "\\" & GUICtrlRead($cnTarget) & "\c$\Program Files\Lotus\Notes\Data"
                Sleep(200)
                GUIDelete($ChildWin)
                ExitLoop
                GUISwitch($ParentWin)
                GUISetState(@SW_SHOW, $ParentWin)
            Case $lnmsg = $Box_Multi And BitAND(GUICtrlRead($Box_Multi), $GUI_CHECKED) = $GUI_CHECKED
                $Lotus_Location = "\\" & GUICtrlRead($cnTarget) & "\c$" & $DOC & GUICtrlRead($prCombo) & "\Local Settings\Application Data\Lotus\Notes\Data"
                Sleep(200)
                GUIDelete($ChildWin)
                ExitLoop
                GUISwitch($ParentWin)
                GUISetState(@SW_SHOW, $ParentWin)
            Case $lnmsg = $Box_System And BitAND(GUICtrlRead($Box_System), $GUI_CHECKED) = $GUI_CHECKED
                $Lotus_Location = "\\" & GUICtrlRead($cnTarget) & "\c$\Lotus\Notes\Data"
                Sleep(200)
                GUIDelete($ChildWin)
                ExitLoop
                GUISwitch($ParentWin)
                GUISetState(@SW_SHOW, $ParentWin)
        EndSelect
    WEnd
EndFunc   ;==>Lotus

below are the includeds

HKCUReg.au3

#include-once
#include <File.au3>
#include <Security.au3>
#include ".\Reg.au3"

; #INDEX# =======================================================================================================================================
; Title .........: HKCUReg
; AutoIt Version : 3.2.10++
; Language ......: English
; Description ...: Perform registry operations on 'HKCU' for a specific or all user accounts on a computer
; ===============================================================================================================================================

; #CURRENT# =====================================================================================================================================
;_HKCU_Delete
;_HKCU_EnumKey
;_HKCU_EnumVal
;_HKCU_Import
;_HKCU_Read
;_HKCU_Write
; ===============================================================================================================================================

; #INTERNAL_USE_ONLY#============================================================================================================================
;GetProfile
;ProfileAdd
;Split_sKey
; ===============================================================================================================================================

; #FUNCTION# ====================================================================================================================================
; Name...........: _HKCU_Delete
; Description ...: Deletes a key or value from the registry
; Syntax.........: _HKCU_Delete($sKey [, $sValue])
; Parameters ....: $sKey - see RegDelete function for details (no 'HKCU' required)
;                  $sValue - [optional] see RegDelete function for details
; Requirement(s).:
; Return values .: Returns an Array where:
;                  Column 0 - User account name
;                  Column 1 - RegDelete function return value
;                  Column 2 - RegDelete function @error macro
; Author ........: engine
; Modified.......:
; Remarks .......: It is possible to access remote registries by using $sKey in the form "\\\computername\keyname"
;                  It is possible to access a specific user account by using $sKey in the form "\\username\keyname"
;                  It is possible to access both a remote registry and a specific user account by using $sKey in the form
;                  "\\\computername\\username\keyname"
; Related .......:
; Link ..........;
; Examples ......;  _HKCU_Delete("Software\7-Zip", "Path")
;                   _HKCU_Delete("\\\computername\Software\7-Zip", "Path")
;                   _HKCU_Delete("\\username\Software\7-Zip", "Path")
;                   _HKCU_Delete("\\\computername\\username\Software\7-Zip", "Path")
; ===============================================================================================================================================

Func _HKCU_Delete($sKey, $sValue = Default)
    Local $asSplit = Split_sKey($sKey)
    Local $avProfile = GetProfile($asSplit[1], $asSplit[0])
    Local $avArray[$avProfile[0][0] + 1][3], $iLoaded, $iResult
    $avArray[0][0] = $avProfile[0][0]
    For $i = 1 To $avProfile[0][0]
        If $avProfile[$i][3] = 0 Then
            $iLoaded = _RegLoadHive($avProfile[$i][1] & "\NTUSER.DAT", $avProfile[$i][2])
        EndIf
        If $sValue = Default Then
            $iResult = RegDelete($avProfile[$i][2] & "\" & $asSplit[2])
        Else
            $iResult = RegDelete($avProfile[$i][2] & "\" & $asSplit[2], $sValue)
        EndIf
        $avArray[$i][0] = $avProfile[$i][0]
        $avArray[$i][1] = $iResult
        $avArray[$i][2] = @error
        If $iLoaded Then _RegUnloadHive($avProfile[$i][2])
    Next
    Return $avArray
EndFunc ;==> _HKCU_Delete

; #FUNCTION# ====================================================================================================================================
; Name...........: _HKCU_EnumKey
; Description ...: Reads the name of a subkey according to it's instance
; Syntax.........: _HKCU_EnumKey($sKey, $iInstance)
; Parameters ....: $sKey - see RegEnumKey function for details (no 'HKCU' required)
;                  $iInstance - see RegEnumKey function for details
; Requirement(s).:
; Return values .: Returns an Array where:
;                  Column 0 - User account name
;                  Column 1 - RegEnumKey function return value
;                  Column 2 - RegEnumKey function @error macro
; Author ........: engine
; Modified.......:
; Remarks .......: It is possible to access remote registries by using $sKey in the form "\\\computername\keyname"
;                  It is possible to access a specific user account by using $sKey in the form "\\username\keyname"
;                  It is possible to access both a remote registry and a specific user account by using $sKey in the form
;                  "\\\computername\\username\keyname"
; Related .......:
; Link ..........;
; Example .......;
;                  #include <Array.au3>
;                  #include "HKCUReg.au3"
;
;                  $sComputer = @ComputerName
;
;                  For $i = 1 To 100
;                       $b = _HKCU_EnumKey("\\\" & $sComputer & "\Software", $i)
;                       $iProd = 1
;                       For $j = 1 To $b[0][0]
;                           $iProd *= $b[$j][2]
;                       Next
;                       If $iProd <> 0 Then ExitLoop
;                       _ArrayDisplay($b, $i)
;                  Next
; ===============================================================================================================================================

Func _HKCU_EnumKey($sKey, $iInstance)
    Local $asSplit = Split_sKey($sKey)
    Local $avProfile = GetProfile($asSplit[1], $asSplit[0])
    Local $avArray[$avProfile[0][0] + 1][3], $iLoaded
    $avArray[0][0] = $avProfile[0][0]
    For $i = 1 To $avProfile[0][0]
        If $avProfile[$i][3] = 0 Then
            $iLoaded = _RegLoadHive($avProfile[$i][1] & "\NTUSER.DAT", $avProfile[$i][2])
        EndIf
        $avArray[$i][0] = $avProfile[$i][0]
        $avArray[$i][1] = RegEnumKey($avProfile[$i][2] & "\" & $asSplit[2], $iInstance)
        $avArray[$i][2] = @error
        If $iLoaded Then _RegUnloadHive($avProfile[$i][2])
    Next
    Return $avArray
EndFunc ;==> _HKCU_EnumKey

; #FUNCTION# ====================================================================================================================================
; Name...........: _HKCU_EnumVal
; Description ...: Reads the name of a value according to it's instance
; Syntax.........: _HKCU_EnumVal($sKey, $iInstance)
; Parameters ....: $sKey - see RegEnumVal function for details (no 'HKCU' required)
;                  $iInstance - see RegEnumVal function for details
; Requirement(s).:
; Return values .: Returns an Array where:
;                  Column 0 - User account name
;                  Column 1 - RegEnumVal function return value
;                  Column 2 - RegEnumVal function @error macro
;                  Column 3 - RegEnumVal function @extended macro
; Author ........: engine
; Modified.......:
; Remarks .......: It is possible to access remote registries by using $sKey in the form "\\\computername\keyname"
;                  It is possible to access a specific user account by using $sKey in the form "\\username\keyname"
;                  It is possible to access both a remote registry and a specific user account by using $sKey in the form
;                  "\\\computername\\username\keyname"
; Related .......:
; Link ..........;
; Example .......;
;                  #include <Array.au3>
;                  #include "HKCUReg.au3"
;
;                  $sComputer = @ComputerName
;
;                  For $i = 1 To 100
;                       $b = _HKCU_EnumVal("\\\" & $sComputer & "\Software\AutoIt v3\Aut2Exe", $i)
;                       $iProd = 1
;                       For $j = 1 To $b[0][0]
;                           $iProd *= $b[$j][2]
;                       Next
;                       If $iProd <> 0 Then ExitLoop
;                       _ArrayDisplay($b, $i)
;                  Next
; ===============================================================================================================================================

Func _HKCU_EnumVal($sKey, $iInstance)
    Local $asSplit = Split_sKey($sKey)
    Local $avProfile = GetProfile($asSplit[1], $asSplit[0])
    Local $avArray[$avProfile[0][0] + 1][4], $iLoaded
    $avArray[0][0] = $avProfile[0][0]
    For $i = 1 To $avProfile[0][0]
        If $avProfile[$i][3] = 0 Then
            $iLoaded = _RegLoadHive($avProfile[$i][1] & "\NTUSER.DAT", $avProfile[$i][2])
        EndIf
        $avArray[$i][0] = $avProfile[$i][0]
        $avArray[$i][1] = RegEnumVal($avProfile[$i][2] & "\" & $asSplit[2], $iInstance)
        $avArray[$i][2] = @error
        $avArray[$i][3] = @extended
        If $iLoaded Then _RegUnloadHive($avProfile[$i][2])
    Next
    Return $avArray
EndFunc ;==> _HKCU_EnumVal

; #FUNCTION# ====================================================================================================================================
; Name...........: _HKCU_Import
; Description ...: Imports a previously exported reg file to the registry
; Syntax.........: _HKCU_Import($sReg [, $sName])
; Parameters ....: $sReg - Path and filename of the file to be imported, file extension (.reg)
;                  $sName - User account name, defaults to all users
; Requirement(s).: Registry Console Tool
; Return values .: Returns an Array where:
;                  Column 0 - User account name
;                  Column 1 - Return value:
;                           1 - Success
;                           0 - Failure
;                  Column 2 - @error macro:
;                           1 - Failure
;                           0 - Success
; Author ........: engine
; Modified.......:
; Remarks .......: This function doesn't support remote computers
; Related .......:
; Link ..........;
; Examples ......;  _HKCU_Import("ffdshow.reg")
;                   _HKCU_Import("ffdshow.reg", "Guest")
; ===============================================================================================================================================

Func _HKCU_Import($sReg, $sName = "")
    Local $avProfile = GetProfile($sName)
    Local $avArray[$avProfile[0][0] + 1][3], $iLoaded, $avReg, $sReplace, $sTempReg, $iResult
    $avArray[0][0] = $avProfile[0][0]
    For $i = 1 To $avProfile[0][0]
        If $avProfile[$i][3] = 0 Then
            $iLoaded = _RegLoadHive($avProfile[$i][1] & "\NTUSER.DAT", $avProfile[$i][2])
        EndIf
        _FileReadToArray($sReg, $avReg)
        $sReplace = StringReplace($avProfile[$i][2], "\\" & @ComputerName & "\", "")
        For $k = 1 To $avReg[0]
            $avReg[$k] = StringReplace($avReg[$k], "HKEY_CURRENT_USER", $sReplace)
        Next
        $sTempReg = _TempFile(@UserProfileDir, "~", ".reg")
        _FileWriteFromArray($sTempReg, $avReg, 1)
        $iResult = RunWait('reg import "' & $sTempReg & '"', "", @SW_HIDE)
        $avArray[$i][0] = $avProfile[$i][0]
        $avArray[$i][1] = 1 - $iResult - @error
        $avArray[$i][2] = @error
        FileDelete($sTempReg)
        If $iLoaded Then _RegUnloadHive($avProfile[$i][2])
    Next
    Return $avArray
EndFunc ;==> _HKCU_Import

; #FUNCTION# ====================================================================================================================================
; Name...........: _HKCU_Read
; Description ...: Reads a value from the registry
; Syntax.........: _HKCU_Read($sKey, $sValue)
; Parameters ....: $sKey - see RegRead function for details (no 'HKCU' required)
;                  $sValue - see RegRead function for details
; Requirement(s).:
; Return values .: Returns an Array where:
;                  Column 0 - User account name
;                  Column 1 - RegRead function return value
;                  Column 2 - RegRead function @error macro
;                  Column 3 - RegRead function @extended macro
; Author ........: engine
; Modified.......:
; Remarks .......: It is possible to access remote registries by using $sKey in the form "\\\computername\keyname"
;                  It is possible to access a specific user account by using $sKey in the form "\\username\keyname"
;                  It is possible to access both a remote registry and a specific user account by using $sKey in the form
;                  "\\\computername\\username\keyname"
; Related .......:
; Link ..........;
; Examples ......;  _HKCU_Read("Software\7-Zip", "Path")
;                   _HKCU_Read("\\\computername\Software\7-Zip", "Path")
;                   _HKCU_Read("\\username\Software\7-Zip", "Path")
;                   _HKCU_Read("\\\computername\\username\Software\7-Zip", "Path")
; ===============================================================================================================================================

Func _HKCU_Read($sKey, $sValue)
    Local $asSplit = Split_sKey($sKey)
    Local $avProfile = GetProfile($asSplit[1], $asSplit[0])
    Local $avArray[$avProfile[0][0] + 1][4], $iLoaded
    $avArray[0][0] = $avProfile[0][0]
    For $i = 1 To $avProfile[0][0]
        If $avProfile[$i][3] = 0 Then
            $iLoaded = _RegLoadHive($avProfile[$i][1] & "\NTUSER.DAT", $avProfile[$i][2])
        EndIf
        $avArray[$i][0] = $avProfile[$i][0]
        $avArray[$i][1] = RegRead($avProfile[$i][2] & "\" & $asSplit[2], $sValue)
        $avArray[$i][2] = @error
        $avArray[$i][3] = @extended
        If $iLoaded Then _RegUnloadHive($avProfile[$i][2])
    Next
    Return $avArray
EndFunc ;==> _HKCU_Read

; #FUNCTION# ====================================================================================================================================
; Name...........: _HKCU_Write
; Description ...: Creates a key or value in the registry
; Syntax.........: _HKCU_Write($sKey [, $sValue, $sType, $vData])
; Parameters ....: $sKey - see RegWrite function for details (no 'HKCU' required)
;                  $sValue - [optional] see RegWrite function for details
;                  $sType - [optional] see RegWrite function for details
;                  $vData - [optional] see RegWrite function for details
; Requirement(s).:
; Return values .: Returns an array where:
;                  Column 0 - User account name
;                  Column 1 - RegWrite function return value
;                  Column 2 - RegWrite function @error macro
; Author ........: engine
; Modified.......:
; Remarks .......: It is possible to access remote registries by using $sKey in the form "\\\computername\keyname"
;                  It is possible to access a specific user account by using $sKey in the form "\\username\keyname"
;                  It is possible to access both a remote registry and a specific user account by using $sKey in the form
;                  "\\\computername\\username\keyname"
; Related .......:
; Link ..........;
; Examples ......;  _HKCU_Write("Software\7-Zip", "Path", "REG_SZ", @ProgramFilesDir & "\7-Zip")
;                   _HKCU_Write("\\\computername\Software\7-Zip", "Path", "REG_SZ", @ProgramFilesDir & "\7-Zip")
;                   _HKCU_Write("\\username\Software\7-Zip", "Path", "REG_SZ", @ProgramFilesDir & "\7-Zip")
;                   _HKCU_Write("\\\computername\\username\Software\7-Zip", "Path", "REG_SZ", @ProgramFilesDir & "\7-Zip")
; ===============================================================================================================================================

Func _HKCU_Write($sKey, $sValue = "", $sType = "REG_SZ", $vData = "")
    Local $asSplit = Split_sKey($sKey)
    Local $avProfile = GetProfile($asSplit[1], $asSplit[0])
    Local $avArray[$avProfile[0][0] + 1][3], $iLoaded
    $avArray[0][0] = $avProfile[0][0]
    For $i = 1 To $avProfile[0][0]
        If $avProfile[$i][3] = 0 Then
            $iLoaded = _RegLoadHive($avProfile[$i][1] & "\NTUSER.DAT", $avProfile[$i][2])
        EndIf
        $avArray[$i][0] = $avProfile[$i][0]
        $avArray[$i][1] = RegWrite($avProfile[$i][2] & "\" & $asSplit[2], $sValue, $sType, $vData)
        $avArray[$i][2] = @error
        If $iLoaded Then _RegUnloadHive($avProfile[$i][2])
    Next
    Return $avArray
EndFunc ;==> _HKCU_Write

; #INTERNAL_USE_ONLY#============================================================================================================================
; Name...........: GetProfile
; Description ...: Determine each user's Profile folder, the user's SID and if the profile is loaded to the registry
; Syntax.........: GetProfile([$sAccount, $sComputer])
; Parameters ....: $sAccount - User account name, defaults to all users
;                  $sComputer - Computer name, the local computer is default
; Requirement(s).: Service 'RemoteRegistry' running on the target computer
;                  When the target computer is the local computer, the 'RemoteRegistry' service isn't required
; Return values .: An array containing the path to each user's profile folder, the user's SID
;                  The array returned is two-dimensional and is made up as follows:
;                  $array[0][0] = Number of profiles
;                  $array[1][0] = 1st user name
;                  $array[1][1] = Path to 1st user profile
;                  $array[1][2] = 1st user registry hive
;                  $array[1][3] = 1 if 1st user profile is loaded to the registry, 0 if not
;                  $array[2][0] = 2nd user name
;                  $array[2][1] = Path to 2nd user profile
;                  $array[2][2] = 2nd user registry hive
;                  $array[2][3] = 1 if 2nd user profile is loaded to the registry, 0 if not
;                  ...
;                  $array[n][0] = nth user name
;                  $array[n][1] = Path to nth user profile
;                  $array[n][2] = nth user registry hive
;                  $array[n][3] = 1 if nth user profile is loaded to the registry, 0 if not
; Author ........: engine
; Modified.......:
; Remarks .......: For internal use only
; Related .......:
; Link ..........;
; Example .......; GetProfile("Default User") to get Default User's profile data on the local computer
; ===============================================================================================================================================

Func GetProfile($sAccount = "", $sComputer = @ComputerName)
    Local $avArray[1][4], $sEnv
    Local Const $sProfileListKey = "\\" & $sComputer & "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
    Local Const $sRootKey = "\\" & $sComputer & "\HKEY_USERS\"
    Local Const $sDefaultUser = RegRead($sProfileListKey, "DefaultUserProfile")
    If @error Then
        $avArray[0][0] = 0
        Return $avArray
    EndIf
    If $sAccount = "" Or $sAccount = $sDefaultUser Then
        Local $iInstance, $sSID
        While 1
            $iInstance += 1
            $sSID = RegEnumKey($sProfileListKey, $iInstance)
            If @error Then ExitLoop
            If StringLen($sSID) > 8 Then ProfileAdd($avArray, $sSID, $sProfileListKey, $sRootKey)
        WEnd
        Local $u = UBound($avArray), $iSum
        For $k = 1 To $u - 1
            $iSum += $avArray[$k][3]
        Next
        ReDim $avArray[$u + 1][4]
        $avArray[$u][0] = $sDefaultUser
        $avArray[$u][1] = RegRead($sProfileListKey, "ProfilesDirectory") & "\" & $sDefaultUser
        If $iSum = 0 Then
            $avArray[$u][2] = "\\" & $sComputer & "\HKEY_CURRENT_USER"
            $avArray[$u][3] = 1
        Else
            Local $sDSID, $avDU
            Do
                $sDSID = "S-1-5-21-" & Random(1E+8, 999999999, 1) & "-" & Random(1E+9, 9999999999, 1) & "-" & Random(1E+8, 999999999, 1) & "-" & Random(1E+3, 9999, 1)
                $avDU = _Security__LookupAccountSid($sDSID)
            Until $avDU = 0
            $avArray[$u][2] = $sRootKey & $sDSID
            $avArray[$u][3] = 0
        EndIf
        If $sAccount = $sDefaultUser Then
            Local $avNew[2][4] = [["", "", "", ""], [$avArray[$u][0], $avArray[$u][1], $avArray[$u][2], $avArray[$u][3]]]
            $avArray = $avNew
        EndIf
    Else
        Local $avSID = _Security__LookupAccountName($sAccount, $sComputer)
        ProfileAdd($avArray, $avSID[0], $sProfileListKey, $sRootKey)
    EndIf
    $avArray[0][0] = UBound($avArray) - 1
    For $j = 1 To $avArray[0][0]
        $sEnv = StringRegExp($avArray[$j][1], "\x25\S{1,128}\x25", 1)
        If Not @error Then $avArray[$j][1] = StringReplace( $avArray[$j][1], $sEnv[0], EnvGet( StringReplace($sEnv[0], "%", "") ) )
    Next
    Return $avArray
EndFunc ;==> GetProfile

; #INTERNAL_USE_ONLY#============================================================================================================================
; Name...........: ProfileAdd
; Description ...: Add profile data to an array that will be returned by GetProfile function
; Syntax.........: ProfileAdd($avArray, $sSID, $sProfileListKey, $sRootKey)
; Parameters ....: $avArray - Array
;                  $sSID - Account SID
;                  $sProfileListKey - Constant defined inside GetProfile function
;                  $sRootKey - Constant defined inside GetProfile function
; Requirement(s).:
; Return values .:
; Author ........: engine
; Modified.......:
; Remarks .......: For internal use only
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================================

Func ProfileAdd(ByRef $avArray, $sSID, Const $sProfileListKey, Const $sRootKey)
    Local $avUser = _Security__LookupAccountSid($sSID), $sPath, $i
    If Not @error And $avUser <> 0 Then
        If $avUser[2] = 1 Then
            $sPath = RegRead($sProfileListKey & "\" & $sSID, "ProfileImagePath")
            If Not @error Then
                $i = UBound($avArray)
                ReDim $avArray[$i + 1][4]
                $avArray[$i][0] = $avUser[0]
                $avArray[$i][1] = $sPath
                $avArray[$i][2] = $sRootKey & $sSID
                RegEnumKey($sRootKey & $sSID, 1)
                If @error Then
                    $avArray[$i][3] = 0
                Else
                    $avArray[$i][3] = 1
                EndIf
            EndIf
        EndIf
    EndIf
EndFunc ;==> ProfileAdd

; #INTERNAL_USE_ONLY#============================================================================================================================
; Name...........: Split_sKey
; Description ...: Splits $sKey between computername, username and keyname
; Syntax.........: Split_sKey($sKey)
; Parameters ....: $sKey - Reg function main key
; Requirement(s).:
; Return values .:
; Author ........: engine
; Modified.......:
; Remarks .......: For internal use only
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================================

Func Split_sKey($sKey)
    Local $asArray[3]
    If StringInStr($sKey, "\\\") = 1 Then
        Local $asComputer = StringRegExp($sKey, "\\\\\\[^\\]*\\", 1)
        If Not @error Then
            $asArray[0] = StringTrimRight( StringTrimLeft($asComputer[0], 3), 1 )
            $sKey = StringReplace($sKey, $asComputer[0], "\", 1)
            If Not StringInStr($sKey, "\\") = 1 Then $sKey = StringTrimLeft($sKey, 1)
        EndIf
    EndIf
    If $asArray[0] = "" Then $asArray[0] = @ComputerName
    If StringInStr($sKey, "\\") = 1 And Not StringInStr($sKey, "\\\") = 1 Then
        Local $asUser = StringRegExp($sKey, "\\\\[^\\]*\\", 1)
        If Not @error Then
            $asArray[1] = StringTrimRight( StringTrimLeft($asUser[0], 2), 1 )
            $sKey = StringReplace($sKey, $asUser[0], "", 1)
        EndIf
    EndIf
    If Not ( StringInStr($sKey, "\") = 1 Or StringInStr($sKey, "\", 0, -1) = StringLen($sKey) Or StringInStr($sKey, "\\") ) Then
        $asArray[2] = $sKey
    EndIf
    Return $asArray
EndFunc ;==> Split_sKey

Reg.au3

#include-once
#include <SecurityConstants.au3>
#include "Privilege.au3"

; #INDEX# =======================================================================================================================================
; Title .........: Reg
; AutoIt Version : 3.2.10++
; Language ......: English
; Description ...: Perform operations with registry files
; ===============================================================================================================================================

; #CURRENT# =====================================================================================================================================
;_RegLoadHive
;_RegRestoreHive
;_RegSaveHive
;_RegUnloadHive
; ===============================================================================================================================================

; #INTERNAL_USE_ONLY#============================================================================================================================
;RegCloseKey
;RegConnectRegistry
;RegCreateKeyEx
;RegOpenKeyEx
;Split_sRootKey
; ===============================================================================================================================================

Global Const $KEY_READ = 0x20019
Global Const $KEY_WRITE = 0x20006

; #FUNCTION# ====================================================================================================================================
; Name...........: _RegLoadHive
; Description ...: Loads a file as a registry hive
; Syntax.........: _RegLoadHive($sFile, $sKey)
; Parameters ....: $sFile - Full path to the file to be loaded
;                  $sKey - Registry key to load the file to
;                          Must start with HKEY_LOCAL_MACHINE or HKEY_USERS
; Requirement(s).: None
; Return values .: Success - 1
;                  Failure - 0
;                            Sets @error
; Author ........: engine
; Modified.......:
; Remarks .......: It is possible to access remote registries by using $sRootKey in the form "\\computername\keyname"
;                  If a remote computer is specified than $sFile is relative to that computer
;                  You can only load registry hives to a subkey immediately below HKEY_LOCAL_MACHINE or HKEY_USERS
; Related .......:
; Link ..........;
; Examples ......;  _RegLoadHive("C:\Documents and Settings\Guest\ntuser.dat", "HKU\TempHive")
;                   _RegLoadHive("C:\Documents and Settings\Guest\ntuser.dat", "HKLM\TempHive")
;                   _RegLoadHive("C:\Documents and Settings\Administrator\ntuser.dat", "\\computername\HKU\S-1-5-21-domain-500")
;                   _RegLoadHive("C:\Documents and Settings\Guest\ntuser.dat", "\\computername\HKEY_USERS\S-1-5-21-domain-501")
; ===============================================================================================================================================

Func _RegLoadHive($sFile, $sKey)
    Local $avArray = Split_sRootKey($sKey)
    Local $hKey = RegConnectRegistry($avArray[0], $avArray[1])
    Local $avCurr[2][2] = [[$SE_RESTORE_NAME, $SE_PRIVILEGE_ENABLED], [$SE_BACKUP_NAME, $SE_PRIVILEGE_ENABLED]]
    Local $avPrev = _SetPrivilege($avCurr)
    Local $avRLH = DllCall("Advapi32.dll", "long", "RegLoadKey", "hwnd", $hKey, "str", $avArray[2], "str", $sFile)
    _SetPrivilege($avPrev)
    RegCloseKey($hKey)
    Return SetError( $avRLH[0], 0, Number($avRLH[0] = 0) )
EndFunc ;==> _RegLoadHive

; #FUNCTION# ====================================================================================================================================
; Name...........: _RegRestoreHive
; Description ...: Reads the registry information in a specified file and copies it over the specified key
; Syntax.........: _RegRestoreHive($sFile, $sKey)
; Parameters ....: $sFile - The name of the file with the registry information
;                  $sKey - Registry key
; Requirement(s).: None
; Return values .: Success - 1
;                  Failure - 0
;                            Sets @error
; Author ........: engine
; Modified.......:
; Remarks .......: It is possible to access remote registries by using $sKey in the form "\\computername\keyname"
;                  If a remote computer is specified than $sFile is relative to that computer
; Related .......:
; Link ..........;
; Example .......;  _RegRestoreHive("HKCU.dat", "\\" & @ComputerName & "\HKCU")
; ===============================================================================================================================================

Func _RegRestoreHive($sFile, $sKey)
    Local Const $REG_FORCE_RESTORE = 0x00000008
    Local $avArray = Split_sRootKey($sKey)
    Local $hRoot = RegConnectRegistry($avArray[0], $avArray[1])
    Local $hKey = RegCreateKeyEx( $hRoot, $avArray[2], BitOR($KEY_READ, $KEY_WRITE) )
    RegCloseKey($hRoot)
    Local $avCurr[2][2] = [[$SE_RESTORE_NAME, $SE_PRIVILEGE_ENABLED], [$SE_BACKUP_NAME, $SE_PRIVILEGE_ENABLED]]
    Local $avPrev = _SetPrivilege($avCurr)
    Local $avRRK = DllCall("Advapi32.dll", "long", "RegRestoreKey", "hwnd", $hKey, "str", $sFile, "dword", $REG_FORCE_RESTORE)
    _SetPrivilege($avPrev)
    RegCloseKey($hKey)
    Return SetError( $avRRK[0], 0, Number($avRRK[0] = 0) )
EndFunc ;==> _RegRestoreHive

; #FUNCTION# ====================================================================================================================================
; Name...........: _RegSaveHive
; Description ...: Saves the specified key and all of its subkeys and values to a new file, in the standard format
; Syntax.........: _RegSaveHive($sFile, $sKey)
; Parameters ....: $sFile - The name of the file in which the specified key and subkeys are to be saved
;                  $sKey - Registry key
; Requirement(s).: None
; Return values .: Success - 1
;                  Failure - 0
;                            Sets @error
; Author ........: engine
; Modified.......:
; Remarks .......: It is possible to access remote registries by using $sKey in the form "\\computername\keyname"
; Related .......:
; Link ..........;
; Example .......;  _RegSaveHive("HKCU.dat", "\\" & @ComputerName & "\HKCU")
; ===============================================================================================================================================

Func _RegSaveHive($sFile, $sKey)
    Local $avArray = Split_sRootKey($sKey)
    Local $hRoot = RegConnectRegistry($avArray[0], $avArray[1])
    Local $hKey = RegOpenKeyEx($hRoot, $avArray[2], $KEY_READ)
    RegCloseKey($hRoot)
    Local $avCurr[2] = [$SE_BACKUP_NAME, $SE_PRIVILEGE_ENABLED]
    Local $avPrev = _SetPrivilege($avCurr)
    Local $avRSK = DllCall("Advapi32.dll", "long", "RegSaveKey", "hwnd", $hKey, "str", $sFile, "ptr", 0)
    _SetPrivilege($avPrev)
    RegCloseKey($hKey)
    Return SetError( $avRSK[0], 0, Number($avRSK[0] = 0) )
EndFunc ;==> _RegSaveHive

; #FUNCTION# ====================================================================================================================================
; Name...........: _RegUnloadHive
; Description ...: Unloads a registry hive
; Syntax.........: _RegUnloadHive($sKey)
; Parameters ....: $sKey - Registry key to unload the hive from
; Requirement(s).: None
; Return values .: Success - 1
;                  Failure - 0
;                            Sets @error
; Author ........: engine
; Modified.......:
; Remarks .......: It is possible to access remote registries by using $sKey in the form "\\computername\keyname"
; Related .......:
; Link ..........;
; Examples ......;  _RegUnloadHive("HKU\TempHive")
;                   _RegUnloadHive("HKLM\TempHive")
;                   _RegUnloadHive("\\computername\HKU\S-1-5-21-domain-500")
;                   _RegUnloadHive("\\computername\HKEY_USERS\S-1-5-21-domain-501")
; ===============================================================================================================================================

Func _RegUnloadHive($sKey)
    Local $avArray = Split_sRootKey($sKey)
    Local $hKey = RegConnectRegistry($avArray[0], $avArray[1])
    Local $avCurr[2][2] = [[$SE_RESTORE_NAME, $SE_PRIVILEGE_ENABLED], [$SE_BACKUP_NAME, $SE_PRIVILEGE_ENABLED]]
    Local $avPrev = _SetPrivilege($avCurr)
    Local $avRUH = DllCall("Advapi32.dll", "long", "RegUnLoadKey", "hwnd", $hKey, "str", $avArray[2])
    _SetPrivilege($avPrev)
    RegCloseKey($hKey)
    Return SetError( $avRUH[0], 0, Number($avRUH[0] = 0) )
EndFunc ;==> _RegUnloadHive

; #INTERNAL_USE_ONLY#============================================================================================================================
; Name...........: RegCloseKey
; Description ...: Closes a handle to the specified registry key
; Syntax.........: RegCloseKey($hKey)
; Parameters ....: $hKey - Registry key handle to close
; Requirement(s).: None
; Return values .: Success - 1
;                  Failure - 0
;                            Sets @error
; Author ........: engine
; Modified.......:
; Remarks .......: For internal use only
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================================

Func RegCloseKey($hKey)
    Local $avRCK = DllCall("Advapi32.dll", "long", "RegCloseKey", "hwnd", $hKey)
    Return SetError( $avRCK[0], 0, Number($avRCK[0] = 0) )
EndFunc ;==> RegCloseKey

; #INTERNAL_USE_ONLY#============================================================================================================================
; Name...........: RegConnectRegistry
; Description ...: Establishes a connection to a predefined registry key on another computer
; Syntax.........: RegConnectRegistry($sComputer, $hKey)
; Parameters ....: $sComputer - Computer name in the form '\\computername'
;                  $hKey - Predefined registry key handle
; Requirement(s).: Service 'RemoteRegistry' running on the target computer
;                  When the target computer is the local computer, the 'RemoteRegistry' service isn't required
; Return values .: Success - Registry key handle
;                  Failure - 0
;                            Sets @error
; Author ........: engine
; Modified.......:
; Remarks .......: For internal use only
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================================

Func RegConnectRegistry($sComputer, $hKey)
    Local $avRCR = DllCall( "Advapi32.dll", "long", "RegConnectRegistry", _
        "str", $sComputer, _
        "hwnd", $hKey, _
        "hwnd*", 0 )
    Return SetError($avRCR[0], 0, $avRCR[3])
EndFunc ;==> RegConnectRegistry

; #INTERNAL_USE_ONLY#============================================================================================================================
; Name...........: RegCreateKeyEx
; Description ...: Creates the specified registry key
; Syntax.........: RegCreateKeyEx($kKey, $sSubKey, $iAccess)
; Parameters ....: $hKey - Predefined registry key handle
;                  $sSubKey - The name of the registry subkey to be created
;                  $iAccess - A mask that specifies the desired access rights to the key
; Requirement(s).: None
; Return values .: Success - Registry key handle
;                  Failure - 0
;                            Sets @error
; Author ........: engine
; Modified.......:
; Remarks .......: For internal use only
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================================

Func RegCreateKeyEx($kKey, $sSubKey, $iAccess)
    Local Const $REG_OPTION_NON_VOLATILE = 0x00000000
    Local $avRCKE = DllCall( "Advapi32.dll", "long", "RegCreateKeyEx", _
        "hwnd", $kKey, _
        "str", $sSubKey, _
        "dword", 0, _
        "ptr", 0, _
        "dword", $REG_OPTION_NON_VOLATILE, _
        "dword", $iAccess, _
        "ptr", 0, _
        "hwnd*", 0, _
        "ptr", 0 )
    Return SetError($avRCKE[0], 0, $avRCKE[8])
EndFunc ;==> RegCreateKeyEx

; #INTERNAL_USE_ONLY#============================================================================================================================
; Name...........: RegOpenKeyEx
; Description ...: Opens the specified registry key
; Syntax.........: RegOpenKeyEx($hKey, $sSubKey, $iAccess)
; Parameters ....: $hKey - Predefined registry key handle
;                  $sSubKey - The name of the registry subkey to be opened
;                  $iAccess - A mask that specifies the desired access rights to the key
; Requirement(s).: None
; Return values .: Success - Registry key handle
;                  Failure - 0
;                            Sets @error
; Author ........: engine
; Modified.......:
; Remarks .......: For internal use only
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================================

Func RegOpenKeyEx($hKey, $sSubKey, $iAccess)
    Local $avROKE = DllCall( "Advapi32.dll", "long", "RegOpenKeyEx", _
        "hwnd", $hKey, _
        "str", $sSubKey, _
        "dword", 0, _
        "dword", $iAccess, _
        "hwnd*", 0 )
    Return SetError($avROKE[0], 0, $avROKE[5])
EndFunc ;==> RegOpenKeyEx

; #INTERNAL_USE_ONLY#============================================================================================================================
; Name...........: Split_sRootKey
; Description ...: Splits $sRootKey between computer name, predefined registry key handle and subkey
; Syntax.........: Split_sRootKey($sRootKey)
; Parameters ....: $sRootKey - Reg function main key
; Requirement(s).: None
; Return values .: Returns an array where:
;                  $array[0] = \\computername
;                  $array[1] = Predefined registry key handle
;                  $array[2] = Subkey
; Author ........: engine
; Modified.......:
; Remarks .......: For internal use only
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================================

Func Split_sRootKey($sRootKey)
    Local Const $HKEY_CLASSES_ROOT = 0x80000000
    Local Const $HKEY_CURRENT_USER = 0x80000001
    Local Const $HKEY_LOCAL_MACHINE = 0x80000002
    Local Const $HKEY_USERS = 0x80000003
    Local Const $HKEY_CURRENT_CONFIG = 0x80000005
    Local $avHKEY[5][3] = [["HKCR", "HKEY_CLASSES_ROOT", $HKEY_CLASSES_ROOT], _
    ["HKCU", "HKEY_CURRENT_USER", $HKEY_CURRENT_USER], _
    ["HKLM", "HKEY_LOCAL_MACHINE", $HKEY_LOCAL_MACHINE], _
    ["HKU", "HKEY_USERS", $HKEY_USERS], _
    ["HKCC", "HKEY_CURRENT_CONFIG", $HKEY_CURRENT_CONFIG]]
    Local $avArray[3]
    If StringInStr($sRootKey, "\\") = 1 Then
        Local $asComputer = StringRegExp($sRootKey, "\\\\[^\\]*\\", 1)
        If Not @error Then
            $avArray[0] = StringTrimRight($asComputer[0], 1)
            $sRootKey = StringReplace($sRootKey, $asComputer[0], "", 1)
        EndIf
    EndIf
    If StringInStr($sRootKey, "\") = 1 Or StringInStr($sRootKey, "\", 0, -1) = StringLen($sRootKey) Or StringInStr($sRootKey, "\\") Then
        $avArray[0] = ""
        Return $avArray
    Else
        Local $asSplit = StringSplit($sRootKey, "\")
        For $i = 0 To UBound($avHKEY) - 1
            If $asSplit[1] = $avHKEY[$i][0] Or $asSplit[1] = $avHKEY[$i][1] Then
                $avArray[1] = $avHKEY[$i][2]
                ExitLoop
            EndIf
        Next
        If $avArray[1] = "" Then
            $avArray[0] = ""
            Return $avArray
        EndIf
        For $i = 2 To $asSplit[0] - 1
            $avArray[2] &= $asSplit[$i] & "\"
        Next
        If $asSplit[0] > 1 Then $avArray[2] &= $asSplit[ $asSplit[0] ]
    EndIf
    Return $avArray
EndFunc ;==> Split_sRootKey

Privilege.au3

#include-once
#include <Constants.au3>
#include <SecurityConstants.au3>

; #FUNCTION# ====================================================================================================================================
; Name...........: _SetPrivilege
; Description ...: Enables or disables special privileges as required by some DllCalls
; Syntax.........: _SetPrivilege($avPrivilege)
; Parameters ....: $avPrivilege - An array of privileges and respective attributes
;                                 $SE_PRIVILEGE_ENABLED - The function enables the privilege
;                                 $SE_PRIVILEGE_REMOVED - The privilege is removed from the list of privileges in the token
;                                 0 - The function disables the privilege
; Requirement(s).: None
; Return values .: Success - An array of modified privileges and their respective previous attribute state
;                  Failure - An empty array
;                            Sets @error
; Author ........: engine
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================================

Func _SetPrivilege($avPrivilege)
    Local $iDim = UBound($avPrivilege, 0), $avPrevState[1][2]
    If Not ( $iDim <= 2 And UBound($avPrivilege, $iDim) = 2 ) Then Return SetError(1300, 0, $avPrevState)
    If $iDim = 1 Then
        Local $avTemp[1][2]
        $avTemp[0][0] = $avPrivilege[0]
        $avTemp[0][1] = $avPrivilege[1]
        $avPrivilege = $avTemp
        $avTemp = 0
    EndIf
    Local $k, $tagTP = "dword", $iTokens = UBound($avPrivilege, 1)
    Do
        $k += 1
        $tagTP &= ";dword;long;dword"
    Until $k = $iTokens
    Local $tCurrState, $tPrevState, $pPrevState, $tLUID, $hAdvapi32, $hKernel32, $ahGCP, $avOPT, $aiGLE
    $tCurrState = DLLStructCreate($tagTP)
    $tPrevState = DllStructCreate($tagTP)
    $pPrevState = DllStructGetPtr($tPrevState)
    $tLUID = DllStructCreate("dword;long")
    DLLStructSetData($tCurrState, 1, $iTokens)
    $hAdvapi32 = DllOpen("Advapi32.dll")
    For $i = 0 To $iTokens - 1
        DllCall( $hAdvapi32, "int", "LookupPrivilegeValue", _
            "str", "", _
            "str", $avPrivilege[$i][0], _
            "ptr", DllStructGetPtr($tLUID) )
        DLLStructSetData( $tCurrState, 3 * $i + 2, DllStructGetData($tLUID, 1) )
        DLLStructSetData( $tCurrState, 3 * $i + 3, DllStructGetData($tLUID, 2) )
        DLLStructSetData( $tCurrState, 3 * $i + 4, $avPrivilege[$i][1] )
    Next
    $hKernel32 = DllOpen("Kernel32.dll")
    $ahGCP = DllCall($hKernel32, "hwnd", "GetCurrentProcess")
    $avOPT = DllCall( $hAdvapi32, "int", "OpenProcessToken", _
        "hwnd", $ahGCP[0], _
        "dword", BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY), _
        "hwnd*", 0 )
    DllCall( $hAdvapi32, "int", "AdjustTokenPrivileges", _
        "hwnd", $avOPT[3], _
        "int", False, _
        "ptr", DllStructGetPtr($tCurrState), _
        "dword", DllStructGetSize($tCurrState), _
        "ptr", $pPrevState, _
        "dword*", 0 )
    $aiGLE = DllCall($hKernel32, "dword", "GetLastError")
    DllCall($hKernel32, "int", "CloseHandle", "hwnd", $avOPT[3])
    DllClose($hKernel32)
    Local $iCount = DllStructGetData($tPrevState, 1)
    If $iCount > 0 Then
        Local $pLUID, $avLPN, $tName, $avPrevState[$iCount][2]
        For $i = 0 To $iCount - 1
            $pLUID = $pPrevState + 12 * $i + 4
            $avLPN = DllCall( $hAdvapi32, "int", "LookupPrivilegeName", _
                "str", "", _
                "ptr", $pLUID, _
                "ptr", 0, _
                "dword*", 0 )
            $tName = DllStructCreate("char[" & $avLPN[4] & "]")
            DllCall( $hAdvapi32, "int", "LookupPrivilegeName", _
                "str", "", _
                "ptr", $pLUID, _
                "ptr", DllStructGetPtr($tName), _
                "dword*", DllStructGetSize($tName) )
            $avPrevState[$i][0] = DllStructGetData($tName, 1)
            $avPrevState[$i][1] = DllStructGetData($tPrevState, 3 * $i + 4)
        Next
    EndIf
    DllClose($hAdvapi32)
    Return SetError($aiGLE[0], 0, $avPrevState)
EndFunc ;==> _SetPrivilege

surreal.au3

#region consts
Global Const $FO_MOVE                   = 0x0001
Global Const $FO_COPY                   = 0x0002
Global Const $FO_DELETE                 = 0x0003
Global Const $FO_RENAME                 = 0x0004

Global Const $FOF_MULTIDESTFILES        = 0x0001
Global Const $FOF_CONFIRMMOUSE          = 0x0002
Global Const $FOF_SILENT                = 0x0004
Global Const $FOF_RENAMEONCOLLISION     = 0x0008
Global Const $FOF_NOCONFIRMATION        = 0x0010
Global Const $FOF_WANTMAPPINGHANDLE     = 0x0020
Global Const $FOF_ALLOWUNDO             = 0x0040
Global Const $FOF_FILESONLY             = 0x0080
Global Const $FOF_SIMPLEPROGRESS        = 0x0100
Global Const $FOF_NOCONFIRMMKDIR        = 0x0200
Global Const $FOF_NOERRORUI             = 0x0400
Global Const $FOF_NOCOPYSECURITYATTRIBS = 0x0800
Global Const $FOF_NORECURSION           = 0x1000
Global Const $FOF_NO_CONNECTED_ELEMENTS = 0x2000
Global Const $FOF_WANTNUKEWARNING       = 0x4000
Global Const $FOF_NORECURSEREPARSE      = 0x8000
#endregion consts


;$result = _CopyWithProgress("\\folder\folder\folder\*.*","C:\folder")

Func _CopyWithProgress($sFrom, $sTo)
    ; version 1 by SumTingWong on 5/26/2006
    ; http://www.autoitscript.com/forum/index.php?showtopic=11888
    ; updated by lod3n on 6/5/2007

    Local $SHFILEOPSTRUCT
    Local $pFrom
    Local $pTo
    Local $aDllRet
    Local $nError = 0
    Local $i

    $SHFILEOPSTRUCT = DllStructCreate("int;uint;ptr;ptr;uint;int;ptr;ptr")
    If @error Then Return "nostruct"
; hwnd
    DllStructSetData($SHFILEOPSTRUCT, 1, 0)
; wFunc
    DllStructSetData($SHFILEOPSTRUCT, 2, $FO_COPY)
; pFrom
    $pFrom = DllStructCreate("char[" & StringLen($sFrom)+2 & "]")
; pFrom will now be null-terminated at StringLen($sFrom)+1
    DllStructSetData($pFrom, 1, $sFrom)
    For $i = 1 To StringLen($sFrom)+2
        If DllStructGetData($pFrom, 1, $i) = 10 Then DllStructSetData($pFrom, 1, 0, $i)
    Next
; We need a second null at the end
    DllStructSetData($pFrom, 1, 0, StringLen($sFrom)+2)
    DllStructSetData($SHFILEOPSTRUCT, 3, DllStructGetPtr($pFrom))
; pTo
    $pTo = DllStructCreate("char[" & StringLen($sTo)+2 & "]")
; pTo will now be null-terminated at StringLen($sTo)+1
    DllStructSetData($pTo, 1, $sTo)
; We need a second null at the end
    DllStructSetData($pTo, 1, 0, StringLen($sTo)+2)
    DllStructSetData($SHFILEOPSTRUCT, 4, DllStructGetPtr($pTo))
; fFlags
    DllStructSetData($SHFILEOPSTRUCT, 5, BitOR($FOF_NOCONFIRMMKDIR, _
        $FOF_NOCONFIRMATION, _
        $FOF_NOERRORUI))
; fAnyOperationsAborted
    DllStructSetData($SHFILEOPSTRUCT, 6, 0)
; hNameMappings
    DllStructSetData($SHFILEOPSTRUCT, 7, 0)
; lpszProgressTitle
    DllStructSetData($SHFILEOPSTRUCT, 8, 0)
    $aDllRet = DllCall("shell32.dll", "int", "SHFileOperation", "ptr", DllStructGetPtr($SHFILEOPSTRUCT))
    $retcode = $aDllRet[0]
    $pFrom = 0
    $pTo = 0
    $SHFILEOPSTRUCT = 0
    If $retcode <> 0 Then
        ConsoleWrite(hex($retcode) & ": " & SHFileOperationErrDecode($retcode) & @crlf)
        SetError($nError)
        Return False
    EndIf
    Return True
EndFunc


func SHFileOperationErrDecode($errNum)
    Switch $errNum
        case 113
            return "The source and destination files are the same file."
        case 114
            return "Multiple file paths were specified in the source buffer, but only one destination file path."
        case 115
            return "Rename operation was specified but the destination path is a different directory. Use the move operation instead."
        case 116
            return "The source is a root directory, which cannot be moved or renamed."
        case 117
            return "The operation was cancelled by the user, or silently cancelled if the appropriate flags were supplied to SHFileOperation."
        case 118
            return "The destination is a subtree of the source."
        case 120
            return "Security settings denied access to the source."
        case 121
            return "The source or destination path exceeded or would exceed MAX_PATH."
        case 122
            return "The operation involved multiple destination paths, which can fail in the case of a move operation."
        case 124
            return "The path in the source or destination or both was invalid."
        case 125
            return "The source and destination have the same parent folder."
        case 126
            return "The destination path is an existing file."
        case 128
            return "The destination path is an existing folder."
        case 129
            return "The name of the file exceeds MAX_PATH."
        case 130
            return "The destination is a read-only CD-ROM, possibly unformatted."
        case 131
            return "The destination is a read-only DVD, possibly unformatted."
        case 132
            return "The destination is a writable CD-ROM, possibly unformatted."
        case 133
            return "The file involved in the operation is too large for the destination media or file system."
        case 134
            return "The source is a read-only CD-ROM, possibly unformatted."
        case 135
            return "The source is a read-only DVD, possibly unformatted."
        case 136
            return "The source is a writable CD-ROM, possibly unformatted."
        case 183
            return "MAX_PATH was exceeded during the operation."
        case 1026
            return "An unknown error occurred. This is typically due to an invalid path in the source or destination. This error does not occur on Microsoft Windows Vista and later."
        case 65536
            return "An unspecified error occurred on the destination."
        case 65652
            return "Destination is a root directory and cannot be renamed."
    EndSwitch

    return "SHFileOperation returned errorcode " & hex($errNum) & ", which is not recognized"
EndFunc

thank you everyone for your help

d@ve

Edited by surreal

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  
Followers 0