Posted February 26, 200718 yr You have probably run into the situation, where you had to take ownership of the file or folder in Vista, so you can mess with it..To fasten this process a bit, you can use this script, which will add an option in context menu for the file.Right click on the file --> Send To --> OwnThefile.Here's the code for the script:Dim Act : Set Act = CreateObject("Wscript.Shell")Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")Dim File, File1, File2 For Each File1 in Wscript.Arguments Act.Run("takeown /f " & File1),0,True Act.Run("icacls " & File1 & " /grant administrators:F"),1,True File2 = Split(File1,".") Set File = Fso.GetFile(File1) File.Copy(File2(0) & "_Original." & File2(1)) NextSave it as .vbs file and run it.Or you can use attached file which actually is self extracting .vbs script.OwnTheFile.rar
February 28, 200718 yr Wow, havent tried, bu a great time saver. That process killing my nerves.Thanks for share.
March 2, 200718 yr Author don't workCan you provide more information. Did you get a right click option to take file ownership or not at all. Or this script won't take ownership of the file..
March 3, 200718 yr Author I've noticed that VBS script works on the files directly in system32 directory Eg: sysdm.cpl, syssteup.dllbut it didn't work for program files directory or files Eg: iexplore.exe or Sidebar.exeHere's the code for a new script that is working for sure (save it with .vbs extension).Just drag and drop the original file on the script and it'll modify permissions for the original file and make another copy of the same file in the source directory (backup)..Dim Act : Set Act = CreateObject("Wscript.Shell")Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")Dim File1, File2For Each File1 in Wscript.Arguments Act.Run("takeown /A /f " & Chr(34) & File1 & chr(34)),1,True Act.Run("icacls " & Chr(34) & File1 & chr(34) & " /grant administrators:F"),1,TrueFile2 = Split(File1,".")Set File = Fso.GetFile(File1)File.Copy(File2(0) & "_Original." & File2(1))Nextor download this file:takeown.vbs
March 3, 200718 yr Author Here are two sfx files.One will take ownership of the original file and made a copy of that file.Dim Act : Set Act = CreateObject("Wscript.Shell")Dim File1For Each File1 in Wscript.Arguments Act.Run("takeown /A /f " & Chr(34) & File1 & chr(34)),1,True Act.Run("icacls " & Chr(34) & File1 & chr(34) & " /grant administrators:F"),1,True NextOwnTheFile_V2.exeSecond will only take ownership of the original file.Dim Act : Set Act = CreateObject("Wscript.Shell")Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")Dim File, File1, File2For Each File1 in Wscript.Arguments Act.Run("takeown /A /f " & Chr(34) & File1 & chr(34)),0,True Act.Run("icacls " & Chr(34) & File1 & chr(34) & " /grant administrators:F"),0,TrueFile2 = Split(File1,".")Set File = Fso.GetFile(File1)File.Copy(File2(0) & "_Original." & File2(1))NextOwnTheFile_V3.exeYou can use it by clicking right clicking on the desired file and choosing the option "send to" --> "own the file".
March 6, 200718 yr Author Here's the .reg file that will give you the SHIFT + Right Click = Gain Ownership context menu Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\*\shell\runas]@="Gain Ownership""Extended"="""NoWorkingDirectory"=""[HKEY_CLASSES_ROOT\*\shell\runas\command]@="cmd.exe /c takeown /A /f \"%1\" && icacls \"%1\" /grant administrators:F""IsolatedCommand"="cmd.exe /c takeown /A /f \"%1\" && icacls \"%1\" /grant administrators:F"[HKEY_CLASSES_ROOT\Directory\shell\runas]@="Gain Ownership""Extended"="""NoWorkingDirectory"=""[HKEY_CLASSES_ROOT\Directory\shell\runas\command]@="cmd.exe /c takeown /A /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t""IsolatedCommand"="cmd.exe /c takeown /A /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"ownership.reg
February 14, 200817 yr What if i want to take ownership of a specific file. Say for example i want to take ownership of a file inside the windows system 32 folder. but i dont want to browse all the way there and then right click. Is there a way i can just have a vbscript that i can run from anywhere that will just automaticly take ownership of that specific file and rename it to .old ?This would be really handy for replacing the mui file for example when you wanna remove the watermark from vista sp1. Is it possible tho ? Edited February 14, 200817 yr by amaedict
May 2, 200816 yr Author That would be much harder to achieve. I could do it so you enter the name of the file in the prompt box but I would have to specify the target directory in the script.What if i want to take ownership of a specific file. Say for example i want to take ownership of a file inside the windows system 32 folder. but i dont want to browse all the way there and then right click. Is there a way i can just have a vbscript that i can run from anywhere that will just automaticly take ownership of that specific file and rename it to .old ?This would be really handy for replacing the mui file for example when you wanna remove the watermark from vista sp1. Is it possible tho ?
June 13, 200915 yr Author this script can't, it would have to be modified and question box inserted..
June 13, 200915 yr Also you can't name/rename a folder usually because one or more processes may "use" it when running in memory (i.e when you open a file that is in the folder using default app etc). Just restart Windows Explorer or close/stop the current app/process by using Task Manager etc
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.