Sign in to follow this  
Followers 0
surreal

map drive(s) from array

5 posts in this topic

#1 ·  Posted (edited)

i have a working array that collects the current mapped drives on a remote system on the network. at this time i have the array exporting to a txt file:

driveletter,servername\sharename

driveletter,servername\sharename

driveletter,servername\sharename

i now need to install the gathered drives onto the system the script is ran from.

DriveMapAdd ("driveletter:", "\\servername\sharename")

i tried:

$installdrive = $b[$j][1]

$installpath = $path[1][1]

DriveMapAdd($installdrive, $path)

with no success

can drivemapadd read the array or does it have to pull it from the txt file or an ini? if i need to create an ini instead of the txt file i can do that. if it can read from the array that would be even better. to be honest the most stable is what im hoping for.

but beyond that on how to get this accomplished i have know clue and any help would be greatly appreciated.

below is the code for the array.

Func Mapped()
    Local $asset = GUICtrlRead($cnTarget)
    If BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        Local $mapLocation = $Target & $Temp & "Drives\Drives.txt"
    Else
            Local $mapLocation = $Temp2 & "Drives\Drives.txt"
    EndIf
    For $i = 1 To 25
        $b = _HKCU_EnumKey("\\\" & $asset & "\Network", $i)
        $iProd = 1
        For $j = 1 To $b[0][0]
            $iProd *= $b[$j][2]
            If $b[$j][2] = 0 Then
                $path = _HKCU_Read("\\\" & $asset & "\\" & $b[$j][0] & "\Network\" & $b[$j][1], "RemotePath")
                FileWriteLine($mapFile, $b[$j][1] & "," & $path[1][1])
            EndIf
        Next
        If $iProd <> 0 Then ExitLoop
    Next
EndFunc   ;==>

this is my full code if needed!

#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>

;===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

Local $Temp = "\Migrate_Local\"
Local $Temp2 = "\Migrate_Network\"
Local $LogFile = "c:\Temp\LogFile.txt"
Local $Separator = "------------------------------"

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

$FileMenu = GUICtrlCreateMenu("&File")
$BKItem = GUICtrlCreateMenuItem("Backup Only", $FileMenu)
GUICtrlSetState($BKItem, $GUI_UNCHECKED)
$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)
$CPItem = GUICtrlCreateMenuItem("Command Prompt", $ProMenu)
$HelpMenu = GUICtrlCreateMenu("&Help")
$HelpItem = GUICtrlCreateMenuItem("Help", $HelpMenu)

;===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)
$BoxMap = GUICtrlCreateCheckbox("Mapped Drives", 220, 25)
$BoxPrinter = GUICtrlCreateCheckbox("Network Printers", 220, 45)
$BoxLotus = GUICtrlCreateCheckbox("Lotus Notes", 220, 65)
GUICtrlSetState($BoxMap, $GUI_CHECKED)
GUICtrlSetState($BoxPrinter, $GUI_CHECKED)

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

$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)

