powershell - 在PowerShell中将文件复制到需要管理员权限的文件夹
问题描述
我想c:\windows\system32\drivers\etc
通过 powershell 脚本将主机文件复制到,但是当我这样做时,出现以下错误。如何在不显示密码的情况下以管理员身份运行此命令?
我收到的错误:
copy : Access to the path 'C:\Windows\System32\drivers\etc\hosts' is denied.
At line:1 char:1
+ copy z:\hosts C:\Windows\System32\drivers\etc
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (Z:\hosts:FileInfo) [Copy-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : CopyFileInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand
我运行的命令:
copy z:\hosts C:\Windows\System32\drivers\etc
解决方案
If you have administrator permissions, then you start PowerShell as administrator, or you can run the script as an administrator by adding,
Start-Process powershell -Verb runAs
推荐阅读
- python-3.x - 为什么这个递归 Python 函数将反转的对象作为列表返回?
- css - Bootstrap 4 复选框未正确对齐
- python - Flask Sqlalchemy 模型通过调用 model.__dict__ 返回不同的结果(有时显示反向引用,有时不显示)
- javascript - 如何在 angularjs 的工具提示中显示 ng-messages?
- php - 尽管使用了 try/catch 块,为什么 PHP 会抛出致命错误并破坏 HTTP 500?
- postgresql - 使用 Springboot/JPA 的外键实体关系
- java - 将 openssl 摘要签名语句转换为 Java 代码
- c# - 在 CodeObjectCreateExpression 中分配对象的属性值
- mysql - 如何以无序的方式比较 SQL 查询中的字段(可能是数组)?
- php - Laravel - 格式错误的 UTF-8 字符,可能编码不正确