python访问组策略_如何用python或系统命令查看windows的组策略中的设置

匿名用户

1级

2018-11-22 回答

这种情况是使用的方法不正确导致的。

Python中执行系统命令常见的几种方法如下:

1、os.system

例如:

>>> import os >>> os.system('ls') chk_err_log.py CmdTool.log install_log.txt install_zabbix.sh manage_deploy.sh MegaSAS.log

2、os.popen

例如:

>>> import os >>>tmp = os.popen('ls *.sh').readlines() >>>tmp ['install_zabbix.sh\n', 'manage_deploy.sh\n', 'mysql_setup.sh\n', 'python_manage_deploy.sh\n', 'setup.sh\n']

3、使用模块subprocess

使用方法:

>>> import subprocess >>> subprocess.call (["cmd", "arg1", "arg2"],shell=True)

import subprocess p = subprocess.Popen('ls *.sh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) print p.stdout.readlines() for l

可以使用Python的`subprocess`模块来调用命令行工具来实现禁用命令提示符的功能。具体步骤如下: 1. 使用`subprocess.Popen`函数调用命令行工具`gpedit.msc`来打开本地组策略编辑器: ```python import subprocess subprocess.Popen('gpedit.msc') ``` 2. 通过键盘模拟的方式,按下`Win+R`组合键打开运行窗口,输入`gpedit.msc`并回车打开本地组策略编辑器: ```python import subprocess import time import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.SendKeys("{LWIN}") time.sleep(0.5) shell.SendKeys("r") time.sleep(0.5) shell.SendKeys("gpedit.msc") time.sleep(0.5) shell.SendKeys("{ENTER}") ``` 3. 在本地组策略编辑器找到`用户配置` -> `管理模板` -> `系统` -> `阻止访问命令提示符`,并将其配置为`已禁用`。 ```python import subprocess import time import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.SendKeys("{LWIN}") time.sleep(0.5) shell.SendKeys("r") time.sleep(0.5) shell.SendKeys("gpedit.msc") time.sleep(0.5) shell.SendKeys("{ENTER}") time.sleep(2) shell.SendKeys("{TAB}") time.sleep(0.5) shell.SendKeys("{TAB}") time.sleep(0.5) shell.SendKeys("{DOWN}") time.sleep(0.5) shell.SendKeys("{DOWN}") time.sleep(0.5) shell.SendKeys("{DOWN}") time.sleep(0.5) shell.SendKeys("{DOWN}") time.sleep(0.5) shell.SendKeys("{ENTER}") time.sleep(0.5) shell.SendKeys("{TAB}") time.sleep(0.5) shell.SendKeys("{TAB}") time.sleep(0.5) shell.SendKeys("{TAB}") time.sleep(0.5) shell.SendKeys("{SPACE}") time.sleep(0.5) shell.SendKeys("{ENTER}") ``` 4. 关闭本地组策略编辑器。 ```python import subprocess import time import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.SendKeys("{LWIN}") time.sleep(0.5) shell.SendKeys("r") time.sleep(0.5) shell.SendKeys("gpedit.msc") time.sleep(0.5) shell.SendKeys("{ENTER}") time.sleep(2) shell.SendKeys("{TAB}") time.sleep(0.5) shell.SendKeys("{TAB}") time.sleep(0.5) shell.SendKeys("{DOWN}") time.sleep(0.5) shell.SendKeys("{DOWN}") time.sleep(0.5) shell.SendKeys("{DOWN}") time.sleep(0.5) shell.SendKeys("{DOWN}") time.sleep(0.5) shell.SendKeys("{ENTER}") time.sleep(0.5) shell.SendKeys("{TAB}") time.sleep(0.5) shell.SendKeys("{TAB}") time.sleep(0.5) shell.SendKeys("{TAB}") time.sleep(0.5) shell.SendKeys("{SPACE}") time.sleep(0.5) shell.SendKeys("{ENTER}") time.sleep(2) shell.SendKeys("%{F4}") ``` 以上是基于键盘模拟的方式来操作本地组策略编辑器,也可以使用Windows API来实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值