VBscript to Change Owner of a Folder

I need a script or function that will set/change folder ownership to the account which I specify. I am trying to change owners on a recently migrated fileserver so that I can get owner based reports to work properly. I will award full points to anyone who can get this working.
Who is Participating?
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.

The easiest way to do this is with the takeown command, which is included by default with versions of Windows from Server 2003 up.

If you need to use vbscript, you can call takeown with the shell Run method, e.g.

strFolder = "c:\folder name"
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "takeown /f " & Chr(34) & strFolder & Chr(34) & " /r", 0, True

Open in new window

A5technologyAuthor Commented:
But that would make ME the owner, I need to specify an account to make the owner.

In that case, use SubInACL with the /setowner switch.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

A5technologyAuthor Commented:
Subinacl with the /setowner switch doesn't appear to work on server 2008. No files are modified.
Ok, use icacls with the /setowner switch then.  Note that you may have to use takeown first if you don't already have Full Control of the folders.
A5technologyAuthor Commented:
I found a script that would do what I asked for. Since I asked for a script and NOT a command I am not awarding the points to the above expert. Please close this question.

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
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.