Solved

Take ownership of multiple files

Posted on 2006-11-09
1
645 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 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