Solved

Take ownership of multiple files

Posted on 2006-11-09
1
604 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
seriesUp challenge 7 107
Fix45 challenge 15 85
Delphi Mdi application Child forms get behind control 7 112
Fibonacci challenge 11 82
A short article about problems I had with the new location API and permissions in Marshmallow
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now