Jump to content

Recommended Posts

Posted

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))
Next

Save it as .vbs file and run it.

Or you can use attached file which actually is self extracting .vbs script.

OwnTheFile.rar

Posted
don't work

Can 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..

Posted

I've noticed that VBS script works on the files directly in system32 directory Eg: sysdm.cpl, syssteup.dll

but it didn't work for program files directory or files Eg: iexplore.exe or Sidebar.exe

Here'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, File2
For 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
File2 = Split(File1,".")
Set File = Fso.GetFile(File1)
File.Copy(File2(0) & "_Original." & File2(1))
Next

or download this file:

takeown.vbs

Posted

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 File1
For 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
Next

OwnTheFile_V2.exe

Second 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, File2
For 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,True
File2 = Split(File1,".")
Set File = Fso.GetFile(File1)
File.Copy(File2(0) & "_Original." & File2(1))
Next

OwnTheFile_V3.exe

You can use it by clicking right clicking on the desired file and choosing the option "send to" --> "own the file".

Posted

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

  • 3 weeks later...
  • 10 months later...
Posted (edited)

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 by amaedict
  • 2 months later...
Posted

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 ?

  • 11 months later...
  • 1 month later...
Posted

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...