Jump to content

batch & VBS script to take file ownership


Recommended Posts

Posted
Working perfect...

please add the script to rename the file for backup purpose well.. as for previous one..

B)

Here it is, just drag and drop the original file on the script, it'll modify permissions for the original file and make another copy of the same file in source directory..

Thank You gunsmokingman! :)

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

BTW, how can I add now this new script to my right click selection?


Posted
Working perfect...

please add the script to rename the file for backup purpose well.. as for previous one..

B)

Here it is, just drag and drop the original file on the script, it'll modify permissions for the original file and make another copy of the same file in source directory..

Thank You gunsmokingman! :)

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

BTW, how can I add now this new script to my right click selection?

I have made this new script into a sfx fle that extracts to the Sendto folder,

this one does not create a extra copy of the file

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

I have made this new script into a sfx fle that extracts to the Sendto folder

Save as OwnTheFile_V3

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

OwnTheFile_V2.exe

Posted

wooo something i was looking for, hmm isit there anyway you can take over everyfile because that would save time an effort in a sense

Posted
wooo something i was looking for, hmm isit there anyway you can take over everyfile because that would save time an effort in a sense

This can do multiple files, but there is a limit to how many the Wscript.Arguments can handle.

I believe it can handle under 24 files at a time, but do not quote me on that.

Posted

Yesss, it is working great with every files i have checked till now..

if problem persist.. rectification will obviously be done

Thanks Gunsmokingman for his effort for making the VBS script for sendto menu.

Posted (edited)

now you can take ownership with the registry file

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"

SHIFT + Right Click = Gain Ownership context menu

ownership.reg

Edited by Nepali
Posted
now you can take ownership with the registry file

What this reg entry gives us, right click option to take ownership or?

Thx

Posted (edited)

merging this, you will get option to gain ownership for files and folder

SHIFT + Rt click

Edited by Nepali
  • 3 weeks later...
Posted
Working perfect...

please add the script to rename the file for backup purpose well.. as for previous one..

B)

Here it is, just drag and drop the original file on the script, it'll modify permissions for the original file and make another copy of the same file in source directory..

Thank You gunsmokingman! :)

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

BTW, how can I add now this new script to my right click selection?

I have made this new script into a sfx fle that extracts to the Sendto folder,

this one does not create a extra copy of the file

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

I have made this new script into a sfx fle that extracts to the Sendto folder

Save as OwnTheFile_V3

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

i get a permissions error when i try to run and i'm not sure how to force it to run as admin (or whatever permissions are needed)

now you can take ownership with the registry file
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"

SHIFT + Right Click = Gain Ownership context menu

This doesnt allow for gaining of ownership of executeables

Posted

I used this script to change the permission on mspaint.exe

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

The other scripts I posted where to change permission in the Program Files because of the space in the name.

Before OwnTheFile

BeforeOwnTheFile.jpg

After OwnTheFile

AfterOwnTheFile.jpg

  • 1 month later...
Posted (edited)

I was wondering if anyone can help me with this unkown user?

I would like to remove it if I could, I am the only user on this computer and the guest account is disabled.

vistartm034ub8.gif

Should I run a script to take ownership of "everything" ?

Edited by kartel
  • 1 year later...

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