Hi Carm01,
I see some issues with your code. The FileOpen in the loop which creates a file write handle 26 times and yet not any of those handles used once or closed at the end of use. I would expect the file write handle to be opened before entering the loop or perhaps when the loop is done. The later would mean storing the commands in a variable while looping. Using _FileCreate() seems a waste, especially including <file.au3>, as FileOpen or FileWrite used by itself creates the file anyhow. Instead of going from a to z and using those functions in the loop 26 times, I would recommend DriveGetDrive to get the network drives then it would probably be just a couple of loops depending on the mapped drive count.
Here is an alternative example
; cmd script to write net use commands
$cmdfile = 'MapDrive.cmd'
; get network drives and store into an array
$network_drives = DriveGetDrive('NETWORK')
; check that the array is valid
If Not IsArray($network_drives) Then
MsgBox(0x40030, @ScriptName, 'No network drives found')
Exit 1
Else
; open a handle to write to file using erase mode
$handle_write = FileOpen($cmdfile, 2)
; check that the handle is valid
If $handle_write = -1 Then
MsgBox(0x40030, @ScriptName, 'Unable to open cmd file for write')
Exit 2
Else
; loop through each network drive
For $1 = 1 To UBound($network_drives) -1
; get the unc path of the network drive
$network_path = DriveMapGet($network_drives[$1])
; do not write to file if an error occurred
If @error Then ContinueLoop
; write net use command to the cmd script
FileWrite($handle_write, 'net use ' & $network_drives[$1] & ' "' & $network_path & '"' & @CRLF)
Next
; close the file handle that was used for writing
FileClose($handle_write)
EndIf
EndIf
Perhaps some ideas which you can use to update your code.