1、图示


2、代码
import subprocess
import tkinter as tk
from tkinter import messagebox
def add_windows_credential(target_name, username="guest", password=""):
"""
使用 cmdkey 命令添加 windows 凭据
"""
try:
# 构建 cmdkey 命令
cmd = f'cmdkey /add:{target_name} /user:{username}'
if password:
cmd += f' /pass:{password}'
# 执行命令
result = subprocess.run(cmd, shell=true, capture_output=true, text=true)
# 检查命令执行结果
if result.returncode == 0:
messagebox.showinfo("成功", f"成功添加凭据!\n目标计算机: {target_name}")
return true
else:
messagebox.showerror("错误", f"添加凭据失败: {result.stderr}")
return false
except exception as e:
messagebox.showerror("错误", f"添加凭据时发生错误: {str(e)}")
return false
class credentialapp:
def __init__(self, root):
self.root = root
self.root.title("windows凭据添加工具")
self.root.geometry("300x150")
# 创建主框架,用于居中显示内容
main_frame = tk.frame(root)
main_frame.pack(expand=true)
# 创建输入框和标签
tk.label(main_frame, text="请输入目标计算机名:", font=('arial', 10)).pack(pady=10)
self.computer_entry = tk.entry(main_frame, width=25)
self.computer_entry.pack(pady=5)
# 按钮框架
button_frame = tk.frame(main_frame)
button_frame.pack(pady=20)
# 添加确定和取消按钮
tk.button(button_frame, text="确定", width=10, command=self.add_credential).pack(side=tk.left, padx=10)
tk.button(button_frame, text="取消", width=10, command=self.root.quit).pack(side=tk.left, padx=10)
def add_credential(self):
computer_name = self.computer_entry.get().strip()
if not computer_name:
messagebox.showwarning("警告", "请输入计算机名!")
return
if add_windows_credential(computer_name):
self.computer_entry.delete(0, tk.end) # 清空输入框
def main():
root = tk.tk()
app = credentialapp(root)
root.mainloop()
if __name__ == "__main__":
main()到此这篇关于python制作windows凭据添加工具的文章就介绍到这了,更多相关python windows凭据添加内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论