我可以问Windows执行操作需要什么权限吗?

我可以问Windows执行操作需要什么权限吗?,windows,user-interface,cmd,administration,Windows,User Interface,Cmd,Administration,有没有一种方式可以说“我要发出一些命令,如果它们无法运行,请找出原因并修复它。”理想情况下,它会给我一个简单的Y/N选项来修复它(一次或永远)。或者一些覆盖,比如“以管理员身份运行”应该如何工作,只是跳过所有权限检查?还是关闭权限检查的方法 大概是这样的: C:>删除打印机GHI 无法删除打印机WXY,因为1)您没有权限XYZ,2)您不是组WXY的成员,3)GHI打印机队列中有4394568个未打印的作业,4)您没有ABC进行DEF,5)您的JKL设置为MNO 是否希望Windows授予您XYZ

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

大概是这样的:

C:>删除打印机GHI

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

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

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

用户名:GHI/管理员

密码:密码

打印机GHI已被删除。祝你今天愉快


C:>

要获得Bash中的历史记录和命令行编辑功能,请查看模块。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

我不想为这件事大肆宣扬。不知道我是否有耐心@这是一个伟大的链接。一切都是主观的。PowerShell可以是一个强大的工具。就像任何事情一样,如果你知道怎么做,你几乎可以让它做任何事情。它确实试图帮助人们更好地从CMD过渡。你不能一上车就指望它能工作。你需要知道如何驾驶她。你的问题是什么?PowerShell根本不像bash或cmd。它更像python或perl——也就是说,它是Windows的解释PL。PS4.0有一些令人印象深刻的cmdlet。PS5.0将允许您编写自己的类(无需添加类型)。再加上工作流程以及用于广告和Exchange的模块。我不确定你期望的是什么,但PS是自NT内核以来Windows上发生的最好的事情。哈,布莱恩,我想我已经问过了,但我在底部提出了一个更明确的问题。我想它确实变成了咆哮。仍然太痛苦了,但还是接受了。非常感谢。