收集一些Python操作windows的代码 (不管是自带的or第三方库)均来自网上

1.shutdown 操作

定时关机、重启、注销

#!/usr/bin/python
#-*-coding:utf-8-*-
#shutdown.py import sys#导入
import os from PyQt4.QtCore import *
from PyQt4.QtGui import * class ShutDown(QWidget):
def __init__(self):
super(ShutDown, self).__init__()
self.setWindowTitle('PyQt')
self.hourLabel = QLabel(u'小时')#标签
self.minuteLabel = QLabel(u'分钟')
self.secondLabel = QLabel(u'秒') self.shutDownButton = QPushButton()#按钮
self.shutDownButton.setText(u'关机')
self.shutDownButton.clicked.connect(self.confirm_shutdown)
self.rebootButton = QPushButton()
self.rebootButton.setText(u'重启')
self.rebootButton.clicked.connect(self.confirm_reboot)
self.logoffButton = QPushButton()
self.logoffButton.setText(u'注销')
self.logoffButton.clicked.connect(self.confirm_logoff) self.hourSpinBox = QSpinBox()
self.hourSpinBox.setRange(0,1000)
self.hourSpinBox.setSingleStep(1)
self.hourSpinBox.setValue(0)
self.minuteSpinBox = QSpinBox()
self.minuteSpinBox.setRange(0,1000)
self.minuteSpinBox.setSingleStep(1)
self.minuteSpinBox.setValue(0)
self.secondSpinBox = QSpinBox()
self.secondSpinBox.setRange(0,1000)
self.secondSpinBox.setSingleStep(1)
self.secondSpinBox.setValue(0) self.layout = QGridLayout()#网格布局
self.layout.addWidget(self.hourLabel,1,0)
self.layout.addWidget(self.hourSpinBox,1,1)
self.layout.addWidget(self.minuteLabel,1,2)
self.layout.addWidget(self.minuteSpinBox,1,3)
self.layout.addWidget(self.secondLabel,1,4)
self.layout.addWidget(self.secondSpinBox,1,5)
self.layout.addWidget(self.shutDownButton,2,0,2,2)
self.layout.addWidget(self.rebootButton,2,2,2,2)
self.layout.addWidget(self.logoffButton,2,4,2,2)
self.setLayout(self.layout) def confirm_shutdown(self):
self.time = (self.hourSpinBox.value() * 3600 + self.minuteSpinBox.value() * 60
+ self.secondSpinBox.value())
shutdown = 'C:\Windows\System32\shutdown.exe -s -t ' + str(self.time)
os.system(shutdown)
sys.exit(0) def confirm_reboot(self):
reboot = 'C:\Windows\System32\shutdown.exe -r'
os.system(reboot)
sys.exit(0) def confirm_logoff(self):
logoff = 'C:\Windows\System32\shutdown.exe -l'
os.system(logoff)
sys.exit(0) if __name__ == '__main__':
app = QApplication(sys.argv)
shutdown = ShutDown()
shutdown.show()
sys.exit(app.exec_())

2.windows锁屏

相当与WIN+L 操作

 # -*- coding: utf-8 -*-
# python在windows锁屏的代码
import sys
from ctypes import *
from PyQt4 import QtGui, QtCore
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s class QuitButton(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle(_fromUtf8('windows锁屏')) #utf8 输出中文
lockscreen = QtGui.QPushButton('OK', self)
lockscreen.setGeometry(10, 10, 60, 35)
QtCore.QObject.connect(lockscreen, QtCore.SIGNAL('clicked()'), self.win_L) #self.win_L 点击执行
def win_L(self):
user32 = windll.LoadLibrary('user32.dll')
user32.LockWorkStation() class lockScr(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
def win_L(self):
user32 = windll.LoadLibrary('user32.dll')
user32.LockWorkStation() app = QtGui.QApplication(sys.argv)
qb = QuitButton()
qb.show()
sys.exit(app.exec_())

3.获取电脑的基本信息

引用第三方库WMI 可以查看到 windows当前的版本、位数X86(64)、进程数目、CPU类型和使用率、硬盘的分区和使用率、Ip地址和Mac地址、 详细进程数据等

 #!/usr/bin/env python
# -*- coding: utf-8 -*- import wmi
import os
import sys
import platform
import time
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
def sys_version():
c = wmi.WMI ()
#获取操作系统版本
for sys in c.Win32_OperatingSystem():
print u"Version:%s" % sys.Caption,"Vernum:%s" % sys.BuildNumber
print sys.OSArchitecture#系统是32位还是64位的
print sys.NumberOfProcesses #当前系统运行的进程总数 def cpu_mem():
c = wmi.WMI ()
#CPU类型和内存
for processor in c.Win32_Processor():
#print "Processor ID: %s" % processor.DeviceID
print "Process Name: %s" % processor.Name.strip()
for Memory in c.Win32_PhysicalMemory():
print "Memory Capacity: %.fMB" %(int(Memory.Capacity)/1048576) def cpu_use():
#5s取一次CPU的使用率
c = wmi.WMI()
while True:
for cpu in c.Win32_Processor():
timestamp = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
print '%s | Utilization: %s: %d %%' % (timestamp, cpu.DeviceID, cpu.LoadPercentage)
time.sleep(5)
break def disk():
c = wmi.WMI ()
#获取硬盘分区
for physical_disk in c.Win32_DiskDrive ():
for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"):
for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"):
print physical_disk.Caption, partition.Caption, logical_disk.Caption #获取硬盘使用百分情况
for disk in c.Win32_LogicalDisk (DriveType=3):
print disk.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size)) def network():
c = wmi.WMI ()
#获取MAC和IP地址
for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1):
print "MAC: %s" % interface.MACAddress
for ip_address in interface.IPAddress:
print "ip_add: %s" % ip_address
print #获取自启动程序的位置
for s in c.Win32_StartupCommand ():
print "[%s] %s <%s>" % (s.Location, s.Caption, s.Command) #获取当前运行的进程
for process in c.Win32_Process ():
print process.ProcessId, process.Name def main():
sys_version()
cpu_mem()
disk()
network()
#cpu_use() if __name__ == '__main__':
main()
print platform.system()
print platform.release()
print platform.version()
print platform.platform()
print platform.machine()

