Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

taking ownership of a file/folder

Status
Not open for further replies.

cynic006

MIS
Nov 24, 2004
16
0
0
US
i am trying to write a script that takes ownership of a file. i was sucessfull in finding a way to do this as a test:

strComputer = "."

Set objWMIService = _
GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set objShare = objWMIService.Get("Win32_Directory")

Set objOutParams = objWMIService.ExecMethod( _
"Win32_Directory.Name='C:\\temp'", "TakeOwnerShip")

so this works, now i want to be able to do this for a list of servers which i have read in before.

basically my issue is with the last line when i try and use a UNC path instead. any ideas on why?
 
How about using WMI to connect to the server and then use the local path:

Code:
strComputer = "ServerName" 

Set objWMIService = _
    GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 

Set objShare = objWMIService.Get("Win32_Directory")

Set objOutParams = objWMIService.ExecMethod( _
    "Win32_Directory.Name='C:\\temp'", "TakeOwnerShip")

Ben.

 
thanks, i had managed to get this far on my own. so now i can take ownership of a folder, but not a file. do you know of a way to take ownership of a file?


thanks
 
nevermind. i managed to take care of this. thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top