$ ENV:USERNAME返回计算机名,当SCCM运行脚本作为管理员与非管理员登录 [英] $ENV:USERNAME returns the machine name when SCCM runs a script as admin with a non-admin logged in
问题描述
需要将应用程序数据复制到 $ ENV:USERNAME\AppData\< dir> \ *
(除其他外),需要以管理员身份运行。
我发现的问题是,当脚本在具有管理员权限的非管理员配置文件上运行时,环境变量 $ ENV:USERNAME
返回机器名称而不是实际登录的用户名。
有没有办法?
您可以使用([Security.Principal.WindowsIdentity] :: GetCurrent())。名称
或从注册表获取配置文件路径:
HKEY_CURRENT_USER\Volatile Environment\APPDATA
HKEY_CURRENT_USER\Volatile Environment\LOCALAPPDATA
HKEY_CURRENT_USER\\ \\ Volatile Environment\USERPROFILE
选择你的武器:)
I have a script that needs to run from Software Center when a non-admin is logged in.
It needs to copy application data to $ENV:USERNAME\AppData\<dir>\*
(among other things) and it needs to run as administrator to work properly.
The problem that I've discovered is that when the script is run on a non-admin profile with admin privileges the environment variable $ENV:USERNAME
returns the machine name rather than the actual logged in username.
Is there a way around this?
You can either use ([Security.Principal.WindowsIdentity]::GetCurrent()).Name
or you get the profile path from the registry :
HKEY_CURRENT_USER\Volatile Environment\APPDATA
HKEY_CURRENT_USER\Volatile Environment\LOCALAPPDATA
HKEY_CURRENT_USER\Volatile Environment\USERPROFILE
Choose your weapon :)
这篇关于$ ENV:USERNAME返回计算机名,当SCCM运行脚本作为管理员与非管理员登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!