Skip to content

Commit

Permalink
Change has_admin function
Browse files Browse the repository at this point in the history
Changed has_admin function to not rely on accessing a admin only directory, instead uses ctypes and os modules.
  • Loading branch information
knightlygains committed Oct 14, 2024
1 parent 420ebc0 commit 483602e
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import flet as ft # Must be version 0.23.2 for now
import the_shell
import datetime, json, re, subprocess, os, time, socket, pathlib, csv
import datetime, json, re, subprocess, ctypes, os, time, socket, pathlib, csv
from tutorial_btn import TutorialBtn
import text_values as text_values # Long text values stored in separate file
from dynamic_modal import DynamicModal
Expand Down Expand Up @@ -3271,7 +3271,7 @@ def on_github_hover(e):
e.control.bgcolor = "white" if e.data == "true" else None
e.control.border_radius = 50 if e.data =="true" else 0
e.control.update()

donate_view = ft.Column([
ft.Row([
ft.Column([
Expand Down Expand Up @@ -3373,13 +3373,12 @@ def select_path(e: ft.FilePickerResultEvent):
)

def has_admin():
if os.name == 'nt':
try:
# only windows users with admin privileges can read the C:\windows\temp
temp = os.listdir(os.sep.join([os.environ.get('SystemRoot','C:\\windows'),'temp']))
return True
except:
return False
try:
is_admin = os.getuid() == 0
return is_admin
except AttributeError:
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
return is_admin

setup_view = ft.Container(
content=ft.Column([
Expand All @@ -3404,14 +3403,21 @@ def has_admin():
padding=ft.padding.only(top=10, left=10, bottom=10, right=10)
)

if not has_admin():
update_results("No Admin", "Please re-run this app as admin.", gen_result_id, "localhost")

page_view = setup_view

if not has_admin() == True:
update_results("No Admin", "Please re-run this app as admin.", gen_result_id, "localhost")
print("No admin detected")
else:
print("Admin detected")


# Check if paths to tools are valid, if so show main program view
if os.path.exists(f"{settings_values['pwsh_path']}") and os.path.exists(f"{settings_values['pstools_path']}"):
# Main Program page view
print("Valid PsTools")
page_view = main_view
page.update()

#Finally build the page
page.add(
Expand Down

0 comments on commit 483602e

Please sign in to comment.