we have here a powershell script collenting some user and windows infos storing them to a txt.file.
It would be nice if I could choose which information has to be collected with a wxGlade GUI.
I have already a solution how to execute powershell scripts.
The question is how I receive the values from the PowerShell Variables to the Python-Application:
We are interested in such Powershell-Infos:
$winver = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" -Name
ReleaseID).ReleaseId
$OsName = Get-ComputerInfo OsName
$OsVersion = Get-ComputerInfo OsVersion
$OsBuildNumber = Get-ComputerInfo OsBuildNumber
$OsHardwareAbstractionLayer = Get-ComputerInfo OsHardwareAbstractionLayer
$OfficeVer = reg query "HKEY_CLASSES_ROOT\Word.Application\CurVer"
This is the (TKINTER) Code I use for testing purposes. (Running PowerShell Script from Python) I will upgrade it with some advanced wxGlade-Widgets:
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox as tkmb
from tkinter import simpledialog as tksd
from tkinter import filedialog as tkfd
from pathlib import Path
from datetime import datetime
# First line
root = tk.Tk()
font_size = tk.IntVar(value=12)
# configure root
root.title('Powershell Test')
root.geometry('800x600+300+300')
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
root.configure(bg='#888')
import subprocess # IMPORT FOR SUB PROCESS . RUN METHOD
POWERSHELL_PATH = "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" #
POWERSHELL EXE PATH
ps_script_path =
"C:\\Users\\mr3968\\PycharmProjects\\SystemScriptWithGUI\\Powershell_Scripts\\browser.ps1" #
YOUR POWERSHELL FILE PATH
class Utility: # SHARED CLASS TO USE IN OUR PROJECT
@staticmethod # STATIC METHOD DEFINITION
def openbrowser(script_path, *params): # SCRIPT PATH = POWERSHELL SCRIPT PATH, PARAM =
POWERSHELL SCRIPT PARAMETERS ( IF ANY )
commandline_options = [POWERSHELL_PATH, '-ExecutionPolicy', 'Unrestricted',
ps_script_path] # ADD POWERSHELL EXE AND EXECUTION POLICY TO COMMAND VARIABLE
for param in params: # LOOP FOR EACH PARAMETER FROM ARRAY
commandline_options.append("'" + param + "'") # APPEND YOUR FOR POWERSHELL SCRIPT
process_result = subprocess.run(commandline_options, stdout = subprocess.PIPE, stderr
= subprocess.PIPE, universal_newlines = True) # CALL PROCESS
print(process_result.returncode) # PRINT RETURN CODE OF PROCESS 0 = SUCCESS, NON-
ZERO = FAIL
print(process_result.stdout) # PRINT STANDARD OUTPUT FROM POWERSHELL
print(process_result.stderr) # PRINT STANDARD ERROR FROM POWERSHELL ( IF ANY
OTHERWISE ITS NULL|NONE )
if process_result.returncode == 0: # COMPARING RESULT
Message = "Success !"
else:
Message = "Error Occurred !"
return Message # RETURN MESSAGE
powershell_frame = ttk.Frame(notebook)
notebook.add(powershell_frame, text='Powershell Test 1', underline=0)
powershell_frame.columnconfigure(2, weight=1)
powershell_frame.rowconfigure(1, weight=1)
# button open the browser
open_browser_btn = ttk.Button(
powershell_frame,
text='Open the browser'
)
open_browser_btn.grid(sticky=tk.E, ipadx=5, ipady=5)
open_browser_btn.configure(command=Utility.openbrowser(POWERSHELL_PATH))
root.mainloop()
Does it make sense to make it on this way or is it easier to collect all these infos with a native python code?
Thank you for your support.
I.
EDIT: I think this is a good solution to find e. g. Office Version: Description