Python制作Windows憑據(jù)添加工具
1、圖示


2、代碼
import subprocess
import tkinter as tk
from tkinter import messagebox
def add_windows_credential(target_name, username="guest", password=""):
"""
使用 cmdkey 命令添加 Windows 憑據(jù)
"""
try:
# 構(gòu)建 cmdkey 命令
cmd = f'cmdkey /add:{target_name} /user:{username}'
if password:
cmd += f' /pass:{password}'
# 執(zhí)行命令
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
# 檢查命令執(zhí)行結(jié)果
if result.returncode == 0:
messagebox.showinfo("成功", f"成功添加憑據(jù)!\n目標(biāo)計(jì)算機(jī): {target_name}")
return True
else:
messagebox.showerror("錯(cuò)誤", f"添加憑據(jù)失敗: {result.stderr}")
return False
except Exception as e:
messagebox.showerror("錯(cuò)誤", f"添加憑據(jù)時(shí)發(fā)生錯(cuò)誤: {str(e)}")
return False
class CredentialApp:
def __init__(self, root):
self.root = root
self.root.title("Windows憑據(jù)添加工具")
self.root.geometry("300x150")
# 創(chuàng)建主框架,用于居中顯示內(nèi)容
main_frame = tk.Frame(root)
main_frame.pack(expand=True)
# 創(chuàng)建輸入框和標(biāo)簽
tk.Label(main_frame, text="請(qǐng)輸入目標(biāo)計(jì)算機(jī)名:", 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("警告", "請(qǐng)輸入計(jì)算機(jī)名!")
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()到此這篇關(guān)于Python制作Windows憑據(jù)添加工具的文章就介紹到這了,更多相關(guān)Python Windows憑據(jù)添加內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python實(shí)現(xiàn)Sqlite將字段當(dāng)做索引進(jìn)行查詢的方法
這篇文章主要介紹了Python實(shí)現(xiàn)Sqlite將字段當(dāng)做索引進(jìn)行查詢的方法,涉及Python針對(duì)sqlite數(shù)據(jù)庫(kù)索引操作的相關(guān)技巧,需要的朋友可以參考下2016-07-07
python異步編程 使用yield from過(guò)程解析
這篇文章主要介紹了python異步編程 使用yield from過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09
解決sublime+python3無(wú)法輸出中文的問(wèn)題
今天小編就為大家分享一篇解決sublime+python3無(wú)法輸出中文的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-12-12
淺談pandas關(guān)于查看庫(kù)或依賴庫(kù)版本的API原理
本文主要介紹了淺談pandas關(guān)于查看庫(kù)或依賴庫(kù)版本的API原理,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
python實(shí)現(xiàn)遍歷文件夾圖片并重命名
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)遍歷文件夾圖片并重命名,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03
Python文本情感分類識(shí)別基于SVM算法Django框架實(shí)現(xiàn)
這篇文章主要為大家介紹了Python文本情感分類識(shí)別基于SVM算法Django框架實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07

