niruse Posted January 2, 2013 Share Posted January 2, 2013 i found some scripts and merged it together and it did these things- format partitions a-h- Identify the system drives and system partitions- Check if there is space for a second partition on the system drive- Change the drive letters of optical and removable drives- Check for empty hard drives- If above Yes, Create a second partition on the systen drive- Create partitions on empty drives- Format the newly created partitions- Assign drive letters to the new volumes- Rename the volume names of all drives from e.g. "Local Volume" to "HD0-System" or "HD1-Data"now what i need is to put a loop on half of this script (ill highlight from where i want to loop )i know its connections to this commands but how to put it in script?for $i=1 to 5then i should put the command and then nextso how do i put it in script?script... BlockInput (1);format paratitions a-h on dosRunwait(@ComSpec & " /c "& "format a: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW)winclose("C:\WINDOWS\system32\cmd.exe");Windows XPwinclose("Administrator: C:\Windows\system32\cmd.exe");VistaRunwait(@ComSpec & " /c "& "format b: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW)winclose("C:\WINDOWS\system32\cmd.exe");Windows XPwinclose("Administrator: C:\Windows\system32\cmd.exe");VistaRunwait(@ComSpec & " /c "& "format d: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW)winclose("C:\WINDOWS\system32\cmd.exe");Windows XPwinclose("Administrator: C:\Windows\system32\cmd.exe");VistaRunwait(@ComSpec & " /c "& "format e: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW)winclose("C:\WINDOWS\system32\cmd.exe");Windows XPwinclose("Administrator: C:\Windows\system32\cmd.exe");VistaRunwait(@ComSpec & " /c "& "format f: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW)winclose("C:\WINDOWS\system32\cmd.exe");Windows XPwinclose("Administrator: C:\Windows\system32\cmd.exe");VistaRunwait(@ComSpec & " /c "& "format g: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW)winclose("C:\WINDOWS\system32\cmd.exe");Windows XPwinclose("Administrator: C:\Windows\system32\cmd.exe");VistaRunwait(@ComSpec & " /c "& "format h: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW)winclose("C:\WINDOWS\system32\cmd.exe");Windows XPwinclose("Administrator: C:\Windows\system32\cmd.exe");Vistafrom there i want to start this 5 times loop; ----------------------------------------------------------------------------------------------------------------; Define the include files#include <Array.au3>#include <file.au3>; ----------------------------------------------------------------------------------------------------------------; VariablesLocal $s_SystemDriveLetterLocal $s_AssignedDriveLetterLocal $s_SystemPartitionIDLocal $s_SystemDeviceIDLocal $i_SystemDeviceSizeLocal $i_SystemPartitionSizeLocal $i_NumberOfPartitionsLocal $a_DriveDetails[1][3]Local $wbemFlagReturnImmediately = 0x10Local $wbemFlagForwardOnly = 0x20Local $h_wbemFlags = $wbemFlagReturnImmediately + $wbemFlagForwardOnlyLocal $s_ComputerName = @ComputerNameLocal $s_TagContent = "%PHYSICALDRIVE%"Local $s_DriveDelimiter = "%:"Local $i_Counter = 0Global $s_SystemTempHome = @TempDirGlobal $s_DiskpartCommandsFile = $s_SystemTempHome & "\" & "commands.txt"; ----------------------------------------------------------------------------------------------------------------; Set the WMI-Service$o_WMIService = ObjGet("winmgmts:\\" & $s_ComputerName & "\root\CIMV2"); ----------------------------------------------------------------------------------------------------------------; First of all the DriveLetters of optical and removable drives are renamed; out of the way, starting with "O:" for optical and "R:" for removable drives. ; Using this convention it would be possible to have up to six ptical and ; removable drives in one system, wich should happen quite seldom. Also it; would be possible to have up to 17 logical volumes in a system (drives C:; through T:).;; 1st get arrays of WMI objects this could be simplified into one array pro-; vided with another column containing the "Descriptions" ('CD-ROM Disc' and ; 'Removalbe Disk').$o_OpticalDrives = $o_WMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE Description = 'CD-ROM Disc'", "WQL", $h_wbemFlags)$o_RemovableDrives = $o_WMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE Description = 'Removable Disk'", "WQL", $h_wbemFlags); 2nd create the arrays containing the GUIDs and their DriveLetters;; ...for Optical DrivesGlobal $a_OpticalDriveList[1][2]For $o_items in $o_OpticalDrives $s_DriveLetter = $o_items.Caption Local $a_TempAdd[2] = [$s_DriveLetter, _FindGUID($s_DriveLetter)] _2DArrayAdd($a_OpticalDriveList, $a_TempAdd, False)Next_ArrayDelete($a_OpticalDriveList, 0); ...and then the Removable DisksGlobal $a_RemovableDriveList[1][2]For $o_items in $o_RemovableDrives $s_DriveLetter = $o_items.Caption Local $a_TempAdd[2] = [$s_DriveLetter, _FindGUID($s_DriveLetter)] _2DArrayAdd($a_RemovableDriveList, $a_TempAdd, False)Next_ArrayDelete($a_RemovableDriveList, 0); 3rd change the driveletters; Due to the fact that optical drives usually get the drive letter "D:" after; the base operating system installation, they must be "moved" first. Then I; treat the removable drives, which also get lower drive letters at start.; Finally the hard drives are handled; they will close upo after "C:".;; ...for Optical Drives, starting with "O:" for "optical"$s_FirstOpticalDrive = "O"For $i = 0 to UBound($a_OpticalDriveList) - 1 $s_cmd = "mountvol " & $a_OpticalDriveList[$i][0] & " /D" RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_HIDE) $s_DriveLetterCharNew = Chr((Asc($s_FirstOpticalDrive)) + $i) $a_OpticalDriveList[$i][0] = $s_DriveLetterCharNew & ":" $s_cmd = "mountvol " & $a_OpticalDriveList[$i][0] & " " & $a_OpticalDriveList[$i][1] RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_HIDE)Next; ...and then the Removable Disks (USB), starting with "R:" for "removable"$s_FirstRemovableDrive = "R"For $i = 0 to UBound($a_RemovableDriveList) - 1 $s_cmd = "mountvol " & $a_RemovableDriveList[$i][0] & " /D" RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_HIDE) $s_DriveLetterCharNew = Chr((Asc($s_FirstRemovableDrive)) + $i) $a_RemovableDriveList[$i][0] = $s_DriveLetterCharNew & ":" $s_cmd = "mountvol " & $a_RemovableDriveList[$i][0] & " " & $a_RemovableDriveList[$i][1] RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_HIDE)Next; ----------------------------------------------------------------------------------------------------------------; Now Mine for information about the partition/volume/drive containing the ; operating system, so we later can get the size of the volume housing it. ; This is important to estimate the sense of creating a second data partition ; on that drive.;; Get the (1) DriveLetter (aka "C:") of the partition containing the OS$o_OperatingSystem = $o_WMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE SystemDrive LIKE '" & $s_DriveDelimiter & "' ", "WQL", $h_wbemFlags)For $o_items in $o_OperatingSystem $s_SystemDriveLetter = $o_items.SystemDriveNext; Get the (2) DeviceID (aka "Disk #0, Partition #0") of the system partition$o_LogicalDiskToPartition = $o_WMIService.ExecQuery("SELECT * FROM Win32_LogicalDiskToPartition", "WQL", $h_wbemFlags)For $o_items in $o_LogicalDiskToPartition If StringRight($o_items.Dependent,4) = """" & $s_SystemDriveLetter & """" then $s_SystemPartitionID = StringLeft(StringRight($o_items.Antecedent, 22), 21) EndIfNext; Get the (3) DeviceID (aka "\\\.\PHYSICALDRIVE0") of the device conbtaining ; the system partition$o_DiskDriveToDiskPartition = $o_WMIService.ExecQuery("SELECT * FROM Win32_DiskDriveToDiskPartition", "WQL", $h_wbemFlags)For $o_items in $o_DiskDriveToDiskPartition If StringRight($o_items.Dependent,23) = """" & $s_SystemPartitionID & """" then $s_SystemDeviceID = StringLeft(StringRight($o_items.Antecedent, 22), 21) EndIfNext; ----------------------------------------------------------------------------------------------------------------; Get the size of the partition containing the OS$o_DiskPartition = $o_WMIService.ExecQuery("SELECT * FROM Win32_DiskPartition WHERE DeviceID = '" & $s_SystemPartitionID & "' ", "WQL", $h_wbemFlags)For $o_items in $o_DiskPartition $i_SystemPartitionSize = $o_items.SizeNext; Now get the size of the drive containing the system partition. In my defini-; tion it is only useful to create another partition on the system drive if the ; remaining amounts to at least 10.0 GBytes; (10GBytes = 10737418240 Bytes = 10 *1024 *1024 *1024 Bytes).$o_DiskDrive = $o_WMIService.ExecQuery("SELECT * FROM Win32_DiskDrive WHERE DeviceID = '" & $s_SystemDeviceID & "' ", "WQL", $h_wbemFlags)For $o_items in $o_DiskDrive $i_SystemDeviceSize = $o_items.Size $i_NumberOfPartitions = $o_items.Partitions If ($i_SystemDeviceSize - $i_SystemPartitionSize) >= 10737418240 And $i_NumberOfPartitions = 1 Then Local $b_2ndPartitionOnHD0 = True Local $b_CreatePartition = True Local $a_TempAdd[3] = [$o_items.DeviceId, $b_CreatePartition, $i_NumberOfPartitions] _2DArrayAdd($a_DriveDetails, $a_TempAdd, False) ElseIf $i_NumberOfPartitions = 2 Then Local $b_2ndPartitionOnHD0 = True Local $b_CreatePartition = False Local $a_TempAdd[3] = [$o_items.DeviceId, $b_CreatePartition, $i_NumberOfPartitions] _2DArrayAdd($a_DriveDetails, $a_TempAdd, False) Else Local $b_2ndPartitionOnHD0 = False Local $b_CreatePartition = False Local $a_TempAdd[3] = [$o_items.DeviceId, $b_CreatePartition, $i_NumberOfPartitions] _2DArrayAdd($a_DriveDetails, $a_TempAdd, False) EndIfNext; Check if partitions exist on the physical units NOT containing the OS$o_DiskDrive = $o_WMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", $h_wbemFlags)For $o_items in $o_DiskDrive If StringRight($o_items.DeviceId, 14) <> StringRight($s_SystemDeviceID, 14) Then $i_NumberOfPartitions = $o_items.Partitions If $i_NumberOfPartitions = 0 Then $b_CreatePartition = True Local $a_TempAdd[3] = [$o_items.DeviceId, $b_CreatePartition, $i_NumberOfPartitions] _2DArrayAdd($a_DriveDetails, $a_TempAdd, False) Else $b_CreatePartition = False Local $a_TempAdd[3] = [$o_items.DeviceId, $b_CreatePartition, $i_NumberOfPartitions] _2DArrayAdd($a_DriveDetails, $a_TempAdd, False) EndIf EndIfNext; Delete the first row of the array containing the drives with usable space; ; it only contains the unneeded index_ArrayDelete($a_DriveDetails, 0); ----------------------------------------------------------------------------------------------------------------; Create partitions where needed: ; On Drive 0 if more than 10GB of space are available; On Drive n if no partitions exist; DriveLetters are assigned starting with "D:"$s_AssignedDriveLetter = "d"For $i_i = 0 to UBound($a_DriveDetails) -1 If $a_DriveDetails[$i_i][1] = True Then $s_ActualDriveLetter = Chr((Asc($s_AssignedDriveLetter)) + $i_i) $s_ActualDrive = StringRight($a_DriveDetails[$i_i][0], 1) _FileCreate($s_DiskpartCommandsFile) FileOpen($s_DiskpartCommandsFile, 2) FileWriteLine($s_DiskpartCommandsFile, "select disk " & $s_ActualDrive) FileWriteLine($s_DiskpartCommandsFile, "create partition primary") FileWriteLine($s_DiskpartCommandsFile, "assign letter= " & $s_ActualDriveLetter) FileClose($s_DiskpartCommandsFile) $s_cmd = "diskpart /s " & $s_DiskpartCommandsFile RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_SHOW) Sleep(1000) $s_cmd = "format /fs:ntfs /x /v:TempName /Y " & $s_ActualDriveLetter & ":" RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_SHOW) FileDelete($s_DiskpartCommandsFile) EndIfNext; ----------------------------------------------------------------------------------------------------------------; Finally rename the volumenames using HD0 for the first physical drive, ; HD1 for the second and HDn for all further ones.$o_LogicalDisks = $o_WMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE Description = 'Local Fixed Disk'", "WQL", $h_wbemFlags)For $o_items in $o_LogicalDisks If $o_items.Caption = $s_SystemDriveLetter Then $i_Counter = 0 $o_items.VolumeName = "HD" & $i_Counter & "-System" $o_items.Put_ ElseIf $o_items.Caption = "M:" Or $o_items.Caption = "D:" And $b_2ndPartitionOnHD0 = True Then $i_Counter = 0 $o_items.VolumeName = "HD" & $i_Counter & "-Data" $o_items.Put_ Else $i_Counter = $i_Counter + 1 $o_items.VolumeName = "HD" & $i_Counter & "-Data" $o_items.Put_ EndIfNext; Function _FindGUID to find the GUID belonging to a DriveLetter; ==============================================================================================Func _FindGUID($Drive) Local Const $DevList = 'HKLM\SYSTEM\MountedDevices' Local $i Do If RegRead($DevList, '\DosDevices\' & $Drive) = RegRead($DevList, RegEnumVal($DevList, $i)) Then Return StringReplace(RegEnumVal($DevList, $i), '\??\', '\\?\', 1) $i += 1 Until 0EndFunc ;==>_FindGUID; Function _2DArrayAdd to add lines to a two-dimensional array; ==============================================================================================Func _2DArrayAdd(ByRef $avArray, $vValue, $NestArray = True) Local $iBoundArray0, $iBoundArray1, $iBoundArray2, $iBoundValue1 ; $avArray is not an array If IsArray($avArray) = 0 Then Return SetError(1, 0, -1) ; No. of dimesions in array $iBoundArray0 = UBound($avArray, 0) ; $avArray is more than 2D If $iBoundArray0 > 2 Then Return SetError(1, 1, -1) ; Size of array in first dimension $iBoundArray1 = UBound($avArray, 1) ; Size of array in second dimension If $iBoundArray0 = 2 Then $iBoundArray2 = UBound($avArray, 2) ; If input array is 1D, or $vValue is not an array, or $NestArray = True (default) then save $vValue literally If ($iBoundArray0 = 1) Or (IsArray($vValue) = 0) Or $NestArray Then If $iBoundArray0 = 1 Then ; Add to 1D array ReDim $avArray[$iBoundArray1 + 1] $avArray[$iBoundArray1] = $vValue Else ; Add to 2D array at [n][0] ReDim $avArray[$iBoundArray1 + 1][$iBoundArray2] $avArray[$iBoundArray1][0] = $vValue EndIf Else ; If input array is 2D, and $vValue is an array, and $NestArray = False, ; then $vValue is a 1D array of values to add as a new row. ; $vValue array is not 1D If UBound($vValue, 0) <> 1 Then Return SetError(1, 2, -1) $iBoundValue1 = UBound($vValue, 1) ; $vValue array has too many elements If $iBoundArray2 < $iBoundValue1 Then Return SetError(1, 3, -1) ReDim $avArray[$iBoundArray1 + 1][$iBoundArray2] For $n = 0 To $iBoundValue1 - 1 $avArray[$iBoundArray1][$n] = $vValue[$n] Next EndIf ; Return index of new last row in $avArray Return $iBoundArray1EndFunc ;==>_2DArrayAddty waiting for answer Link to comment Share on other sites More sharing options...
johnmcloud Posted January 2, 2013 Share Posted January 2, 2013 (edited) Use the CODE or AUTOIT Tags, and please explain better what you need to loop.Anyway, you have two ways:While X...WEnd ( X = Number of loops ) --> http://www.autoitscript.com/autoit3/docs/keywords/While.htmDo...Until --> http://www.autoitscript.com/autoit3/docs/keywords/Do.htm Edited January 2, 2013 by johnmcloud Link to comment Share on other sites More sharing options...
Hybrid Posted January 2, 2013 Share Posted January 2, 2013 (edited) Next time put ur code in [ autoit] & [/ autoit] tags And, you should make a func like _StartLoop() ;code here EndFunc and then For $i = 1 To 5 _StartLoop() Next MsgBox(64, "", "Loop Has Been Successfully Executed~!",10) Hope I helped you Edited January 2, 2013 by Hybrid Link to comment Share on other sites More sharing options...
niruse Posted January 2, 2013 Author Share Posted January 2, 2013 sorry i still learning how to use this forum expandcollapse popupBlockInput (1) ;format paratitions a-h on dos Runwait(@ComSpec & " /c "& "format a: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW) winclose("C:\WINDOWS\system32\cmd.exe");Windows XP winclose("Administrator: C:\Windows\system32\cmd.exe");Vista Runwait(@ComSpec & " /c "& "format b: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW) winclose("C:\WINDOWS\system32\cmd.exe");Windows XP winclose("Administrator: C:\Windows\system32\cmd.exe");Vista Runwait(@ComSpec & " /c "& "format d: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW) winclose("C:\WINDOWS\system32\cmd.exe");Windows XP winclose("Administrator: C:\Windows\system32\cmd.exe");Vista Runwait(@ComSpec & " /c "& "format e: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW) winclose("C:\WINDOWS\system32\cmd.exe");Windows XP winclose("Administrator: C:\Windows\system32\cmd.exe");Vista Runwait(@ComSpec & " /c "& "format f: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW) winclose("C:\WINDOWS\system32\cmd.exe");Windows XP winclose("Administrator: C:\Windows\system32\cmd.exe");Vista Runwait(@ComSpec & " /c "& "format g: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW) winclose("C:\WINDOWS\system32\cmd.exe");Windows XP winclose("Administrator: C:\Windows\system32\cmd.exe");Vista Runwait(@ComSpec & " /c "& "format h: /FS:FAT32 /v:USB_Boot /x /y",@WindowsDir,@SW_SHOW) winclose("C:\WINDOWS\system32\cmd.exe");Windows XP winclose("Administrator: C:\Windows\system32\cmd.exe");Vista ; ---------------------------------------------------------------------------------------------------------------- ; Define the include files #include <Array.au3> #include <file.au3> ; ---------------------------------------------------------------------------------------------------------------- ; Variables Local $s_SystemDriveLetter Local $s_AssignedDriveLetter Local $s_SystemPartitionID Local $s_SystemDeviceID Local $i_SystemDeviceSize Local $i_SystemPartitionSize Local $i_NumberOfPartitions Local $a_DriveDetails[1][3] Local $wbemFlagReturnImmediately = 0x10 Local $wbemFlagForwardOnly = 0x20 Local $h_wbemFlags = $wbemFlagReturnImmediately + $wbemFlagForwardOnly Local $s_ComputerName = @ComputerName Local $s_TagContent = "%PHYSICALDRIVE%" Local $s_DriveDelimiter = "%:" Local $i_Counter = 0 Global $s_SystemTempHome = @TempDir Global $s_DiskpartCommandsFile = $s_SystemTempHome & "\" & "commands.txt" ; ---------------------------------------------------------------------------------------------------------------- ; Set the WMI-Service $o_WMIService = ObjGet("winmgmts:\\" & $s_ComputerName & "\root\CIMV2") ; ---------------------------------------------------------------------------------------------------------------- ; First of all the DriveLetters of optical and removable drives are renamed ; out of the way, starting with "O:" for optical and "R:" for removable drives. ; Using this convention it would be possible to have up to six ptical and ; removable drives in one system, wich should happen quite seldom. Also it ; would be possible to have up to 17 logical volumes in a system (drives C: ; through T:). ; ; 1st get arrays of WMI objects this could be simplified into one array pro- ; vided with another column containing the "Descriptions" ('CD-ROM Disc' and ; 'Removalbe Disk'). $o_OpticalDrives = $o_WMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE Description = 'CD-ROM Disc'", "WQL", $h_wbemFlags) $o_RemovableDrives = $o_WMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE Description = 'Removable Disk'", "WQL", $h_wbemFlags) ; 2nd create the arrays containing the GUIDs and their DriveLetters ; ; ...for Optical Drives Global $a_OpticalDriveList[1][2] For $o_items in $o_OpticalDrives $s_DriveLetter = $o_items.Caption Local $a_TempAdd[2] = [$s_DriveLetter, _FindGUID($s_DriveLetter)] _2DArrayAdd($a_OpticalDriveList, $a_TempAdd, False) Next _ArrayDelete($a_OpticalDriveList, 0) ; ...and then the Removable Disks Global $a_RemovableDriveList[1][2] For $o_items in $o_RemovableDrives $s_DriveLetter = $o_items.Caption Local $a_TempAdd[2] = [$s_DriveLetter, _FindGUID($s_DriveLetter)] _2DArrayAdd($a_RemovableDriveList, $a_TempAdd, False) Next _ArrayDelete($a_RemovableDriveList, 0) ; 3rd change the driveletters ; Due to the fact that optical drives usually get the drive letter "D:" after ; the base operating system installation, they must be "moved" first. Then I ; treat the removable drives, which also get lower drive letters at start. ; Finally the hard drives are handled; they will close upo after "C:". ; ; ...for Optical Drives, starting with "O:" for "optical" $s_FirstOpticalDrive = "O" For $i = 0 to UBound($a_OpticalDriveList) - 1 $s_cmd = "mountvol " & $a_OpticalDriveList[$i][0] & " /D" RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_HIDE) $s_DriveLetterCharNew = Chr((Asc($s_FirstOpticalDrive)) + $i) $a_OpticalDriveList[$i][0] = $s_DriveLetterCharNew & ":" $s_cmd = "mountvol " & $a_OpticalDriveList[$i][0] & " " & $a_OpticalDriveList[$i][1] RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_HIDE) Next ; ...and then the Removable Disks (USB), starting with "R:" for "removable" $s_FirstRemovableDrive = "R" For $i = 0 to UBound($a_RemovableDriveList) - 1 $s_cmd = "mountvol " & $a_RemovableDriveList[$i][0] & " /D" RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_HIDE) $s_DriveLetterCharNew = Chr((Asc($s_FirstRemovableDrive)) + $i) $a_RemovableDriveList[$i][0] = $s_DriveLetterCharNew & ":" $s_cmd = "mountvol " & $a_RemovableDriveList[$i][0] & " " & $a_RemovableDriveList[$i][1] RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_HIDE) Next ; ---------------------------------------------------------------------------------------------------------------- ; Now Mine for information about the partition/volume/drive containing the ; operating system, so we later can get the size of the volume housing it. ; This is important to estimate the sense of creating a second data partition ; on that drive. ; ; Get the (1) DriveLetter (aka "C:") of the partition containing the OS $o_OperatingSystem = $o_WMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE SystemDrive LIKE '" & $s_DriveDelimiter & "' ", "WQL", $h_wbemFlags) For $o_items in $o_OperatingSystem $s_SystemDriveLetter = $o_items.SystemDrive Next ; Get the (2) DeviceID (aka "Disk #0, Partition #0") of the system partition $o_LogicalDiskToPartition = $o_WMIService.ExecQuery("SELECT * FROM Win32_LogicalDiskToPartition", "WQL", $h_wbemFlags) For $o_items in $o_LogicalDiskToPartition If StringRight($o_items.Dependent,4) = """" & $s_SystemDriveLetter & """" then $s_SystemPartitionID = StringLeft(StringRight($o_items.Antecedent, 22), 21) EndIf Next ; Get the (3) DeviceID (aka "\\\.\PHYSICALDRIVE0") of the device conbtaining ; the system partition $o_DiskDriveToDiskPartition = $o_WMIService.ExecQuery("SELECT * FROM Win32_DiskDriveToDiskPartition", "WQL", $h_wbemFlags) For $o_items in $o_DiskDriveToDiskPartition If StringRight($o_items.Dependent,23) = """" & $s_SystemPartitionID & """" then $s_SystemDeviceID = StringLeft(StringRight($o_items.Antecedent, 22), 21) EndIf Next ; ---------------------------------------------------------------------------------------------------------------- ; Get the size of the partition containing the OS $o_DiskPartition = $o_WMIService.ExecQuery("SELECT * FROM Win32_DiskPartition WHERE DeviceID = '" & $s_SystemPartitionID & "' ", "WQL", $h_wbemFlags) For $o_items in $o_DiskPartition $i_SystemPartitionSize = $o_items.Size Next ; Now get the size of the drive containing the system partition. In my defini- ; tion it is only useful to create another partition on the system drive if the ; remaining amounts to at least 10.0 GBytes ; (10GBytes = 10737418240 Bytes = 10 *1024 *1024 *1024 Bytes). $o_DiskDrive = $o_WMIService.ExecQuery("SELECT * FROM Win32_DiskDrive WHERE DeviceID = '" & $s_SystemDeviceID & "' ", "WQL", $h_wbemFlags) For $o_items in $o_DiskDrive $i_SystemDeviceSize = $o_items.Size $i_NumberOfPartitions = $o_items.Partitions If ($i_SystemDeviceSize - $i_SystemPartitionSize) >= 10737418240 And $i_NumberOfPartitions = 1 Then Local $b_2ndPartitionOnHD0 = True Local $b_CreatePartition = True Local $a_TempAdd[3] = [$o_items.DeviceId, $b_CreatePartition, $i_NumberOfPartitions] _2DArrayAdd($a_DriveDetails, $a_TempAdd, False) ElseIf $i_NumberOfPartitions = 2 Then Local $b_2ndPartitionOnHD0 = True Local $b_CreatePartition = False Local $a_TempAdd[3] = [$o_items.DeviceId, $b_CreatePartition, $i_NumberOfPartitions] _2DArrayAdd($a_DriveDetails, $a_TempAdd, False) Else Local $b_2ndPartitionOnHD0 = False Local $b_CreatePartition = False Local $a_TempAdd[3] = [$o_items.DeviceId, $b_CreatePartition, $i_NumberOfPartitions] _2DArrayAdd($a_DriveDetails, $a_TempAdd, False) EndIf Next ; Check if partitions exist on the physical units NOT containing the OS $o_DiskDrive = $o_WMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", $h_wbemFlags) For $o_items in $o_DiskDrive If StringRight($o_items.DeviceId, 14) <> StringRight($s_SystemDeviceID, 14) Then $i_NumberOfPartitions = $o_items.Partitions If $i_NumberOfPartitions = 0 Then $b_CreatePartition = True Local $a_TempAdd[3] = [$o_items.DeviceId, $b_CreatePartition, $i_NumberOfPartitions] _2DArrayAdd($a_DriveDetails, $a_TempAdd, False) Else $b_CreatePartition = False Local $a_TempAdd[3] = [$o_items.DeviceId, $b_CreatePartition, $i_NumberOfPartitions] _2DArrayAdd($a_DriveDetails, $a_TempAdd, False) EndIf EndIf Next ; Delete the first row of the array containing the drives with usable space; ; it only contains the unneeded index _ArrayDelete($a_DriveDetails, 0) ; ---------------------------------------------------------------------------------------------------------------- ; Create partitions where needed: ; On Drive 0 if more than 10GB of space are available ; On Drive n if no partitions exist ; DriveLetters are assigned starting with "D:" $s_AssignedDriveLetter = "e" $s_AssignedDriveLetter = "d" $s_AssignedDriveLetter = "f" $s_AssignedDriveLetter = "g" $s_AssignedDriveLetter = "h" $s_AssignedDriveLetter = "i" $s_AssignedDriveLetter = "j" $s_AssignedDriveLetter = "k" $s_AssignedDriveLetter = "l" For $i_i = 0 to UBound($a_DriveDetails) -1 If $a_DriveDetails[$i_i][1] = True Then $s_ActualDriveLetter = Chr((Asc($s_AssignedDriveLetter)) + $i_i) $s_ActualDrive = StringRight($a_DriveDetails[$i_i][0], 1) _FileCreate($s_DiskpartCommandsFile) FileOpen($s_DiskpartCommandsFile, 2) FileWriteLine($s_DiskpartCommandsFile, "select disk " & $s_ActualDrive) FileWriteLine($s_DiskpartCommandsFile, "create partition primary") FileWriteLine($s_DiskpartCommandsFile, "assign letter= " & $s_ActualDriveLetter) FileClose($s_DiskpartCommandsFile) $s_cmd = "diskpart /s " & $s_DiskpartCommandsFile RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_SHOW) Sleep(1000) $s_cmd = "format /fs:ntfs /x /v:TempName /Y " & $s_ActualDriveLetter & ":" RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_SHOW) FileDelete($s_DiskpartCommandsFile) EndIf Next ; ---------------------------------------------------------------------------------------------------------------- ; Finally rename the volumenames using HD0 for the first physical drive, ; HD1 for the second and HDn for all further ones. $o_LogicalDisks = $o_WMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE Description = 'Local Fixed Disk'", "WQL", $h_wbemFlags) For $o_items in $o_LogicalDisks If $o_items.Caption = $s_SystemDriveLetter Then $i_Counter = 0 $o_items.VolumeName = "HD" & $i_Counter & "-System" $o_items.Put_ ElseIf $o_items.Caption = "M:" Or $o_items.Caption = "D:" And $b_2ndPartitionOnHD0 = True Then $i_Counter = 0 $o_items.VolumeName = "HD" & $i_Counter & "-Data" $o_items.Put_ Else $i_Counter = $i_Counter + 1 $o_items.VolumeName = "HD" & $i_Counter & "-Data" $o_items.Put_ EndIf Next ; Function _FindGUID to find the GUID belonging to a DriveLetter ; ============================================================================================== Func _FindGUID($Drive) Local Const $DevList = 'HKLM\SYSTEM\MountedDevices' Local $i Do If RegRead($DevList, '\DosDevices\' & $Drive) = RegRead($DevList, RegEnumVal($DevList, $i)) Then Return StringReplace(RegEnumVal($DevList, $i), '\??\', '\\?\', 1) $i += 1 Until 0 EndFunc ;==>_FindGUID ; Function _2DArrayAdd to add lines to a two-dimensional array ; ============================================================================================== Func _2DArrayAdd(ByRef $avArray, $vValue, $NestArray = True) Local $iBoundArray0, $iBoundArray1, $iBoundArray2, $iBoundValue1 ; $avArray is not an array If IsArray($avArray) = 0 Then Return SetError(1, 0, -1) ; No. of dimesions in array $iBoundArray0 = UBound($avArray, 0) ; $avArray is more than 2D If $iBoundArray0 > 2 Then Return SetError(1, 1, -1) ; Size of array in first dimension $iBoundArray1 = UBound($avArray, 1) ; Size of array in second dimension If $iBoundArray0 = 2 Then $iBoundArray2 = UBound($avArray, 2) ; If input array is 1D, or $vValue is not an array, or $NestArray = True (default) then save $vValue literally If ($iBoundArray0 = 1) Or (IsArray($vValue) = 0) Or $NestArray Then If $iBoundArray0 = 1 Then ; Add to 1D array ReDim $avArray[$iBoundArray1 + 1] $avArray[$iBoundArray1] = $vValue Else ; Add to 2D array at [n][0] ReDim $avArray[$iBoundArray1 + 1][$iBoundArray2] $avArray[$iBoundArray1][0] = $vValue EndIf Else ; If input array is 2D, and $vValue is an array, and $NestArray = False, ; then $vValue is a 1D array of values to add as a new row. ; $vValue array is not 1D If UBound($vValue, 0) <> 1 Then Return SetError(1, 2, -1) $iBoundValue1 = UBound($vValue, 1) ; $vValue array has too many elements If $iBoundArray2 < $iBoundValue1 Then Return SetError(1, 3, -1) ReDim $avArray[$iBoundArray1 + 1][$iBoundArray2] For $n = 0 To $iBoundValue1 - 1 $avArray[$iBoundArray1][$n] = $vValue[$n] Next EndIf ; Return index of new last row in $avArray Return $iBoundArray1 WEnd EndFunc ;==>_2DArrayAdd i need to loop when it starts to identify and makes new partitions after it formats a-h partitions Link to comment Share on other sites More sharing options...
BrewManNH Posted January 2, 2013 Share Posted January 2, 2013 This section of code: ; ---------------------------------------------------------------------------------------------------------------- ; Create partitions where needed: ; On Drive 0 if more than 10GB of space are available ; On Drive n if no partitions exist ; DriveLetters are assigned starting with "D:" $s_AssignedDriveLetter = "e" $s_AssignedDriveLetter = "d" $s_AssignedDriveLetter = "f" $s_AssignedDriveLetter = "g" $s_AssignedDriveLetter = "h" $s_AssignedDriveLetter = "i" $s_AssignedDriveLetter = "j" $s_AssignedDriveLetter = "k" $s_AssignedDriveLetter = "l" is written wrong. After this executes, $s_AssignedDriveLetter will always equal l, because you're assigning the values to the same variable name over and over again. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
guinness Posted January 2, 2013 Share Posted January 2, 2013 _StartLoop() ;code here EndFunc I think you meant this Func StartLoop() ; Add code. EndFunc ;==>StartLoop UDF List:  _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
niruse Posted January 3, 2013 Author Share Posted January 3, 2013 I tried each commands of loop scripts that i found, and I got this same error again and again http://up361.siz.co.il/up3/tdocynjtjd0m.bmp example of loops scripts that I tried 1) for $i = 1 to 5 add code next 2) Func StartLoop() Add code EndFunc ;==>StartLoop hopes for help thanks again Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now