How to get vssadmin delete shadows /all to run in a batch file

Running Small Business Server 2008 on a HP ML350 G5 server.
The 3rd party backup fails often with the error:  “Failed to Create Volume Snapshot.  Result code :  0x0042313”

I have found if I execute the command:
  vssadmin delete shadows /all

This command will fix the problem.  

Question:  I'd like to run this as a batch file.  The batch file will execute the   vssadmin delete shadows /all
   command.  The   vssadmin command asks a question when it executes.  In my batch file I placed the letter Y under the command to run   vssadmin .   It seems   vssadmin does not see the Y  so it just sits there waiting for something to enter the letter Y.

I am not a script expert.  What script would you suggest I write so the   vssadmin delete shadows /all   will see the letter Y and run to completion?

Thank you for your help.
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.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Didn't try if it works with vssadmin, but usually you just write
   echo y| vssadmin delete shadows /all
Davis McCarnOwnerCommented:
Or vssadmin delete shadows /all << Y should feed the Y answer to the command.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Nope, Davis, there is no << in Windows.
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

donpickAuthor Commented:
Hello Qlemo:
  The command you suggest does not work.
The error message is "invalid command"
Then a list of "Commands Supported" follows

Is there a way to do this with vbscript or something else?
vssadmin delete shadows /all /quiet
C:\Windows\system32> echo Y | vssadmin delete shadows /all
vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool
(C) Copyright 2001-2005 Microsoft Corp.

Do you really want to delete 42 shadow copies (Y/N): [N]? Error: Unexpected failure: The handle is invalid.

C:\Windows\system32>vssadmin delete shadows /all /quiet
vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool
(C) Copyright 2001-2005 Microsoft Corp.

C:\Windows\system32>vssadmin list shadows
vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool
(C) Copyright 2001-2005 Microsoft Corp.

No items found that satisfy the query.


Open in new window

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
Davis McCarnOwnerCommented:
Did you run the file as an administrator?

I wish you had run the list option to show the shadow copies as still there before you deleted them.
I figured the fact it showed "Do you really want to delete 42 shadow copies (Y/N)" shows that there were 42 shadow copies prior to deleting them.  I figured that was sufficient rather than showing lots of irrelevant information.
donpickAuthor Commented:
Hello jrhelgeson

Excellent work!   Your solution works.  This is great, I don't have to do this manually anymore.

Hello DavisMcCarn:  Yes, I created a batch file with the commands specified by  jrhelgeson .  I opened a Command window having administrative privileges .  I ran  jrhelgeson command and it works.

So now I will schedule the execution of  the batch file and have it log in as adminstrator.

Thanks again for helping me.  I pay to use Experts – Exchange so prompt and correct answers are greatly appreciated.
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

From novice to tech pro — start learning today.