在本文中,我们将给您介绍关于如何使Windows10计算机使用python脚本进入sleep状态?的详细内容,并且为您解答win10执行python脚本的相关问题,此外,我们还将为您提供关于2021年
在本文中,我们将给您介绍关于如何使Windows 10计算机使用python脚本进入sleep状态?的详细内容,并且为您解答win10执行python脚本的相关问题,此外,我们还将为您提供关于2021年2月的更新是否会迫使Windows 10计算机进入预、python 屏幕找图 点击,使用Python脚本在windows屏幕找图、windows 10 上使用pybind11进行C++和Python代码相互调用 | Interfacing C++ and Python with pybind11 on windows 10、Windows Server 2008R2使用Python脚本查看有效连接数的知识。
本文目录一览:- 如何使Windows 10计算机使用python脚本进入sleep状态?(win10执行python脚本)
- 2021年2月的更新是否会迫使Windows 10计算机进入预
- python 屏幕找图 点击,使用Python脚本在windows屏幕找图
- windows 10 上使用pybind11进行C++和Python代码相互调用 | Interfacing C++ and Python with pybind11 on windows 10
- Windows Server 2008R2使用Python脚本查看有效连接数
如何使Windows 10计算机使用python脚本进入sleep状态?(win10执行python脚本)
如何使用python脚本使计算机sleep?
它必须是 sleep ,而不是hibernate或其他。
我尝试使用,cmd
但是没有命令可以sleep,或者找不到。
答案1
小编典典您可以使用
import osos.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0")
如果此命令对您不起作用(实际上使您的计算机进入休眠模式),则需要关闭休眠模式:
Powercfg -H OFF
要重新打开休眠模式:
Powercfg -H ON
或者,您也可以使用:
Rundll32.exe Powrprof.dll,SetSuspendState Sleep
如果你 不 希望打开休眠关闭只是运行一个命令,你可以使用psshutdown作为替代
C:\Windows\System32\psshutdown.exe -d -t 0
至于做什么os.system
,直接从文档:
在子外壳程序中执行命令(字符串)。
附加说明:
您需要具有管理员权限才能运行Powercfg -H *
2021年2月的更新是否会迫使Windows 10计算机进入预
最近几天,您是否遇到过任何运行1909版或更高版本的Windows 10计算机在启动后进入预启动菜单的情况?一个博客读者使我面临这个问题。
2020年2月17日,他注意到联想的两台计算机在重启后突然停止在预启动菜单中。为此,他写道:本文来源于Win10纯净版,转载请注明来源与出处。
在我的生产环境中,到今天[17.2.2021],我有两台设备(Lenovo),我知道它们在当前Windows更新和预引导菜单中所需的重新引导后启动。
起初,我怀疑是KB4535680周围的问题,但是由于受影响的系统是在一月份的更新周期中,因此我不认为这是问题。
您是否知道2月的更新?到目前为止,我找不到任何东西。
KB4535680周围的问题是在各种HP系统上启动时的Bitlocker恢复密钥请求。
python 屏幕找图 点击,使用Python脚本在windows屏幕找图
python 屏幕找图 点击,使用Python脚本在windows屏幕找图
Python实现windows屏幕找图
import win32gui
hwnd_title = dict()
def get_all_hwnd(hwnd,mouse):
if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
hwnd_title.update({hwnd:win32gui.GetWindowText(hwnd)})
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import *
import win32gui
import sys
import time
import win32gui, win32ui, win32con, win32api
from send_text import send_message_to_slack
import random
import pyscreenshot as ImageGrab
import sys
import numpy as np
import time
from cv2 import cv2
from time import sleep
def get_pay_keyboard_number_location(impath, target,fit_num): #fit_num是匹配度,如 0.95,0.85
print("start find pic")
positions = {}
start = time.time()
img_rgb = cv2.imread(impath)
teNum = "done"
template = cv2.imread(target)
h, w = template.shape[:-1]
res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
threshold = fit_num # 匹配度参数,1为完全匹配
loc = np.where(res >= threshold)
if len(loc) > 0:
# positions[teNum] = zip(*loc[::-1])[0] # python2的写法
zipped = zip(*loc[::-1]) #list[::-1] 相当于起点为最后的一个,终点为第一个,然后一次减少一个
positions[teNum] = (list(zipped))[0]
else:
print("Can not found pic: ")
end = time.time()
print(end - start)
return positions[teNum]
def zhaotu(fenbianlv):
impath1 = ''screenshot.jpg''
targetPath_a = "yellow" +str(fenbianlv)+''.jpg''
win32gui.EnumWindows(get_all_hwnd, 0)
hwnd = win32gui.FindWindow(None, ''C:\Windows\system32\cmd.exe'')
app = QApplication(sys.argv)
screen = QApplication.primaryScreen()
while 1>0:
img = screen.grabWindow(hwnd ).toImage()
img.save("screenshot.jpg")
try:
ls = get_pay_keyboard_number_location(impath1, targetPath_a,0.98) #找目标图
except:
pass
sleep(5)
zhaotu(1792)
Flutter 写的app, 需要源码可以私信~~
windows 10 上使用pybind11进行C++和Python代码相互调用 | Interfacing C++ and Python with pybind11 on windows 10
本文首发于个人博客https://kezunlin.me/post/8b9c051d/,欢迎阅读!
Interfacing C++ and Python with pybind11 on windows 10
Series
- Part 1: Interfacing C++ and Python with pybind11 on windows 10
- Part 2: Interfacing C++ and Python with pybind11 on ubuntu 16.04
Guide
requirements:
- pybind11 v2.3.dev0
- python 2.7
install pytest
pip install pytest
compile
git clone https://github.com/pybind/pybind11.git
cd pybind11
mkdir build
cd build
cmake-gui ..
with options
PYBIND11_CPP_STANDARD /std:c++11 # default c++14
PYTHON_EXECUTABLE C:/Python27/python.exe
CMAKE_INSTALL_PREFIX C:/Program Files/pybind11
compile with VS 2015
with x64 Release
install to C:\Program Files\pybind11
with only include
and share
$ tree .
.
├── include
│ └── pybind11
│ ├── attr.h
│ ├── buffer_info.h
│ ├── cast.h
│ ├── chrono.h
│ ├── common.h
│ ├── complex.h
│ ├── detail
│ │ ├── class.h
│ │ ├── common.h
│ │ ├── descr.h
│ │ ├── init.h
│ │ ├── internals.h
│ │ └── typeid.h
│ ├── eigen.h
│ ├── embed.h
│ ├── eval.h
│ ├── functional.h
│ ├── iostream.h
│ ├── numpy.h
│ ├── operators.h
│ ├── options.h
│ ├── pybind11.h
│ ├── pytypes.h
│ ├── stl.h
│ └── stl_bind.h
└── share
└── cmake
└── pybind11
├── FindPythonLibsNew.cmake
├── pybind11Config.cmake
├── pybind11ConfigVersion.cmake
├── pybind11Targets.cmake
└── pybind11Tools.cmake
6 directories, 29 files
Usage
pybind11 (cpp--->python)
-
module: examplelib
-
target: examplelib
-
cpp: example.cpp
example.cpp
#include <pybind11/pybind11.h>
namespace py = pybind11;
int add(int i, int j) {
return i + j;
}
/*
#include <pybind11/pybind11.h>
namespace py = pybind11;
int add(int i, int j) {
return i + j;
}
struct Pet {
Pet(const std::string &name) : name(name) { }
void setName(const std::string &name_) { name = name_; }
const std::string &getName() const { return name; }
std::string name;
};
/*
module: examplelib
target: examplelib
cpp: example.cpp
*/
PYBIND11_MODULE(examplelib, m)
{
// optional module docstring
m.doc() = "pybind11 example plugin";
// FUNCTIONS
// expose add function, and add keyword arguments and default arguments
m.def("add", &add, "A function which adds two numbers", py::arg("i") = 1, py::arg("j") = 2);
// DATA
// exporting variables
m.attr("the_answer") = 42;
py::object world = py::cast("World");
m.attr("what") = world;
// CLASSES
py::class_<Pet>(m, "Pet")
.def(py::init<const std::string &>())
.def("setName", &Pet::setName)
.def("getName", &Pet::getName);
/*
python3
> help(examplelib)
*/
}
CMakeLists.txt
cmake_minimum_required (VERSION 2.6)
project (pybind)
enable_language(C)
enable_language(CXX)
find_package(pybind11 CONFIG REQUIRED)
include_directories(${pybind11_INCLUDE_DIRS})
message([MAIN] "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
MESSAGE( [Main] " pybind11_INCLUDE_DIRS = ${pybind11_INCLUDE_DIRS}")
MESSAGE( [Main] " pybind11_LIBRARIES = ${pybind11_LIBRARIES}")
#
# # Create an extension module
# add_library(mylib MODULE main.cpp)
# target_link_libraries(mylib pybind11::module)
#
# # Or embed the Python interpreter into an executable
# add_executable(myexe main.cpp)
# target_link_libraries(myexe pybind11::embed)
# method (1): generate `examplelib.pyd`
pybind11_add_module(examplelib example.cpp)
# method (2): generate `examplelib.dll` rename to `examplelib.pyd`
#add_library(examplelib MODULE example.cpp)
#target_link_libraries(examplelib pybind11::module)
MESSAGE( [Main] " pybind11_INCLUDE_DIRS = ${pybind11_INCLUDE_DIRS}")
MESSAGE( [Main] " pybind11_LIBRARIES = ${pybind11_LIBRARIES}")
#add_executable(cpp_use_python cpp_use_python.cpp)
#target_link_libraries(cpp_use_python PRIVATE pybind11::embed)
cmake and config
build with vs and we get 3 files:
examplelib.lib
examplelib.exp
examplelib.cp35-win_amd64.pyd
python import examplelib
python3
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import examplelib
>>> help(examplelib)
Help on module examplelib:
NAME
examplelib - pybind11 example plugin
CLASSES
pybind11_builtins.pybind11_object(builtins.object)
Pet
class Pet(pybind11_builtins.pybind11_object)
| Method resolution order:
| Pet
| pybind11_builtins.pybind11_object
| builtins.object
|
| Methods defined here:
|
| __init__(...)
| __init__(self: examplelib.Pet, arg0: str) -> None
|
| getName(...)
| getName(self: examplelib.Pet) -> str
|
| setName(...)
| setName(self: examplelib.Pet, arg0: str) -> None
|
| ----------------------------------------------------------------------
| Methods inherited from pybind11_builtins.pybind11_object:
|
| __new__(*args, **kwargs) from pybind11_builtins.pybind11_type
| Create and return a new object. See help(type) for accurate signature.
FUNCTIONS
add(...) method of builtins.PyCapsule instance
add(i: int = 1, j: int = 2) -> int
A function which adds two numbers
DATA
the_answer = 42
what = ''World''
FILE
e:\git\car\extra\pybind11\build\release\examplelib.cp35-win_amd64.pyd
>>> p = examplelib.Pet(''kzl'')
>>> print(p)
<examplelib.Pet object at 0x0000025EED9E3D18>
>>> p.getName()
''kzl''
>>> examplelib.add(1,2)
3
>>> examplelib.the_answer
42
>>> examplelib.what
''World''
>>>
embed
example.py
def add(i, j):
print("hello, pybind11")
return i+j
class MyMath:
def __init__(self,name):
self.name = name
def my_add(self,i,j):
return i + j
def my_strcon(self,a,b):
return a + b
cpp_use_python.cpp
#include <pybind11/embed.h>
#include <iostream>
namespace py = pybind11;
int main() {
py::scoped_interpreter python;
/*
import sys
print sys.path
print "Hello,World!"
*/
py::module sys = py::module::import("sys");
py::print(sys.attr("path"));
py::print("Hello, World!"); // use the Python API
/*
import example
n = example.add(1,2)
*/
py::module example = py::module::import("example");
py::object result = example.attr("add")(1, 2);
int n = result.cast<int>();
assert(n == 3);
std::cout << "result from example.add(1,2) = " << n << std::endl;
/*
from example import MyMath
obj = MyMath("v0")
obj.my_add(1,2)
*/
py::object MyMath = py::module::import("example").attr("MyMath"); // class
py::object obj = MyMath("v0"); // class object
py::object my_add = obj.attr("my_add");// object method
py::object result2 = my_add(1, 2); // result
int n2 = result2.cast<int>(); // cast from python type to c++ type
assert(n2 == 3);
std::cout << "result from obj.my_add(1,2) = " << n2 << std::endl;
/*
from example import MyMath
obj = MyMath("v0")
obj.my_strcon("abc","123");
*/
py::object my_strcon = obj.attr("my_strcon"); // object method
py::object result3 = my_strcon("abc", "123");
std::string str3 = result3.cast<std::string>();
std::cout << "result from obj.my_strcon(abc,123) = " << str3 << std::endl;
return 0;
}
CMakeLists.txt
cmake_minimum_required (VERSION 2.6)
project (pybind)
enable_language(C)
enable_language(CXX)
find_package(pybind11 CONFIG REQUIRED)
include_directories(${pybind11_INCLUDE_DIRS})
MESSAGE( [Main] " pybind11_INCLUDE_DIRS = ${pybind11_INCLUDE_DIRS}")
MESSAGE( [Main] " pybind11_LIBRARIES = ${pybind11_LIBRARIES}")
add_executable(cpp_use_python cpp_use_python.cpp)
target_link_libraries(cpp_use_python PRIVATE pybind11::embed)
Reference
- pybind11
- pybind11 embedding
- accessing-python-libraries-from-c
History
- 20180301: created.
Copyright
- Post author: kezunlin
- Post link: https://kezunlin.me/post/8b9c051d/
- Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.
Windows Server 2008R2使用Python脚本查看有效连接数
背景
之前在文章Windows Server 2008R2使用Batch脚本查看有效连接数提到过要使用Python脚本来统计连接数,并且做日志分割。之前还考虑过直接使用Batch来完成日志分割,最后败在Batch通过%time%
获取到的当前时间为命令行窗口打开的时间(我去,我放弃Batch了)。
Python3
import subprocess
import time
from datetime import datetime
import os
import csv
import time
import argparse
# python3 windows_netstat.py :80
# netstat -ano | find ":80" | find "ESTABLISHED" /c
parser = argparse.ArgumentParser()
parser.add_argument("port", type=str, help="port")
args = parser.parse_args()
timeFormat = "%Y-%m-%d %H:%M:%S.%f"
starTimeTitle = "时间"
connectionsTitle = "连接数"
while True:
starTime = datetime.now()
timeNow = starTime.strftime(timeFormat)
try:
output=subprocess.check_output(''netstat -ano | find "{0}" | find "ESTABLISHED" /c''.format(args.port), shell=True)
connections = output.decode(''utf-8'').strip()
nowTime = datetime.now()
csvFileName = "netstat_{0}.csv".format(nowTime.strftime("%Y-%m-%d"))
if os.path.exists(csvFileName) is not True:
with open(csvFileName, "w", encoding="utf-8", newline="") as csvfile:
fieldnames = [starTimeTitle, connectionsTitle]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
with open(csvFileName, "a", encoding="utf-8", newline="") as csvfile:
fieldnames = [starTimeTitle, connectionsTitle]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writerow({starTimeTitle : timeNow, connectionsTitle : connections})
except subprocess.CalledProcessError as e:
print("command ''{0}'' return with error (code {1}): {2}".format(e.cmd, e.returncode, e.output))
time.sleep(0.2)
这里大部分要点,都在文章Windows Server 2008R2使用Batch脚本查看有效连接数提到过,这里只提一下subprocess
调用本地netstat
的问题。
output=subprocess.check_output(''netstat -ano | find "{0}" | find "ESTABLISHED" /c''.format(args.port), shell=True)
这里是执行本地netstat
命令。这里获取到output
是字节数据组,不是字符串,还需要将该值转化成文本,故使用如下方式,进行编码:
output.decode(''utf-8'')
这样转化过文本包含换行符\n
,则还需要进行如下操作:
connections = output.decode(''utf-8'').strip()
这样得到的connections
值才是我们需要的统计的连接数。
使用
python3 windows_netstat.py :80
只要80端口存在有效连接就在本地生成一个csv文件,并且按天进行文件分割。
感受
人生苦短 我用Python 参考: Built-in Functions Python3 open python3 csv 如何移除换行符? 13.6 执行外部命令并获取它的输出 Subprocess management
关于如何使Windows 10计算机使用python脚本进入sleep状态?和win10执行python脚本的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于2021年2月的更新是否会迫使Windows 10计算机进入预、python 屏幕找图 点击,使用Python脚本在windows屏幕找图、windows 10 上使用pybind11进行C++和Python代码相互调用 | Interfacing C++ and Python with pybind11 on windows 10、Windows Server 2008R2使用Python脚本查看有效连接数的相关知识,请在本站寻找。
本文标签: