【问题标题】:Can I ask Windows what permissions I need to perform an action? [closed]我可以询问 Windows 执行操作需要哪些权限吗? [关闭]
【发布时间】:2015-01-04 19:43:25
【问题描述】:

有没有办法说“我即将发出一些命令,如果它们无法运行,请找出原因并修复它。”理想情况下,它会给我一个简单的 Y/N 选项来修复它(一次或永远)。或者一些覆盖,比如以管理员身份运行应该如何工作,只是跳过所有权限检查?或者关闭权限检查的方法?

类似这样的:

C:> 删除打印机 GHI

您无法删除打印机 WXY,因为 1) 您没有权限 XYZ,2) 您不是 WXY 组的成员,3) GHI 打印机的队列中有 4394568 个未打印作业,以及4) 你没有 ABC 做 DEF 和 5) 你的 JKL 设置为 MNO。

您是否希望 Windows 授予您 XYZ 权限,将您添加到组 WXY 的成员资格,并让您 ABC 执行 DEF,将您的 JKL 设置为 PQR 并删除 4,394,568 个未打印的作业,并删除打印机 GHI? [O/Y/N](仅 [O] 次,[Y] 永久,[N]o)?是的

提供域 GHI 的管理员用户名和密码。

用户名:GHI/管理员

密码:密码

打印机 GHI 已被删除。祝你有美好的一天。

C:>

【问题讨论】:

  • 我不想为此写一大堆咆哮。不确定我是否有耐心。 @HyperAnthony 这是一个很好的链接。一切都是主观的。 PowerShell 可以是一个强大的工具。就像任何事情一样,如果您知道如何使用它,您几乎可以让它做任何事情。它确实试图帮助人们很好地从 CMD 过渡。你不能坐进车里就指望它能工作。你需要知道如何驾驶她。
  • 你的问题是什么?
  • PowerShell 根本不像 bash 或 cmd。它更像是 python 或 perl - 即它是用于 Windows 的解释型 PL。 PS 4.0 有一些非常令人印象深刻的 cmdlet。 PS 5.0 将让您编写自己的类(无需添加类型)。加上工作流以及 AD 和 Exchange 模块等内容。我不确定你的预期,但 PS 是自 NT 内核以来 Windows 发生的最好的事情。
  • Ha Bryan,我以为我已经问过了,但我在底部提出了一个更明确的问题。我猜它确实变成了咆哮。

标签: windows user-interface cmd administration


【解决方案1】:

要获得 Bash 中的历史记录和命令行编辑功能,请查看 PSReadline 模块。 PowerShell 已经有相当不错的制表符补全功能,但 PSReadline 让它变得更好。

顺便说一句,PowerShell 与其说是使用 API,不如说是使用对象。管理打印机非常简单:

8> Get-Printer

Name                           ComputerName    Type         DriverName                PortName        Shared   Publishe
                                                                                                               d
----                           ------------    ----         ----------                --------        ------   --------
Send To OneNote 2013                           Local        Send to Microsoft OneN... NUL:            False    False
Quicken PDF Printer                            Local        Amyuni Document Conver... NUL:            False    False
Microsoft XPS Document Writer                  Local        Microsoft XPS Document... PORTPROMPT:     False    False
HP Photosmart 7520                             Local        HP Photosmart 7520 ser... 192.168.1.127_1 False    False
hp LaserJet 1300 PCL 5                         Local        hp LaserJet 1300 PCL 5    DOT4_001        True     False
Fax                                            Local        Microsoft Shared Fax D... SHRFAX:         False    False

9> Remove-Printer 'Microsoft XPS Document Writer'
Remove-Printer : Access was denied to the specified resource.
At line:1 char:1
+ Remove-Printer 'Microsoft XPS Document Writer'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (MSFT_Printer (N...= "", Type = 0):ROOT/StandardCimv2/MSFT_Printer) [R
   emove-Printer], CimException
    + FullyQualifiedErrorId : HRESULT 0x80070005,Remove-Printer

关于有更多有用的错误消息的公平点。这是产品一直在改进的地方,例如:

10> Invoke-Command -ComputerName . {Get-Service spooler}
[localhost] Connecting to remote server localhost failed with the following error message : The client cannot connect
to the destination specified in the request. Verify that the service on the destination is running and is accepting
requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly
IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and
configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help
topic.
    + CategoryInfo          : OpenError: (localhost:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken

【讨论】:

  • 还是很痛苦,但接受了。谢谢。
猜你喜欢
  • 2012-03-11
  • 2020-05-03
  • 2019-08-23
  • 2012-04-24
  • 1970-01-01
  • 1970-01-01
  • 2014-08-28
  • 1970-01-01
  • 2019-06-24
相关资源
最近更新 更多