Jump to content

niruse

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by niruse

  1. ty for help now i gonna try hope ill back with asnwers ty now ill learn and read it works well
  2. sorry for didnt write any information at title i forgot hi guys i still learning autoit script and i have a small question if anyone knows. my script make a question of yes and no and i wanna make an option for my client . when he press no i wanna let him choose the time to run script, and after the time gone it ask again if run the script or wait again(i wanna backup outlook files and i cant close the program when my manager write some important mails so i let him choose the time). thanks anyways ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file) $answer = MsgBox(4, "AutoIt Example (English Only)", "run backup now?") ; Check the user's answer to the prompt (see the help file for MsgBox return values) ; If "No" was clicked (7) then exit the script If $answer = 7 Then MsgBox(0, "choose time to run backup") EndIf ; Run MSDos Run("notepad.exe") WinWaitActive("[CLASS:Notepad]")
  3. 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
  4. sorry i still learning how to use this forum BlockInput (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
  5. 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 5 then i should put the command and then next so how do i put it in script? script... BlockInput (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 from there i want to start this 5 times loop ; ---------------------------------------------------------------------------------------------------------------- ; 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 = "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) 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 EndFunc ;==>_2DArrayAdd ty waiting for answer
×
×
  • Create New...