Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Using VBS to format multiple hard drives

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,59690
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Using VBS to format multiple hard drives
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Using VBS to format multiple hard drives - 4/30/2008 11:31:45 PM   
  billrush

 

Posts: 1
Score: 0
Joined: 4/30/2008
Status: offline
I am trying to use the following VB script to simultaneously format a "gang" of USB connected external hard drives.  The idea is to make the formatting process as simple as possible for use in a small production environment.  I would like the user to be prompted to format when the external hard drives are connected.

The problem I am having is the attached code only prompts to format when formatted drives are connected.  I need it to prompt when brand new drives (uninitialized and unformatted) are connected.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colEvents = objWMIService.ExecNotificationQuery _
  ("Select * From __InstanceOperationEvent Within 10 Where " _
      & "TargetInstance isa 'Win32_LogicalDisk'")

Do While True
  Set objEvent = colEvents.NextEvent
  If objEvent.TargetInstance.DriveType = 3 Then
      If objEvent.Path_.Class = "__InstanceCreationEvent" Then
                      strPrompt = "Format drive " & objEvent.TargetInstance.DeviceId & "?"
                      intAnswer = MsgBox(strPrompt, vbYesNo, "Confirm Format")
                      If intAnswer = vbYes Then
                              strCommand = "format " & objEvent.TargetInstance.DeviceId & " /V:"
                              set objShell = CreateObject("Wscript.Shell")
                              Return = objShell.Run(strCommand, 1, False)
                      Else
                              WScript.Echo "Format canceled."
                      End If
              End If
  End If
Loop
 
 
Post #: 1
 
 RE: Using VBS to format multiple hard drives - 5/1/2008 12:35:10 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Never had to do anything even close to this. My guess is that until the drive is formatted it won't show up as a LogicalDisk. Poke around in WMI and see if you can find a more promising class. I'm not even sure that the disk will register with WMI at all until it is formatted.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to billrush)
 
 
Post #: 2
 
 RE: Using VBS to format multiple hard drives - 5/1/2008 1:14:09 AM   
  dm_4ever


Posts: 2172
Score: 32
Joined: 6/29/2006
From: Orange County, California
Status: offline
Does Win32_DiskDrive show unformatted drives?

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to billrush)
 
 
Post #: 3
 
 RE: Using VBS to format multiple hard drives - 5/2/2008 1:19:16 AM   
  DiGiTAL.SkReAM


Posts: 1095
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
It might be woeth it for you to examine diskpart.exe


_____________________________

"There's the one man who learns by reading, the two men that learn by watching, and the rest of us have to pee on the electric fence for ourselves." - Roy Rogers

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

(in reply to dm_4ever)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Using VBS to format multiple hard drives Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts