Автор: Teo
Дата сообщения: 24.05.2007 16:47
jONES1979
вот [more=скрипт полностью]'TODO
' - add repartition command via diskpart for each volume
' - add possibility to auto generate cmd.txt
'
Option Explicit
Dim boolDebugEnabled, boolOk
Dim strComputerName, strQuery, strMessage, strDiskPartCmdPath, strDriveLetterToChange, strNeededDriveLetter
Dim wmiServices, wmiDiskDrives, wmiDiskDrive, wmiDiskPartitions, wmiDiskPartition, wmiLogicalDisks, wmiLogicalDisk, WshShell, objWmiService, colDisks, objDisk
Dim intCounter, intDiskDriveIndex
Dim subChangeLetter, objFSO, objDiskPartCMDFile, strDiskPartCmd
strComputerName = "."
'WScript.Echo Chr("C")+1
'''''''''''''''''''''''''''''''''''''''''''''''''
boolDebugEnabled = false
'''''''''''''''''''''''''''''''''''''''''''''''''
IF boolDebugEnabled THEN
WScript.Echo "Debug is ON. Output will be verbose."
END IF
subCheckPartitionsAmount
WScript.Echo subCheckLogicalDisksAmount(intCounter)
'so we have exactly 4 logical disks and 4 partitions, running main check procedure
subMainCheck boolOk
IF boolOk THEN
WScript.Echo "All drives are connected properly."
ELSE
SET WshShell = WScript.CreateObject("WScript.Shell")
strDiskpartCmdPath = Chr(34) & "c:\Windows\Temp\dp.cmd" & Chr(34)
WshShell.Run (strDiskpartCmdPath)
END IF
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
FUNCTION subCheckPartitionsAmount
Set wmiServices = GetObject ( _
"winmgmts:{impersonationLevel=Impersonate}!//" _
& strComputerName)
' Get physical disk drive
Set wmiDiskDrives = wmiServices.ExecQuery ( _
"SELECT * FROM Win32_DiskDrive")
For Each wmiDiskDrive In wmiDiskDrives
If boolDebugEnabled Then
'WScript.Echo "Checking disk: " & wmiDiskDrive.Caption & VbNewLine & "DeviceID: " _
' & " (" & wmiDiskDrive.DeviceID & ")"
WScript.Echo "Disk number: " & wmiDiskDrive.Index & " has " & wmiDiskDrive.Partitions & " partitions"
End If
IF wmiDiskDrive.Partitions <> 2 THEN
strMessage = "ATTENTION!!! " & "Disk " & wmiDiskDrive.Index & " doesn't contain 2 partitions"
subQuit (strMessage)
END IF
NEXT
END FUNCTION
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
FUNCTION subQuit (strMessage)
WScript.Echo strMessage
WScript.Echo "Stopping."
WScript.Quit
END FUNCTION
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
FUNCTION subCheckLogicalDisksAmount (intCounter)
Set objWMIService = GetObject("winmgmts:\\" & strComputerName & "\root\cimv2")
'checking amount of logical disks
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")
For each objDisk in colDisks
IF objDisk.DriveType = 3 THEN
intCounter = intCounter + 1
IF boolDebugEnabled THEN
Wscript.Echo "DeviceID: " & vbTab & objDisk.DeviceID
END IF
END IF
Next
IF intCounter < 4 THEN
strMessage = "ATTENTION!!! You have 4 partitions but number of logical disks is less then 4. This is odd. Please reboot so the system may assign necessary letters itself"
subQuit (strMessage)
END IF
IF intCounter > 4 THEN
strMessage = "Found more than 4 logical disks. This is odd. Please delete unnecessary."
subQuit (strMessage)
END IF
END FUNCTION
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
FUNCTION subMainCheck (boolOk)
Set wmiServices = GetObject ( _
"winmgmts:{impersonationLevel=Impersonate}!//" _
& strComputerName)
' Get physical disk drive
Set wmiDiskDrives = wmiServices.ExecQuery ( _
"SELECT * FROM Win32_DiskDrive")
For Each wmiDiskDrive In wmiDiskDrives
'Use the disk drive device id to
' find associated partition
strQuery = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" _
& wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition"
Set wmiDiskPartitions = wmiServices.ExecQuery(strQuery)
For Each wmiDiskPartition In wmiDiskPartitions
'Use partition device id to find logical disk
Set wmiLogicalDisks = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" _
& wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
FOR EACH wmiLogicalDisk IN wmiLogicalDisks
IF boolDebugEnabled THEN
WScript.Echo "Partition number " & wmiDiskPartition.Index & " on disk " & wmiDiskDrive.Index & " has letter " & wmiLogicalDisk.DeviceID
END IF
IF wmiDiskDrive.Index = 0 THEN
IF wmiDiskPartition.Index = 0 AND wmiLogicalDisk.DeviceID <> "C:" THEN
strMessage = "ATTENTION!!! It seems that system drive connected in wrong way!!!"
strMessage = "There's problem with disk " & wmiLogicalDisk.DeviceID & " It must have letter C."
subQuit (strMessage)
END IF
IF wmiDiskPartition.Index = 1 AND wmiLogicalDisk.DeviceID <> "D:" THEN
strMessage = "There's problem with disk " & wmiLogicalDisk.DeviceID & " It must have letter D."
intDiskDriveIndex = wmiDiskDrive.Index
strDriveLetterToChange = wmiLogicalDisk.DeviceID
strNeededDriveLetter = "D"
subAssignLetter intDiskDriveIndex, strDriveLetterToChange, strNeededDriveLetter
subRunDiskpart ("D")
subQuit (strMessage)
END IF
END IF
IF wmiDiskDrive.Index = 1 THEN
IF wmiDiskPartition.Index = 0 AND wmiLogicalDisk.DeviceID <> "E:" THEN
strMessage = "There's problem with disk " & wmiLogicalDisk.DeviceID & " It must have letter E."
WScript.Echo strMessage
subRunDiskpart ("E")
'subQuit (strMessage)
END IF
IF wmiDiskPartition.Index = 1 AND wmiLogicalDisk.DeviceID <> "F:" THEN
strMessage = "There's problem with disk " & wmiLogicalDisk.DeviceID & " It must have letter F."
WScript.Echo strMessage
subRunDiskpart ("F")
'subQuit (strMessage)
END IF
END IF
IF wmiLogicalDisk.DeviceID = "F:" THEN
boolOk = true
ELSE
boolOk = false
END IF
NEXT
NEXT
NEXT
END FUNCTION
FUNCTION subRunDiskpart (strLetterToChange)
WScript.Echo "Running partition tool."
SET WshShell = WScript.CreateObject("WScript.Shell")
'WScript.Echo strDiskpartCmdPath
strDiskpartCmdPath = Chr(34) & "c:\Windows\Temp\" & strLetterToChange & ".cmd" & Chr(34)
WshShell.Run (strDiskpartCmdPath)
END FUNCTION
FUNCTION subAssignLetter (intDiskDriveIndex, strDriveLetterToChange, strNeededDriveLetter)
Const ForAppending = 2
SET WshShell = WScript.CreateObject("WScript.Shell")
SET objFSO=WScript.CreateObject("Scripting.FileSystemObject")
SET objDiskPartCMDFile = objFSO.OpenTextFile("c:\windows\temp\cmd.txt",ForAppending,true)
objDiskPartCMDFile.WriteLine("select disk " & intDiskDriveIndex)
'removing BOTH letters
objDiskPartCMDFile.WriteLine("select volume " & strNeededDriveLetter)
objDiskPartCMDFile.WriteLine("remove letter " & strNeededDriveLetter)
objDiskPartCMDFile.WriteLine("select volume " & strDriveLetterToChange)
objDiskPartCMDFile.WriteLine("remove letter " & strDriveLetterToChange)
objDiskPartCMDFile.WriteLine("assign letter " & strNeededDriveLetter)
objDiskPartCMDFile.Close
strDiskpartCmd = Chr(34) & "c:\windows\system32\diskpart.exe " & Chr(34) & "/s " & Chr(34) & "c:\Windows\Temp\cmd.txt" & Chr(34)
WScript.Echo strDiskpartCmd
WshShell.Run(strDiskpartCmd)
END FUNCTION
[/more]
фактически ничего
я так понимаю, что-то с WMI
но как узнать, что?