@stottle
0.3.7.r1182 includes some stuff to experiment with the driver installing.
First add some code to the plugin, so we have two test buttons:
Code: Select all
def Configure(self, dummy=True):
from eg.WinApi.PipedProcess import ExecAsAdministrator
from os.path import join, dirname
import sys
scriptPath = join(dirname(__file__.decode(sys.getfilesystemencoding())), "Install.py")
panel = eg.ConfigPanel()
installButton = panel.Button("Install Service")
def OnInstallButton(event):
ExecAsAdministrator(scriptPath, "Install")
installButton.Bind(wx.EVT_BUTTON, OnInstallButton)
uninstallButton = panel.Button("Uninstall Service")
def OnUnInstallButton(event):
ExecAsAdministrator(scriptPath, "Uninstall")
uninstallButton.Bind(wx.EVT_BUTTON, OnUnInstallButton)
panel.sizer.Add(installButton)
panel.sizer.Add((10, 10))
panel.sizer.Add(uninstallButton)
while panel.Affirmed():
panel.SetResult()
Quite clumsy, but works. The important function is ExecAsAdministrator() from eg.WinApi.PipedProcess.
The first argument is a Python file that should be executed in the elevated process. The second parameter is the name of the function that should be called inside the Python module. You can supply additional parameters that will be used to call the function, but we don't use it here. If such parameters are used, they must be "pickle-able".
Now we add a file "Install.py" to your plugin folder, with this content:
Code: Select all
import sys
from os.path import dirname, join
from eg.WinApi.Service import Service
def Install():
service = Service(u"AlternateMceIrService")
pluginDir = dirname(__file__.decode(sys.getfilesystemencoding()))
service.Install(join(pluginDir, "AlternateMceIrService_86.exe"))
service.Start()
print "Service successfully installed"
def Uninstall():
service = Service(u"AlternateMceIrService")
service.Stop()
service.Uninstall()
print "Service successfully uninstalled"
So once a button is pressed, the appropriate function will be called in this file.
"Service" from eg.WinApi.Service is the needed helper class for manipulating services. Its only instantiation parameter is the name of the service. It mainly has four methods:
Install(exePath):
To install a service. You have to supply the path to the executable to install
Start(), Stop(), Uninstall(): Should be easy to guess what they do.
So this code as is only works for 32-bit and will also throw exceptions quite easily. For example if you try to install the service, when it is already installed. But this is just a matter of some try/except blocks.
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!