Solved

Take ownership of multiple files

Posted on 2006-11-09
1
633 Views
Last Modified: 2012-06-21
I have the following script that will take ownership of 1 folder, what I want to do is to have this take ownership of a large amount of folders at once by either pulling the folder name from a text file or just listing it in the script.  So I have a directory called owner and say I have 10 folders under that called 1 through 10.. is this possible?

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
    ("Select * From Win32_Directory Where Name = 'C:\\Owner'")

For Each objFolder in colFolders
    objFolder.TakeOwnershipEx
Next
0
Comment
Question by:rtmcmullen
1 Comment
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 17908310
From the original article (http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan06/hey0111.mspx):
"The TakeOwnershipEx method enables us to take ownership not only of the folder C:\Scripts but also any subfolders found in C:\Scripts. If you don’t want to take ownership of the subfolders then use the TakeOwnership method instead."

So it should already work for the scenario you suggest.

If you did want to take ownership of several individual folders then you could use the script below, adding any desired folders to arrFolderList.

strComputer = "."

arrFolderList=Array("'C:\\Owner\\1'","'C:\\Owner\\2'")

For Each strFolder in arrFolderList
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
   Set colFolders = objWMIService.ExecQuery _
      ("Select * From Win32_Directory Where Name = " & strFolder)

   For Each objFolder in colFolders
      objFolder.TakeOwnershipEx
   Next
Next
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 122
silent install of security banner via msiexec command 4 94
C# Error - Add Failed 12 93
MacOS and programming in React 7 41
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question