Jump to content

batch & VBS script to take file ownership


Nepali

Recommended Posts

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?

Link to comment
Share on other sites


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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 3 weeks later...
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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
Share on other sites

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