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.
LVL 2
A5technologyAsked:
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.

Shift-3Commented:
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

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

Thanks,
Ben
0
Shift-3Commented:
In that case, use SubInACL with the /setowner switch.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

A5technologyAuthor Commented:
Subinacl with the /setowner switch doesn't appear to work on server 2008. No files are modified.
0
Shift-3Commented:
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.
0
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.
0

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.