New
#520
Oh well... I'll just have to keep looking.
Another localization you might want to include: The label "Take Ownership" can be translated to different languages.
Here's the latest version, which includes this:
I'll leave it to you (or other users) to add any other languages anyone wants. I have no need for anything except English, so I haven't been able to test any of them. The translations of "Take Ownership" are from Google Translate.Code:REM Install "Take ownership" to context menu (with automatic localization) @TITLE %~nx0 REM Add "Take Ownership" to context menus REM Created by: Shawn Brink REM Updated on: September 18th 2019 REM Tutorial: https://www.tenforums.com/tutorials/3841-add-take-ownership-context-menu-windows-10-a.html @Rem ********** User-configurable options. *********** REM To pause before execution, enable this line REM SET PauseBefore=PAUSE ^& & SET PauseBeforePS=PAUSE ^^^& REM To pause after execution, enable this line SET PauseAfter= ^& PAUSE& SET PauseAfterPS= ^^^& PAUSE REM To pause after execution only if error, enable this line REM SET PauseAfter= ^|^| PAUSE& SET PauseAfterPS= ^^^|^^^| PAUSE REM Position in context menu REM Permissible values are top, middle and bottom SET Position=middle @Rem ********** End of user-configurable options. *********** REM Do we have admin rights? openfiles >NUL: 2>&1 || (@echo This script must be run as administrator! & pause & exit /b 2) REM Get Windows' Installed Language. FOR /F "tokens=2*" %%P IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Nls\Language" /V "Default" ^| find /i "REG_"') DO set Language=%%Q REM English: Yes IF %Language% EQU 0409 SET Yes=Y& SET TO-label=Take Ownership REM French: Oui IF /I %Language% EQU 040C SET Yes=O& SET TO-label=Prendre possession REM Spanish: Si IF /I %Language% EQU 0C0A SET Yes=S& SET TO-label=Tomar posesión REM Add more languages here IF NOT DEFINED Yes @ECHO I don't know what language %Language% is. You'll have to add it. & PAUSE & EXIT /B 2 REM Get path to "Users" directory. FOR /F "tokens=2*" %%P IN ('REG QUERY "HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList" /V "ProfilesDirectory" ^| find /i "REG_"') DO set ProfPath=%%Q REM Delete any old versions REG delete "HKLM\Software\Classes\*\shell\TakeOwnership" /f REG delete "HKLM\Software\Classes\*\shell\runas" /f REG delete "HKLM\Software\Classes\dllfile\shell\runas" /f REG delete "HKLM\Software\Classes\Directory\shell\runas" /f REG delete "HKLM\Software\Classes\Directory\shell\TakeOwnership" /f REG delete "HKLM\Software\Classes\Drive\shell\runas" /f REG add "HKLM\Software\Classes\*\shell\runas" /ve /t REG_SZ /d "%TO-label%" /f REG add "HKLM\Software\Classes\*\shell\runas" /v "Icon" /t REG_SZ /d "C:\Windows\System32\imageres.dll,-78" /f REG delete "HKLM\Software\Classes\*\shell\runas" /v "Extended" /f REG add "HKLM\Software\Classes\*\shell\runas" /v "HasLUAShield" /t REG_SZ /d "" /f REG add "HKLM\Software\Classes\*\shell\runas" /v "NoWorkingDirectory" /t REG_SZ /d "" /f REG add "HKLM\Software\Classes\*\shell\runas" /v "Position" /t REG_SZ /d "%Position%" /f REG add "HKLM\Software\Classes\*\shell\runas\command" /ve /t REG_SZ /d "cmd.exe /c %PauseBefore% takeown /f "%%1" && icacls "%%1" /GRANT *S-1-3-4:F /c /l%PauseAfter%" /f REG add "HKLM\Software\Classes\*\shell\runas\command" /v "IsolatedCommand" /t REG_SZ /d "cmd.exe /c %PauseBefore% takeown /f "%%1" && icacls "%%1" /GRANT *S-1-3-4:F /c /l%PauseAfter%" /f REG add "HKLM\Software\Classes\Directory\shell\TakeOwnership" /ve /t REG_SZ /d "%TO-label%" /f REG ADD "HKLM\SOFTWARE\Classes\Directory\shell\TakeOwnership" /V "AppliesTo" /T REG_SZ /D "NOT (System.ItemPathDisplay:="%ProfPath%" OR System.ItemPathDisplay:="%ProgramData%" OR System.ItemPathDisplay:="%SystemRoot%" OR System.ItemPathDisplay:="%SystemRoot%\\System32" OR System.ItemPathDisplay:="%ProgramFiles%" OR System.ItemPathDisplay:="%ProgramFiles(x86)%")" /F REG delete "HKLM\Software\Classes\Directory\shell\TakeOwnership" /v "Extended" /f REG add "HKLM\Software\Classes\Directory\shell\TakeOwnership" /v "HasLUAShield" /t REG_SZ /d "" /f REG add "HKLM\Software\Classes\Directory\shell\TakeOwnership" /v "NoWorkingDirectory" /t REG_SZ /d "" /f REG add "HKLM\Software\Classes\Directory\shell\TakeOwnership" /v "Position" /t REG_SZ /d "%Position%" /f REG add "HKLM\Software\Classes\Directory\shell\TakeOwnership\command" /ve /t REG_SZ /d "powershell -windowstyle hidden -command "Start-Process cmd -ArgumentList '/c %PauseBeforePS% takeown /f "%%1" /r /d %Yes% ^&^& icacls "%%1" /grant *S-1-3-4:F /t /c /l /q%PauseAfterPS%' -Verb runAs"" /f REG add "HKLM\Software\Classes\Directory\shell\TakeOwnership\command" /v "IsolatedCommand" /t REG_SZ /d "powershell -windowstyle hidden -command "Start-Process cmd -ArgumentList '/c %PauseBeforePS% takeown /f "%%1" /r /d %Yes% ^&^& icacls "%%1" /grant *S-1-3-4:F /t /c /l /q%PauseAfterPS%' -Verb runAs"" /f REG add "HKLM\Software\Classes\Drive\shell\runas" /ve /t REG_SZ /d "%TO-label%" /f REG delete "HKLM\Software\Classes\Drive\shell\runas" /v "Extended" /f REG add "HKLM\Software\Classes\Drive\shell\runas" /v "HasLUAShield" /t REG_SZ /d "" /f REG add "HKLM\Software\Classes\Drive\shell\runas" /v "NoWorkingDirectory" /t REG_SZ /d "" /f REG add "HKLM\Software\Classes\Drive\shell\runas" /v "Position" /t REG_SZ /d "%Position%" /f REG add "HKLM\Software\Classes\Drive\shell\runas" /v "AppliesTo" /t REG_SZ /d "NOT (System.ItemPathDisplay:="%SystemDrive%")" /f REG add "HKLM\Software\Classes\Drive\shell\runas\command" /ve /t REG_SZ /d "cmd.exe /c %PauseBefore% takeown /f "%%1" /r /d %Yes% && icacls "%%1" /grant *S-1-3-4:F /t /c%PauseAfter%" /f REG add "HKLM\Software\Classes\Drive\shell\runas\command" /v "IsolatedCommand" /t REG_SZ /d "cmd.exe /c %PauseBefore% takeown /f "%%1" /r /d %Yes% && icacls "%%1" /grant *S-1-3-4:F /t /c%PauseAfter%" /f EXIT /B 0
I just realized that the script I posted recently probably won't work properly on 32-bit Windows, because there's no Program Files (x86) directory and no environment variable pointing to it. To allow my script to work on both 64-bit and 32-bit Windows, replace the line that beginswith the following 2 lines:Code:REG ADD "HKLM\SOFTWARE\Classes\Directory\shell\TakeOwnership" /V "AppliesTo"
I've tested this on my 64-bit computers and it works properly. I don't currently have a 32-bit Win10 system to test it on, but it looks like it should work. I recommend you test it yourself before putting it into production.Code:IF /I "%PROCESSOR_ARCHITECTURE%" NEQ "x86" (SET PF86= OR System.ItemPathDisplay:=\"%ProgramFiles(x86)%\") ELSE (SET PF86=) REG ADD "HKLM\SOFTWARE\Classes\Directory\shell\TakeOwnership" /V "AppliesTo" /T REG_SZ /D "NOT (System.ItemPathDisplay:=\"%ProfPath%\\\" OR System.ItemPathDisplay:=\"%ProgramData%\" OR System.ItemPathDisplay:=\"%SystemRoot%\" OR System.ItemPathDisplay:=\"%SystemRoot%\\System32\" OR System.ItemPathDisplay:=\"%ProgramFiles%\"%PF86%)" /F
Note: the "ELSE" part of the IF command may seem redundant, but I believe in defensive programming - many times I've had to fix programs that didn't work right because the previous programmer assumed a variable was empty, blank or zero, and it wasn't!
This is so so so useful for me right now and is just perfect.
registered this account just to say thank you, blessings to you and yours!
I'm looking at an anomaly I've never seen or heard of using Take Ownership. I am trying to open/copy/save files from an old hard drive which was running MS Vista. The drive looks normal and healthy, nothing obviously amiss, via USB adapter. On two different systems both of which are running Win 10 ver 1909 build 18363, when I take ownership of the Documents & Settings folder, the User Account name for the 'host' is copied over to the USB device/drive in the folder 'owned'. Thus, the original User Account name of the user under Vista is not present, but instead is a user profile with the name of the host system [the windows 10 mule I'm using to fetch the files]. Looking into that folder there's little there - the old files are not apparent - unseen.
It gets worse: on the C drive [the main boot volume of the windows 10 'host'] there is a new folder called "Documents & Settings" that is locked/protected... I am completely baffled. I don't quite know what to do... I'll treat the old drive from this point forward as one with lost/damaged files and use forensic tools to recover them, which I hope is not difficult, but I don't know what corruption has occurred to my 2 good mules!! yikes
help? Ideas?
You are not supposed to take ownership of documents and settings:
Stop Application Data folder replicating? Solved - Page 8 - Windows 7 Help Forums
Instead you navigate to C:\Users\{user name}\Documents and copy files from there.
Taking ownership can sometimes cause issues of it's own, normally when the developer of software have used ownership to make a function work rather than change the actual access rights. as only one user can take ownership at any time this can cause the issues when a second users "steals" the ownership.
I would suggest that where possible you always assign rights correctly using the standard procedure
I would personally only take ownership of data drives, but even these I would use the following method when not in a rush
Right click on a folder and choose the security tab
Select edit
Select your own user name, (or the administrators group if you use multiple administrators)
Assign the Full Control right for your user to to the folder.
By default this right should be automatically cascaded down the folder structure (and the included files), if not there is a tick box you can check to ensure this.
As this method does not change the default folder ownership rights there is much less chance of any rights issues in future
users/name was protected of course.
I got there another way.
still baffled as to the mechanism at work however - for edification would love an explanation.
to reiterate, upon what appeared to be a Successful 'take ownership', -
- a new folder containing copies of my existing "users" [not the target drive, but the drive of the windows 10 device used for the work] was created under the heading of c:/"Documents and Settings". It contained nothing from the target except the name of the folder
- a new set of users appeared under the Target [in this case I think it was E:/], which were from the windows 10 'mule'...
- no files visible... in other words, nothing from the target drive appeared to be in the Documents Settings folder of the E: [target] drive.
exactly that was produced twice, 2 different windows 10 pc's
but, no apparent harm done.... I just deleted the new folder of the 2 pc's and everything ok.
the files were intact on the target drive - no harm that I can find though it did require some file system repairs
thank you both
Just an observation.
In the Add_Take_Ownership_To_Context_Menu file [FIRST POST], at the top there are two lines to remove the Key first . . .
Code:[-HKEY_CLASSES_ROOT\*\shell\TakeOwnership] [-HKEY_CLASSES_ROOT\*\shell\runas]
. . . although there are only . . .
Code:[HKEY_CLASSES_ROOT\*\shell\runas] [HKEY_CLASSES_ROOT\Directory\shell\TakeOwnership] [HKEY_CLASSES_ROOT\Drive\shell\runas]
Does this mean that there is one missing or [HKEY_CLASSES_ROOT\*\shell\TakeOwnership] is wrongly entered?
Thanks in advance.