关于Python 获取windows信息收集的更多相关文章

  1. python获取windows信息

    转载自http://www.blog.pythonlibrary.org/2010/02/06/more-windows-system-information-with-python/ How to ...

  2. 用python获取服务器硬件信息[转]

    #!/usr/bin/env python # -*- coding: utf-8 -*- import rlcompleter, readline readline.parse_and_bind(' ...

  3. 用python获取ip信息

    1.138网站 http://user.ip138.com/ip/首次注册后赠送1000次请求,API接口请求格式如下,必须要有token值 import httplib2 from urllib.p ...

  4. 内网渗透----windows信息收集整理

    一.基础信息收集 1.信息收集类型 操作系统版本.内核.架构 是否在虚拟化环境中,已安装的程序.补丁 网络配置及连接 防火墙设置 用户信息.历史纪录(浏览器.登陆密码) 共享信息.敏感文件.缓存信息. ...

  5. 利用python 获取 windows 组策略

    工作中有时候会有这种需求: 1. 自动配置组策略的安全基线,这个东西不用你自己写了,微软有这个工具,Microsoft Security Compliance Manager,你可以在下面的地址去下载 ...

  6. python 获取对象信息

    当我们拿到一个对象的引用时,如何知道这个对象是什么类型.有哪些方法呢? 使用type() 首先,我们来判断对象类型,使用type()函数: 基本类型都可以用type()判断: >>> ...

  7. python写一个信息收集四大件的脚本

    0x0前言: 带来一首小歌: 之前看了小迪老师讲的课,仔细做了些笔记 然后打算将其写成一个脚本. 0x01准备: requests模块 socket模块 optparser模块 time模块 0x02 ...

  8. Python 获取车票信息

    提示:该代码仅供学习使用,切勿滥用!!! 先来一个git地址:https://gitee.com/wang_li/li_wang 效果图: 逻辑: 1.获取Json文件的内容 2.根据信息生成URL ...

  9. python获取对象信息

    获取对象信息 拿到一个变量,除了用 isinstance() 判断它是否是某种类型的实例外,还有没有别的方法获取到更多的信息呢? 例如,已有定义: class Person(object): def ...

随机推荐

  1. r-cnn学习(一)

    http://closure11.com/rcnn-fast-rcnn-faster-rcnn%E7%9A%84%E4%B8%80%E4%BA%9B%E4%BA%8B/ 首先看fast r-cnn这篇 ...

  2. 如何给ZenCart网站livezilla客服系统?

    大致步骤: 1 去官网下载livezilla

  3. ubuntu14.04 server安装gnome-desktop

    You can install the default Ubuntu desktop by executing the following: sudo apt-get install ubuntu-d ...

  4. rabbitmq使用

    1. 用户管理 用户管理包括增加用户,删除用户,查看用户列表,修改用户密码. 相应的命令 (1) 新增一个用户 rabbitmqctl  add_user  Username  Password (2 ...

  5. 【GoLang】panic defer recover 深入理解

    唉,只能说C程序员可以接受go的错误设计,相比java来说这个设计真的很差劲! 我认为知乎上说的比较中肯的: 1. The key lesson, however, is that errors ar ...

  6. We will be discontinuing the Nitrous Development Platform and Cloud IDE on November 14th, 2016.

    我表示我很难过 Nitrous We will be discontinuing the Nitrous Development Platform and Cloud IDE on November ...

  7. 解读Unity中的CG编写Shader系列一

    转自http://www.itnose.net/detail/6095323.html 前提知识点: 1.CG代码必须用 CGPROGRAM ... ENDCG括起来 2.顶点着色器与片段着色器的主函 ...

  8. 算法手记 之 数据结构(堆)(POJ 2051)

    一篇读书笔记 书籍简评:<ACM/ICPC 算法训练教程>这本书是余立功主编的,代码来自南京理工大学ACM集训队代码库,所以小编看过之后发现确实很实用,适合集训的时候刷题啊~~,当时是听了 ...

  9. Java for LeetCode 211 Add and Search Word - Data structure design

    Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...

  10. a byte of python (摘01)

    a byte of python 第一章 介绍 Python 特色 简单.易学.免费.开源 高层语言.可移植性.解释性 面向对象.可扩展性.可嵌入性 丰富的库 第二章 安装Python http:// ...