微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试创建服务搜索器

如何解决尝试创建服务搜索器

我正在尝试编写一个 python 脚本,该脚本将搜索 Windows 服务,并将它们显示在带有名称显示名称和状态的列表框中,但到目前为止我所做的只会显示零。在下方的对话框中,我可以看到 3 个输出,但我不知道如何将它们放入其下方的列表框中。

def search_query(searchbar):
    NameSave=("powershell -command "+'"'+"get-service *"+ searchbar+'* |ft -HideTableHeaders"')
    NameList=subprocess.call(NameSave,shell=True)
    serviceslist.insert(0,NameList)


searchf= tk.Frame(root,bg="#20179a")
searchf.place(relx=0.5,rely= 0.3,relwidth=0.6,relheight=0.075,anchor="n")
searchbar= tk.Entry(searchf,font="Helvetica 18 bold",justify="center")
searchbar.place(relx=0.4,rely=0.5,relwidth=0.65,relheight=0.8,anchor="center")
searchbutton=tk.Button(searchf,text="Search Service",font="Helvetica 16 bold",fg="#20179a",bd=0,command= lambda: search_query(searchbar.get()))
searchbutton.place(relx=0.75,relwidth=0.2,anchor="w")



servicesf=tk.Frame(root,bg="#20179a")
servicesf.place(relx=0.05,rely=0.4,relwidth=0.9,relheight=0.45)
serviceslist=tk.ListBox(servicesf,font="Helvetica 18 bold")
serviceslist.place(relx=0.025,rely=0.1,relwidth=0.95,relheight=0.8)

Function for search

app design

解决方法

这个问题有一个 PowerShell 本机解决方案,只需几行。

Get-Service |Out-GridView -passthru `
   -Title "All Services on $($env:COMPUTERNAME),Select one or more for additional info" |
    Format-List 

生成此用户界面。

enter image description here

然后可以将结果存储在变量中以备后用,或发送到另一个命令,例如在这种情况下 Format-List

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。