如何以编程方式以管理员权限运行批处理脚本?

时间:2019-01-04 01:27:38

标签: batch-file

如何以管理员权限运行批处理脚本,而不是右键单击该脚本并以编程方式单击“以管理员身份运行”?

由于右键单击会浪费时间来计算菜单,因此,我更喜欢使用具有管理员权限的批处理脚本来运行的更快方法。

2 个答案:

答案 0 :(得分:1)

您可以使用vbs完成此操作。您需要做的就是将以下代码添加到批处理脚本的开头:


~ceph -s 
cluster:
id:     XXXXXXXXXXXXXXXX
health: HEALTH_ERR
        3 pools have many more objects per pg than average
        358887/12390692 objects misplaced (2.896%)
        2 scrub errors
        9677 PGs pending on creation
        Reduced data availability: 7125 pgs inactive, 6185 pgs down, 2 pgs peering, 2709 pgs stale
        Possible data damage: 2 pgs inconsistent
        Degraded data redundancy: 193505/12390692 objects degraded (1.562%), 351 pgs degraded, 1303 pgs undersized
        53882 slow requests are blocked > 32 sec
        4082 stuck requests are blocked > 4096 sec
        too many PGs per OSD (2969 > max 200)
services:
mon: 3 daemons, quorum ceph-mon01,ceph-mon02,ceph-mon03
mgr: ceph-mon03(active), standbys: ceph-mon01, ceph-mon02
osd: 39 osds: 36 up, 36 in; 51 remapped pgs
rgw: 1 daemon active
data:
pools:   18 pools, 54656 pgs
objects: 6050k objects, 10940 GB
usage:   21721 GB used, 45314 GB / 67035 GB avail
pgs:     13.036% pgs not active
            193505/12390692 objects degraded (1.562%)
            358887/12390692 objects misplaced (2.896%)
            46177 active+clean
            5070  down
            1114  stale+down
            1088  stale+active+undersized
            547   activating
            201   stale+active+undersized+degraded
            173   stale+activating
            96    activating+degraded
            61    stale+active+clean
            43    activating+remapped
            39    stale+activating+degraded
            24    stale+activating+remapped
            9     activating+undersized+degraded+remapped
            4     stale+activating+undersized+degraded+remapped
            2     active+clean+inconsistent
            1     stale+activating+degraded+remapped
            1     stale+remapped+peering
            1     active+undersized
            1     stale+peering
            1     stale+active+clean+remapped
            1     down+remapped
            1     stale+remapped
            1     activating+degraded+remapped
io:
client:   967 kB/s rd, 1225 kB/s wr, 29 op/s rd, 30 op/s wr

希望对您有帮助。

答案 1 :(得分:0)

您要查找的命令是runas-这使您可以以与当前用户不同的用户身份运行程序。

我不确定是否允许您编写密码脚本,但可以从内存中缓存凭据以供以后使用。

要编写密码脚本,需要使用psexec之类的工具(由Microsoft的PsTools套件组成)。您应该能够执行以下操作:

psexec \\127.0.0.1 -u Administrator -p <admin-password> xyzzy

以管理员身份运行xyzzy命令。

我通常无法测试,因为我们的公司保护软件阻止了psexec程序的创建,因为该程序被用于攻击媒介。但是,我在隔离的测试台区域发现了一台计算机,该计算机可以正常运行:

C:\> psexec \\172.16.1.100 -u Administrator -p NeverYouMind ipconfig
PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

Windows IP Configuration
Ethernet adapter Local Area Connection:
   Connection-specific DNS Suffix  . :
   IPv4 Address. . . . . . . . . . . : 172.16.1.100
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 172.16.1.1
ipconfig exited on 172.16.1.100 with error code 0.