0

I wrote a little program to automate:

  1. Taking own of a file/folder for a specified User.
  2. Get (for the same User) FULL CONTROL of the file/folder.

Now, it is well know that takeown.exe wants cmd.exe to be run as Administrator rights. So, to do in a batch file (most of the time called from a non-Administrator cmd window), I run:

call runas /noprofile /user:"!domain!\!runasUsr!" "cmd /k takeown /f ""!entity!"" /r"

However, even though I pass as !runAsUsr! a name which is contained in the Administrators Group, I get:

ERROR: the user currently connected does not have the ownership privileges on file/folder ...

I tried setting !runAsUsr! = Administrators, but unfortunately I do not remember the password (if I even set one...). For that, I could change from computer manager (or net command), but I do not well know how that command works, so I wouldn't mess things up.

But still, I do not understand why I get that error since the User I pass is within the Administrators group..

I see from computer manager that default account for computer administration is User:Administrator of the Group:Administrators, so this might be the problem. So, how to set the other account to have same rights?

I also tried

call runas /noprofile /user:"!domain!\Administrator" "cmd /k takeown /f ""!entity!"" /r"

getting following error:

ERROR RUNAS: impossible to execute - cmd /k takeown /f "C:\Program Files\Microsoft VS Code\resources\app\extensions\css" /r
1327: restriction on user account do not allow this user to get access. 
For example, empty password field not allowed, access times restrictions or application of restriction criteria.
mEm
  • 353
  • 3
  • 12
  • `runas` does as it says. But as there is no interactive user there is no-one to right click and choose Run As Administrator. – user14797724 Feb 05 '21 at 08:07
  • Well, there are many question on this topic, from which you can assert that `runas` is used within a batch file to launch (within another cmd window) another `command` with possibly elevated privileges. Also, what was not visible to you, this new cmd (*where I have the error messages*) appears, and the root folder is exactly "**C:\Windows\System32**" which is the one you're in when launching `cmd.exe` as Administrator.. – mEm Feb 05 '21 at 08:13
  • Why doesn't your command work then? – user14797724 Feb 05 '21 at 08:25
  • If I had the answer maybe I wouldn't post the question here on SO, don't you think? :) – mEm Feb 05 '21 at 08:27
  • And takeown works for all users that have permission to take ownership. – user14797724 Feb 05 '21 at 08:30
  • If I run `takeown` from a `cmd` opened as Administrator, then it works fine. I try then, as you see in the question, to `runas Administrator` the command `takeown` and I get what you read. Maybe I was not clear enough, but did you get exactly what I am asking? – mEm Feb 05 '21 at 08:35
  • No I didn't as you can't elevate via runas. – user14797724 Feb 05 '21 at 08:37
  • So based on this, it is not possible to run `takeown` from a *normal* batch file. Is it? – mEm Feb 05 '21 at 08:38
  • Yes but but not with admin powers. Use Task Scheduler. – user14797724 Feb 05 '21 at 08:40
  • PS administration is http://serverfault.com and home computers http://superuser.com. – user14797724 Feb 05 '21 at 08:43
  • Also takeown takes user info. See takeown /?. – user14797724 Feb 05 '21 at 08:44

0 Answers0