;===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)
            Else
                GUICtrlSetState($BKItem, $GUI_CHECKED)
            EndIf
            $target = FileSelectFolder("Choose the location you want to back up to:", "")
                 If $target = '' Then GUICtrlSetState($BKItem, $GUI_UNCHECKED)
        Case $msg = $HelpItem
            MsgBox(64, "", "Help File Coming Soon")
        Case $msg = $RDItem
            Run('mstsc.exe', @SystemDir)
        Case $msg = $CMItem
            ShellExecute('compmgmt.msc', @SystemDir, @SW_MAXIMIZE)
        Case $msg = $LogItem
            ShellExecute($LogFile, "")
        Case $msg = $CPItem
            Run('cmd.exe', @SystemDir)

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

            If BitAND(GUICtrlRead($BoxLotus), $GUI_UNCHECKED) = $GUI_UNCHECKED Then
                GUICtrlSetState($BoxLotus, $GUI_UNCHECKED)
            Else
                Lotus()
                GUICtrlSetState($BoxLotus, $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
            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()
    SplashTextOn("", "Working...", 165, 40, -1, -1, 2, "", 9)
    ;===Mapped Drives
    If GUICtrlRead($BoxMap) = $GUI_CHECKED Then GUICtrlSetData($cnMessage, 'Transferring: Mapped Drives')
    GUICtrlSetColor($cnMessage, 0x008000)
    If BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        DirCreate($Target & $Temp & "Drives")
        Mapped()
    Else
            DirCreate($Temp2 & "Drives")
            Mapped()
            DriveMapAdd ("X:", "\\wwcodcfileclst\Software")
    EndIf
    ;===Printers
    If GUICtrlRead($BoxPrinter) = $GUI_CHECKED Then GUICtrlSetData($cnMessage, 'Transferring: Printers')
    GUICtrlSetColor($cnMessage, 0x008000)
    If BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        DirCreate($Target & $Temp & "Printers")
        Printers()
    Else
            DirCreate($Temp2 & "Printers")
            Printers()
    EndIf
    ;===Lotus Notes
    If GUICtrlRead($BoxLotus) = $GUI_CHECKED Then GUICtrlSetData($cnMessage, 'Transferring: Lotus Notes')
    GUICtrlSetColor($cnMessage, 0x008000)
    If BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        DirCreate($Target & $Temp & "Notes")
        FileCopy($Lotus_Location & "\*.id", $Target & $Temp & "Notes", 1)
        FileCopy($Lotus_Location & "\Desktop6.ndk", $Target & $Temp & "Notes", 1)
        FileCopy($Lotus_Location & "\Names.nsf", $Target & $Temp & "Notes", 1)
        FileCopy($Lotus_Location & "\User.dic", $Target & $Temp & "Notes", 1)
        DirCreate($Target & $Temp & "Notes\Archive")
        DirCopy($Lotus_Location & "\Archive", $Target & $Temp & "Notes\Archive", 1)
        FileWriteLine($LogFile, @CRLF & $Separator & "Lotus Notes:" & @TAB & "(Successful)" & @CRLF)
    Else
            DirCreate($Temp2 & "Notes")
            FileCopy($Lotus_Location & "\*.id", $Temp2 & "Notes", 1)
            FileCopy($Lotus_Location & "\Desktop6.ndk", $Temp2 & "Notes", 1)
            FileCopy($Lotus_Location & "\Names.nsf", $Temp2 & "Notes", 1)
            FileCopy($Lotus_Location & "\User.dic", $Temp2 & "Notes", 1)
            DirCreate($Temp2 & "Notes\Archive")
            DirCopy($Lotus_Location & "\Archive", $Temp2 & "Notes\Archive", 1)
            FileWriteLine($LogFile, @CRLF & $Separator & "Lotus Notes:" & @TAB & "(Network Successful)" & @CRLF)
    EndIf
    SplashOff()
    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()
    Local $passet = GUICtrlRead($cnTarget)
    If BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        Local $pLocation = $Target & $Temp & "Printers\Printers.txt"
    Else
            Local $pLocation = $Temp2 & "Printers\Printers.txt"
    EndIf

    $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
EndFunc   ;==>Printers

;===Function For Mapped Drives=====================================================================
Func Mapped()
    Local $asset = GUICtrlRead($cnTarget)
    If BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        Local $mapLocation = $Target & $Temp & "Drives\Drives.txt"
    Else
            Local $mapLocation = $Temp2 & "Drives\Drives.txt"
    EndIf
    For $i = 1 To 25
        $b = _HKCU_EnumKey("\\\" & $asset & "\Network", $i)
        $iProd = 1
        For $j = 1 To $b[0][0]
            $iProd *= $b[$j][2]
            If $b[$j][2] = 0 Then
                $path = _HKCU_Read("\\\" & $asset & "\\" & $b[$j][0] & "\Network\" & $b[$j][1], "RemotePath")
                FileWriteLine($mapFile, $b[$j][1] & "," & $path[1][1])
            EndIf
        Next
        If $iProd <> 0 Then ExitLoop
    Next
EndFunc   ;==>Mapped

;===Function For Lotus Notes Child Window==========================================================
Func Lotus()
    $ChildWin = GUICreate("", 135, 110, -1, -1, $WS_EX_TOPMOST)
    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
                Global $Lotus_Location = "\\" & GUICtrlRead($cnTarget) & "\c$\Program Files\Lotus\Notes\Data"
                GUIDelete($ChildWin)
                ExitLoop
                GUISwitch($ParentWin)
                GUISetState(@SW_SHOW, $ParentWin)
            Case $lnmsg = $Box_Multi And BitAND(GUICtrlRead($Box_Multi), $GUI_CHECKED) = $GUI_CHECKED
                Global $Lotus_Location = "\\" & GUICtrlRead($cnTarget) & "\c$" & $DOC & GUICtrlRead($prCombo) & "\Local Settings\Application Data\Lotus\Notes\Data"
                GUIDelete($ChildWin)
                ExitLoop
                GUISwitch($ParentWin)
                GUISetState(@SW_SHOW, $ParentWin)
            Case $lnmsg = $Box_System And BitAND(GUICtrlRead($Box_System), $GUI_CHECKED) = $GUI_CHECKED
                Global $Lotus_Location = "\\" & GUICtrlRead($cnTarget) & "\c$\Lotus\Notes\Data"
                GUIDelete($ChildWin)
                ExitLoop
                GUISwitch($ParentWin)
                GUISetState(@SW_SHOW, $ParentWin)
        EndSelect
    WEnd
EndFunc   ;==>Lotus

update: i tried this also with no luck

Func Mapped()
    Local $asset = GUICtrlRead($cnTarget)
    If BitAND(GUICtrlRead($BKItem), $GUI_CHECKED) = $GUI_CHECKED Then
        Local $mapLocation = $target & $Temp & "Drives\Drives.ini"
    Else
        Local $mapLocation = $Temp2 & "Drives\Drives.ini"
    EndIf
    $mapFile = FileOpen($mapLocation, 10)
    For $i = 1 To 25
        $b = _HKCU_EnumKey("\\\" & $asset & "\Network", $i)
        $iProd = 1
        For $j = 1 To $b[0][0]
            $iProd *= $b[$j][2]
            If $b[$j][2] = 0 Then
                $path = _HKCU_Read("\\\" & $asset & "\\" & $b[$j][0] & "\Network\" & $b[$j][1], "RemotePath")
                $inipath = $b[$j][1] & "=" & $path[1][1]
                IniWriteSection($mapLocation, "NetworkDrive", $inipath)
            EndIf
        Next
        If $iProd <> 0 Then ExitLoop
    Next
    $var = IniReadSection($mapLocation, "NetworkDrive")
    For $x = 1 To $var[0][0]
        DriveMapAdd($var[$x][0], $var[$x][1])
    Next
EndFunc
Edited by surreal

Share this post


Link to post
Share on other sites



I don't know if you must supply drives letter as "Z:", "X:", etc.. but you can try. :)

Share this post


Link to post
Share on other sites

thx for the reply Authenticity.

the issue is that the drive letter will be different per mapped drive per user. the drive letter is pulled and stored in the array. maybe this is a limitation of DriveMapAdd?

d@ve

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

alright, so i still cannot figure this out yet. but i do have a new idea. was wondering if the below would be possible?

im thinking of having a separate click maybe in the toolbar. once clicked it will run the mapped drives function. but do the following:

bring up a _GUICtrlListView of the remote users mapped drives. then have a checkbox that you can select what drive you want to map on the new system. a button that once clicked would map the drives from the gathered array that have been checked.

im not sure if this is something possible, if so wow this would be great. any and all help would be so greatly appreciated, thank you so much.

d@ve

Edited by surreal

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I don't know if this help but I use this:

Global $network_drives[24]
Global $number_of_network_drives

Func _mapdrive($DriveLtr, $DrivePath)
 DriveMapAdd($DriveLtr, $DrivePath, 1)
 Switch @error
  Case 1
   MsgBox(16, "O.M.G Error", "An unknown error occured on " & $DrivePath & " trying to be mapped as local drive " & $DriveLtr & " maybe end device is not avilable for mapping")
  Case 2
   MsgBox(16, "Access Error", "Access to the remote share " & $DrivePath & " was denied")
  Case 3
   MsgBox(64, "Map Drive Error", "The device/drive " & $DriveLtr & " is already assigned and will be deleted")
  Case 4
   MsgBox(16, "Device Error", "Invalid device " & $DriveLtr & " name")
  Case 5
   MsgBox(16, "Connect to Remote Share Error", "Invalid remote share :" & $DrivePath)
  Case 6
   MsgBox(16, "Password Error", "Invalid password")
  Case Else
   ;MsgBox(64, "Completed!", "Mapped " & $DriveLtr & " to share " & $DrivePath)
   Sleep(500)
 EndSwitch
EndFunc   ;==>_mapdrive

Func _delmappeddrive($drived)
 Local $i = $number_of_network_drives
 If $drived = "*" Then
  Do
   DriveMapDel($network_drives[$i] & ":")
   Sleep(500)
   $i = $i - 1
  Until $i = 0
 Else
  DriveMapDel($drived)
  Switch @error
   Case 0
    MsgBox(64, "Map Drive Error", "The device/drive " & $network_drives[$i] & ": is already assigned and will be deleted")
   Case Else
    ;MsgBox(64, "Completed!", "Deleted " & $network_drives[$i])
  EndSwitch
 EndIf
EndFunc   ;==>_delmappeddrive

Func _EnumerateDrives()
 ; see [url="http://www.asciitable.com/"]http://www.asciitable.com/[/url] for a really good ascii convertion table
 Local $x = 1
 Local $y = 1
 For $dl = 72 To 89 ; (H-Y)
  $network_drives[$x] = Chr($dl)
  $drive = Chr($dl) & ":\"
  $drive_letter = Chr($dl)
  DriveGetFileSystem($drive)
  If @error = 0 Then
   ;MsgBox(16, "Network Drive", "Drive in Use " & $drive & @CRLF & @CRLF & " Array Varible :" & $network_drives[$x])
   $x = $x + 1
  Else
   ;MsgBox(16,"New Drive " & $network_drives[$y], "Free Drive " & $drive_letter)
   $y = $y + 1
  EndIf
 Next
 $number_of_network_drives = $x - 1
 Return $number_of_network_drives
 ;MsgBox(16, "Drives", "Number of network drives in use are " & $number_of_network_drives)
EndFunc   ;==>_EnumerateDrives

Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

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