VB script objvolumes.format no longer working


I use the following code as part of a backup process. For some reason the format part of the script has stopped working. I don't know why. Nothing has changed on the server (2008) unless some Microsoft patch has broken it.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colVolumes = objWMIService.ExecQuery _
    ("Select * from Win32_Volume Where Name = 'E:\\'")

For Each objVolume in colVolumes
    errResult = objVolume.Format("NTFS")

Open in new window

The drive E definitely exists, i can format it from explorer no problems.  When i execute this errresult is set to 18 however i cant find any info on what this means.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Does it run when you invoke the script manually?  If so, you should check the credentials of the scheduled task.

Does it produce an error message?
Bill PrewIT / Software Engineering ConsultantCommented:
Per this page https://msdn.microsoft.com/en-us/library/aa390432%28v=vs.85%29.aspx, error 18 documented as an "unknown error", not too helpful.

MichaelAuthor Commented:
Script is failing when called both by scheduled task and when i run it manually. I've extracted out the above code into separate script and doesn't work either. I'm logged on as admin user and the script is executed as a admin user
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Add an On Error statement and see if this is a "user interrupt" caused 18 (trappable) error
MichaelAuthor Commented:
OK guys i solved this myself. I don't know what is the root cause however what i did corrected it. This machine has several volumes mounted,

C,  A raid 1 Mirrored Set
D  A Windows Dynamic volume over 4 disks
E   A Removable USB disk
G  A Raid 5 Set Using HP Controller

Drive D had a failed disk and thus the dynamic volume was broken and offline. However this disk had no impact on the regular backup however it seem to upset the code that i was using to perform the format. I deleted this dynamic volume as it was scrap data anyhow and recreated it minus the failed disk and my format code started working again. Not sure why but i would love to know. I'm not a programmer but am good at google and cobbled together this script. With that said, I'm not always 100% sure of what the code is doing!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MichaelAuthor Commented:
It fixed it
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.