first commit
This commit is contained in:
commit
bd8a119506
4 files changed
+77
No files matched your search
@@ -0,0 +1,14 @@
|
||||
[tool.poetry]
|
||||
name = "wpsext"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["wn0x00 <wn0x00@qq.com>"]
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "3.7"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
@@ -0,0 +1,8 @@
|
||||
def test_open_wps():
|
||||
pass
|
||||
|
||||
def test_close_wps():
|
||||
pass
|
||||
|
||||
def test_invoke_func():
|
||||
pass
|
||||
@@ -0,0 +1,45 @@
|
||||
import winreg
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
|
||||
def read_registry_value(key, subkey, value_name):
|
||||
"""通过注册表查询指定键值的值"""
|
||||
try:
|
||||
registry_key = winreg.OpenKey(key, subkey, 0, winreg.KEY_READ)
|
||||
value, regtype = winreg.QueryValueEx(registry_key, value_name)
|
||||
winreg.CloseKey(registry_key)
|
||||
return value
|
||||
except WindowsError as e:
|
||||
return None
|
||||
|
||||
|
||||
def get_wps_exe_path():
|
||||
"""通过注册表定位 wps 的安装路径"""
|
||||
key = winreg.HKEY_CURRENT_USER
|
||||
subkey = r"Software\kingsoft\Office\6.0\Common"
|
||||
value_name = "InstallRoot"
|
||||
install_root = read_registry_value(key, subkey, value_name)
|
||||
|
||||
if not install_root:
|
||||
raise FileNotFoundError("未找到 WPS 安装路径,请检查是否安装 WPS。")
|
||||
|
||||
wps_exe_path = os.path.join(install_root, "office6", "wps.exe")
|
||||
|
||||
assert os.path.exists(wps_exe_path), f"未找到 WPS 安装路径,请检查是否安装 WPS。"
|
||||
return wps_exe_path
|
||||
|
||||
|
||||
def run_wps():
|
||||
"""启动 WPS"""
|
||||
wps_exe_path = get_wps_exe_path()
|
||||
params = ["/prometheus", "/t"]
|
||||
process = subprocess.Popen(
|
||||
[wps_exe_path] + params,
|
||||
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.DETACHED_PROCESS,
|
||||
)
|
||||
print("Process ID:", process.pid)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_wps()
|
||||
Reference in new issue
Block a user