$ ENV:USERNAME返回计算机名,当SCCM运行脚本作为管理员与非管理员登录 [英] $ENV:USERNAME returns the machine name when SCCM runs a script as admin with a non-admin logged in

查看:700
本文介绍了$ ENV:USERNAME返回计算机名,当SCCM运行脚本作为管理员与非管理员登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



需要将应用程序数据复制到 $ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