Jump to content


Photo

Take ownership in Vista (.vbs script)


  • Please log in to reply
17 replies to this topic

#1 NIM

NIM

    Vigilant

  • Administrator
  • 3,839 posts
  • OS:Windows 8 x64

Posted 26 February 2007 - 05:07 PM

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.
Attached File  OwnTheFile.rar   54.05K   205 downloads

#2 MrNxDmX

MrNxDmX

    ***NR***

  • Members
  • PipPipPipPipPipPipPip
  • 2,005 posts
  • Location:İzmir\Buca
  • OS:Windows 7 x64

Posted 28 February 2007 - 11:00 AM

Wow, havent tried, bu a great time saver. That process killing my nerves.
Thanks for share.

#3 Gordon

Gordon

    Lurker

  • Members
  • Pip
  • 1 posts

Posted 02 March 2007 - 03:31 PM

don't work

#4 NIM

NIM

    Vigilant

  • Administrator
  • 3,839 posts
  • OS:Windows 8 x64

Posted 02 March 2007 - 04:06 PM

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

#5 NIM

NIM

    Vigilant

  • Administrator
  • 3,839 posts
  • OS:Windows 8 x64

Posted 03 March 2007 - 11:17 AM

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:
Attached File  takeown.vbs   429bytes   24 downloads

#6 NIM

NIM

    Vigilant

  • Administrator
  • 3,839 posts
  • OS:Windows 8 x64

Posted 03 March 2007 - 07:17 PM

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
Attached File  OwnTheFile_V2.exe   67.4K   13 downloads

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
Attached File  OwnTheFile_V3.exe   67.49K   27 downloads

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

#7 NIM

NIM

    Vigilant

  • Administrator
  • 3,839 posts
  • OS:Windows 8 x64

Posted 06 March 2007 - 01:10 PM

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"

Attached Files



#8 eXpert_1

eXpert_1

    Lurker

  • Members
  • Pip
  • 4 posts

Posted 28 March 2007 - 09:22 AM

Thanks for share.

#9 delphinas

delphinas

    Lurker

  • Members
  • Pip
  • 1 posts

Posted 01 April 2007 - 09:04 AM

Thanx! :)

#10 amaedict

amaedict

    Lurker

  • Members
  • Pip
  • 7 posts

Posted 14 February 2008 - 08:37 AM

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, 14 February 2008 - 08:38 AM.


#11 NIM

NIM

    Vigilant

  • Administrator
  • 3,839 posts
  • OS:Windows 8 x64

Posted 02 May 2008 - 09:07 PM

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 ?



#12 Primavera

Primavera

    Lurker

  • Members
  • Pip
  • 1 posts
  • OS:non-selected

Posted 18 April 2009 - 06:04 AM

ownership.reg

Working perfect on Vista Ultimate...Thanks very much.

#13 AMIRZ

AMIRZ

    Loyal Member and Friend

  • Contributors
  • 517 posts
  • Location:Jakarta
  • OS:Windows 7

Posted 18 April 2009 - 01:46 PM

:D Lol nice bump! And really pretty nice tweak thanks! :thumbsup_anim:

#14 babu

babu

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts
  • Location:India
  • OS:Windows 8 x86

Posted 13 June 2009 - 05:17 PM

When i want to name a folder it cannot be named.Can this file help.

#15 NIM

NIM

    Vigilant

  • Administrator
  • 3,839 posts
  • OS:Windows 8 x64

Posted 13 June 2009 - 07:37 PM

this script can't, it would have to be modified and question box inserted..

#16 AMIRZ

AMIRZ

    Loyal Member and Friend

  • Contributors
  • 517 posts
  • Location:Jakarta
  • OS:Windows 7

Posted 13 June 2009 - 08:02 PM

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

#17 babu

babu

    Advanced Member

  • Members
  • PipPipPip
  • 66 posts
  • Location:India
  • OS:Windows 8 x86

Posted 14 June 2009 - 05:55 AM

Even after creating a new folder it cannot be named.Please clarify my doubt.

#18 AMIRZ

AMIRZ

    Loyal Member and Friend

  • Contributors
  • 517 posts
  • Location:Jakarta
  • OS:Windows 7

Posted 15 June 2009 - 09:30 PM

Maybe you got a malware attack?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users