Jump to content

batch & VBS script to take file ownership


Nepali

Recommended Posts

Simply creat a batch file to take the file ownership and to alter it.

I hate to take ownership going to system directory, right click, an blah blah blah

ECHO Taking ownership of the file uxtheme.dll

takeown /f %systemroot%\System32\uxtheme.dll

icacls %systemroot%\System32\uxtheme.dll /grant administrators:F

Echo Renaming file to uxtheme.old

ren %systemroot%\System32\uxtheme.dll uxtheme.old

Echo copying patched uxtheme.dll

xcopy /y X:\uxtheme.dll "%systemroot%\System32\"

it will be much better if somone could made it better like VBS or EXE just to ask the file name which we wants to take ownership.

Registry entry to gain ownership

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]

@="Take 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"

Edited by Nepali
Link to comment
Share on other sites


Thanks for posting this! I was thought of making something like this when I was using Vista, but that only lasted about an hour before I put XP back on...

I don't see why this could not be made into a shell extension, aka added to the right-click context menu to make things even easier...

[EDIT] untested but here's the idea:

Windows Registry Editor Version 5.00

;Take Ownership of

[HKEY_CLASSES_ROOT\*\Shell\Take Ownership of\command]

@="takeown /f %1"

@="icacls %1 /grant administrators:F"

Might be a variable for %current username% that could replace "administrators" too.

Link to comment
Share on other sites

Here is a VBS script that uses the code provided by Nepali

I have made this a sfx file that extracts to the SendTo Folder

So all you have to do is select the file and then use the

SendTo context menu to use the script.

Save As OwnTheFile.vbs

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

Self Extracting VBS

OwnTheFile.exe

Link to comment
Share on other sites

Not working here, script only makes a copy of the original file with new permissions, but the original file retains it's permissions.

1:\ I copy dfrgui.exe to my desktop

2:\ I then used my Sendto OwnTheFile

3:\ As you can see it changed the permissions

ChangePermissions.jpg

Link to comment
Share on other sites

Well, I was trying to change the permissions for the "wlsrvc.dll" file in C:\Program Files\Windows Sidebar

Here's what I did:

I've used "own the file" option from a right click selection on that file (C:\Program Files\Windows Sidebar\wlsrvc.dll)

The script made a copy of that file with _original extension for the name, and it changed the permissions for that file, not the original one.

So now I have original file "wlsrvc.dll" intact with old permissions, and the other file, made by script (wlsrvc_Original.dll) with newly permission setup.

I don't need the script to make another file, I'd like to change the permissions on the original file if possible..

What am I missing here, help.. :rolleyes:

Link to comment
Share on other sites

Try this

1:\ Make a folder called shell on %systemdrive%

2:\ Copy the file to the new folder then try the ownthefile

Note

I do not know how permission work on this I only provided a script to make

it easier to do.

Here is the same script but I have removed making a extra file.

Save As OneTheFile_V1.vbs

Dim Act : Set Act = CreateObject("Wscript.Shell")
Dim File1
For Each File1 in Wscript.Arguments
Act.Run("takeown /f " & File1),0,True
Act.Run("icacls " & File1 & " /grant administrators:F"),1,True
Next

Just open the original script with notepad and select all

and paste the above code in it to not make a extra copy.

Link to comment
Share on other sites

heres the slightly changed Script ...

ECHO Taking ownership of the file uxtheme.dll

takeown /A /f %systemroot%\System32\uxtheme.dll

icacls %systemroot%\System32\uxtheme.dll /grant administrators:F

Echo Renaming file to uxtheme.old

ren %systemroot%\System32\uxtheme.dll uxtheme.old

Echo copying patched uxtheme.dll

xcopy /y X:\uxtheme.dll "%systemroot%\System32\"

but this didn't work

Dim Act : Set Act = CreateObject("Wscript.Shell")

Dim File1

For Each File1 in Wscript.Arguments

Act.Run("takeown /A /f " & File1),1,True

Act.Run("icacls " & File1 & " /grant administrators:F"),1,True

Next

this screen popuped once while executing VBS script, does this have any meaning. I only changed the text with BOLD

errorfg8.th.jpg

Edited by Nepali
Link to comment
Share on other sites

actually what i have noticed is

The 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

But the batch script works for both directory, what could be the problem

if i copy the same iexplore.exe to the desktop, it loss the ownership by default, it doesn't need to take the ownership of the file.

So ownership should be taken from the default folder where the actual file reside.

Link to comment
Share on other sites

I tried this script on wmplayer.exe and it change the permission for the admin.

I just drag and drop it on the this script

Save as OwnTheFile_V2

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

Changedpermission.jpg

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...