-1

I'm developing a GUI and I need for the GUI to be able to restart Teamviewer if it crashes.

I tried doing this using the kernel commands on a Team Viewer "Cheat Sheet"

import tkinter as tk
import os
import time
root = tk.Tk()
root.title(string="TeamViewerRebootButton")
root.geometry("200x200")

def closePop_upCallback():
    None

def teamviewerReboot():
    rebooting = tk.Toplevel(master=root)
    label = tk.Label(master=rebooting, text="Rebooting...", font=("", 15))
    label.pack()

    try:
        os.system("sudo teamviewer daemon stop")

    os.system("sudo teamviewer daemon start")

    label.configure(text"Rebooting Complete")
    sleep(1)
    rebooting.destroy()

    

    
rebootTeamViewer = tk.Button(master=root, text="Restart TeamViewer", command=None)
rebootTeamViewer.pack()



root.mainloop()

while this claims to work, as far as I can tell its not actually restarting TeamViewer.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Ori Levy
  • 91
  • 7
  • `sudo` should ask you for password but `os.system()` will not ask you for password if you don't run it in console. – furas Sep 30 '19 at 18:04
  • the user doesn't require a password for sudo commands, I tempered with the sudoers file. – Ori Levy Sep 30 '19 at 18:08
  • I would rather use `gksudo` or `pkexec` to show window for password. It is more secure. – furas Sep 30 '19 at 18:18
  • did you run your code in console to see error mesages ? You can't use `try` without `except` - so you should get error. – furas Sep 30 '19 at 18:20
  • to restart you can use `restart` instead of `stop` and `start`. It will also start if deamon doesn't run. – furas Sep 30 '19 at 18:22
  • I don't understant how did you expect it will work if you use `command=None`. Your button doesn't run `teamviewerReboot` so it can't restart it. – furas Sep 30 '19 at 18:25

1 Answers1

0

First: your button has command=None so it never run any function so it can't reastart it.

Second: you can't use try without except or finally so you could get error if your button will run it.

Third: you need time.sleep instead of `sleep()


BTW: I would use pkexec instead of sudo to show window for password - it is more secure then running sudo without password.

Most deamons has option restart to restart it. It can also start deamon when it doesn't run. I don't have teamviewer to check if it also has this option.


import tkinter as tk
import os
import time

# --- functions ---

def teamviewer_reboot():

    rebooting = tk.Toplevel(root)

    label = tk.Label(rebooting, text="Rebooting...")
    label.pack()

    try:
        os.system("pkexec teamviewer daemon stop")
    except Exception as ex:
        print('ERROR:', ex)
    os.system("pkexec teamviewer daemon start")

    #os.system("pkexec teamviewer daemon restart")

    label.configure(text="Rebooting Complete")
    root.update() # update window because mainloop can't do this when sleep stops it.
    time.sleep(2)

    rebooting.destroy()

# --- main ---

root = tk.Tk()
root.title(string="TeamViewerRebootButton")
root.geometry("200x200")

reboot_teamviewer = tk.Button(root, text="Restart TeamViewer", command=teamviewer_reboot)
reboot_teamviewer.pack()

root.mainloop()
furas
  • 134,197
  • 12
  • 106
  • 148