Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Python run TeamViewer from ini file.



#---------------Import Modules-------------------
import subprocess, platform, os, ConfigParser, time
from Tkinter import *
from tkFileDialog import askopenfilename


#---------------Tkinter-------------------------
root = Tk()
root.title("TeamViewer_Parse_From_File")
root.geometry("300x550")
#Scrol bar settings
scrollbar = Scrollbar(root)
scrollbar.pack( side = RIGHT, fill=Y )
#-------------Global Variable is here------------------
List_with_Server = []
Config = ConfigParser.ConfigParser()
Path = None
Path_To_Ini = None
Run = "TeamViewer.exe"
#--------------Check machine 86 or 64------------------
if platform.machine() == 'x86':
#global name
Path = "C:\\Program Files\\TeamViewer"
Path_To_Ini = "C:\\Program Files\\TeamViewer\\acc.ini"
else:
#global name
Path = "C:\\Program Files (x86)\\TeamViewer"
Path_To_Ini = "C:\\Program Files (x86)\\TeamViewer\\acc.ini"

#--------------Function is here------------------------
#--------------Load servers from file in windows-------
def Popalni():
global Path_To_Ini
global Path
global Run
global Config
global List_with_Server
os.chdir(Path)
ini_file = open(Path_To_Ini, 'r')
ini_file_content = ini_file.read().strip()
Config.read(Path_To_Ini)
List_with_Server = list(Config.sections())

for i in (Config.sections()):
mylist.insert(END,i)
mylist.see(END)
mylist.update()


def Open_Directory():
"""Use for add additional file"""
name = askopenfilename()
subprocess.Popen(["notepad.exe", name])

#----------After click on server name load param to begin---
def choose():
firstIndex = mylist.curselection()[0]
global Choiced_Name
global Config
Choiced_Name = List_with_Server[firstIndex]
option = Config.options(Choiced_Name)
ID_Server = Config.get(Choiced_Name, "User")
Password_Server = Config.get(Choiced_Name, "Password")
p = subprocess.Popen(Run+" -i " + ID_Server + " --Password " + Password_Server, shell=True)
time.sleep(2)
p.kill()
root.destroy()

#Menu Bar settings
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Load_All", command=Popalni)
filemenu.add_command(label="Open_Ini_File", command=Open_Directory)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="Menu", menu=filemenu)
root.config(menu=menubar)

mylist = Listbox(root, yscrollcommand = scrollbar.set , bg="lightblue")

frame=Frame(root)
frame.pack()
#Label(text="Anchor").pack(side=LEFT)
chooseButton = Button(frame, text="Load_List", command=Popalni ,bg="lightgreen")
chooseButton.pack(side=LEFT,anchor=NW)
chooseButton1 = Button(frame, text="Run_ID", command=lambda:choose(), bg="lightgreen")
chooseButton1.pack(anchor=NW)
mylist.pack( side = LEFT, fill = BOTH, expand=1 )
scrollbar.config( command = mylist.yview )

#-----------------Take the magic--------------------
if __name__ == "__main__":
mainloop()
The ini file called "acc.ini" is in the following form:
[First_Id]
User=111111111
Password=Password

[Second_ID]
User=222222222
Password=Password


This post first appeared on Linux Command's, please read the originial post: here

Share the post

Python run TeamViewer from ini file.

×

Subscribe to Linux Command's

Get updates delivered right to your inbox!

Thank you for your subscription

×