How to run a script as administrator and copy some setting of the connected user's profile?

I want to copy some profile setting to the connected on folder (% userprofile%\AppData\Roaming\Microsoft\Word) user profile password when they connect. Because the standard user accounts do not have the right admin to copy files to the folder, so I use schedule a task to run the .cmd as local administrator every time that a user login. But, when I use the % username % setting to try copying the file to the logged on user profile, the setting of % username % is interpreted as the name of the local administrator because the scheduled task is run as administrator. Therefore, the file is exemplary in the local Administrator profile. All solutions? Thank you

I log on as a user account standard and do a right-click the .cmd and run as admin. The script interpreter .cmd parameter of % username % as the admin because I ran as administrator.

-> Not altogether. There are two cases:

  • You are connected under an administrator account. When you right click on cmd.exe, then you get a 'high' console session that is still running under the name of your current account.
  • You are connected under a regular account. When you right click on cmd.exe and then you get a prompt and admin account name and its password. The new session is running under admin account.

Is there a way to set the parameter to % username % as long as the logged on user, when you run the .cmd as an administrator.

-> No - see above. Execution of a session high under a regular user account would defy the principle of administrator accounts.

Either of these two options, I gave you in my previous answer might work, with a bit of scripting. A much simpler method would be to restore the default permissions to the %userprofile%\AppData\Roaming\Microsoft\Word folder. Normally full, users have access to it. This is my preferred option. With the help of a scheduled task that is running under an administrator account is a kludge.

Tags: Windows

Similar Questions

Maybe you are looking for