home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2566 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  11.5 KB  |  387 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from pywin.mfc import dialog
  5. import win32ui
  6. import win32con
  7. import win32service
  8.  
  9. class StartupDlg(dialog.Dialog):
  10.     IDC_LABEL = 127
  11.     IDC_DEVICE = 128
  12.     IDC_BOOT = 129
  13.     IDC_SYSTEM = 130
  14.     IDC_AUTOMATIC = 131
  15.     IDC_MANUAL = 132
  16.     IDC_DISABLED = 133
  17.     
  18.     def __init__(self, displayname, service):
  19.         dialog.Dialog.__init__(self, self.GetResource())
  20.         self.name = displayname
  21.         self.service = service
  22.  
  23.     
  24.     def __del__(self):
  25.         win32service.CloseServiceHandle(self.service)
  26.  
  27.     
  28.     def OnInitDialog(self):
  29.         cfg = win32service.QueryServiceConfig(self.service)
  30.         self.GetDlgItem(self.IDC_BOOT + cfg[1]).SetCheck(1)
  31.         status = win32service.QueryServiceStatus(self.service)
  32.         if status[0] & win32service.SERVICE_KERNEL_DRIVER or status[0] & win32service.SERVICE_FILE_SYSTEM_DRIVER:
  33.             self.GetDlgItem(self.IDC_LABEL).SetWindowText('Device:')
  34.         else:
  35.             self.GetDlgItem(self.IDC_LABEL).SetWindowText('Service:')
  36.             self.GetDlgItem(self.IDC_BOOT).EnableWindow(0)
  37.             self.GetDlgItem(self.IDC_SYSTEM).EnableWindow(0)
  38.         self.GetDlgItem(self.IDC_DEVICE).SetWindowText(str(self.name))
  39.         return dialog.Dialog.OnInitDialog(self)
  40.  
  41.     
  42.     def OnOK(self):
  43.         self.BeginWaitCursor()
  44.         starttype = self.GetCheckedRadioButton(self.IDC_BOOT, self.IDC_DISABLED) - self.IDC_BOOT
  45.         
  46.         try:
  47.             win32service.ChangeServiceConfig(self.service, win32service.SERVICE_NO_CHANGE, starttype, win32service.SERVICE_NO_CHANGE, None, None, 0, None, None, None, None)
  48.         except:
  49.             self.MessageBox('Unable to change startup configuration', None, win32con.MB_ICONEXCLAMATION)
  50.  
  51.         self.EndWaitCursor()
  52.         return dialog.Dialog.OnOK(self)
  53.  
  54.     
  55.     def GetResource(self):
  56.         style = win32con.WS_POPUP | win32con.DS_SETFONT | win32con.WS_SYSMENU | win32con.WS_CAPTION | win32con.WS_VISIBLE | win32con.DS_MODALFRAME
  57.         exstyle = None
  58.         t = [
  59.             [
  60.                 'Service Startup',
  61.                 (6, 18, 188, 107),
  62.                 style,
  63.                 exstyle,
  64.                 (8, 'MS Shell Dlg')]]
  65.         t.append([
  66.             130,
  67.             'Device:',
  68.             self.IDC_LABEL,
  69.             (6, 7, 40, 8),
  70.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.SS_LEFT])
  71.         t.append([
  72.             130,
  73.             '',
  74.             self.IDC_DEVICE,
  75.             (48, 7, 134, 8),
  76.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.SS_LEFT])
  77.         t.append([
  78.             128,
  79.             'Startup Type',
  80.             -1,
  81.             (6, 21, 130, 80),
  82.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_GROUP | win32con.BS_GROUPBOX])
  83.         t.append([
  84.             128,
  85.             '&Boot',
  86.             self.IDC_BOOT,
  87.             (12, 33, 39, 10),
  88.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_AUTORADIOBUTTON])
  89.         t.append([
  90.             128,
  91.             '&System',
  92.             self.IDC_SYSTEM,
  93.             (12, 46, 39, 10),
  94.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_AUTORADIOBUTTON])
  95.         t.append([
  96.             128,
  97.             '&Automatic',
  98.             self.IDC_AUTOMATIC,
  99.             (12, 59, 118, 10),
  100.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_AUTORADIOBUTTON])
  101.         t.append([
  102.             128,
  103.             '&Manual',
  104.             self.IDC_MANUAL,
  105.             (12, 72, 118, 10),
  106.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_AUTORADIOBUTTON])
  107.         t.append([
  108.             128,
  109.             '&Disabled',
  110.             self.IDC_DISABLED,
  111.             (12, 85, 118, 10),
  112.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_AUTORADIOBUTTON])
  113.         t.append([
  114.             128,
  115.             'OK',
  116.             win32con.IDOK,
  117.             (142, 25, 40, 14),
  118.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.WS_GROUP | win32con.BS_DEFPUSHBUTTON])
  119.         t.append([
  120.             128,
  121.             'Cancel',
  122.             win32con.IDCANCEL,
  123.             (142, 43, 40, 14),
  124.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON])
  125.         t.append([
  126.             128,
  127.             '&Help',
  128.             win32con.IDHELP,
  129.             (142, 61, 40, 14),
  130.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON])
  131.         return t
  132.  
  133.  
  134.  
  135. class ServiceDlg(dialog.Dialog):
  136.     IDC_LIST = 128
  137.     IDC_START = 129
  138.     IDC_STOP = 130
  139.     IDC_PAUSE = 131
  140.     IDC_CONTINUE = 132
  141.     IDC_STARTUP = 133
  142.     IDC_PROFILES = 134
  143.     IDC_PARAMS = 135
  144.     
  145.     def __init__(self, machineName = ''):
  146.         dialog.Dialog.__init__(self, self.GetResource())
  147.         self.HookCommand(self.OnListEvent, self.IDC_LIST)
  148.         self.HookCommand(self.OnStartCmd, self.IDC_START)
  149.         self.HookCommand(self.OnStopCmd, self.IDC_STOP)
  150.         self.HookCommand(self.OnPauseCmd, self.IDC_PAUSE)
  151.         self.HookCommand(self.OnContinueCmd, self.IDC_CONTINUE)
  152.         self.HookCommand(self.OnStartupCmd, self.IDC_STARTUP)
  153.         self.machineName = machineName
  154.         self.scm = win32service.OpenSCManager(self.machineName, None, win32service.SC_MANAGER_ALL_ACCESS)
  155.  
  156.     
  157.     def __del__(self):
  158.         win32service.CloseServiceHandle(self.scm)
  159.  
  160.     
  161.     def OnInitDialog(self):
  162.         self.listCtrl = self.GetDlgItem(self.IDC_LIST)
  163.         self.listCtrl.SetTabStops([
  164.             158,
  165.             200])
  166.         if self.machineName:
  167.             self.SetWindowText('Services on %s' % self.machineName)
  168.         
  169.         self.ReloadData()
  170.         return dialog.Dialog.OnInitDialog(self)
  171.  
  172.     
  173.     def ReloadData(self):
  174.         service = self.GetSelService()
  175.         self.listCtrl.SetRedraw(0)
  176.         self.listCtrl.ResetContent()
  177.         svcs = win32service.EnumServicesStatus(self.scm)
  178.         i = 0
  179.         self.data = []
  180.         for svc in svcs:
  181.             
  182.             try:
  183.                 status = ('Unknown', 'Stopped', 'Starting', 'Stopping', 'Running', 'Continuing', 'Pausing', 'Paused')[svc[2][1]]
  184.             except:
  185.                 status = 'Unknown'
  186.  
  187.             s = win32service.OpenService(self.scm, svc[0], win32service.SERVICE_ALL_ACCESS)
  188.             cfg = win32service.QueryServiceConfig(s)
  189.             
  190.             try:
  191.                 startup = ('Boot', 'System', 'Automatic', 'Manual', 'Disabled')[cfg[1]]
  192.             except:
  193.                 startup = 'Unknown'
  194.  
  195.             win32service.CloseServiceHandle(s)
  196.             pos = self.listCtrl.AddString(str(svc[1]) + '\t' + status + '\t' + startup)
  197.             self.listCtrl.SetItemData(pos, i)
  198.             self.data.append(tuple(svc[2]) + (svc[1], svc[0]))
  199.             i = i + 1
  200.             if service and service[1] == svc[0]:
  201.                 self.listCtrl.SetCurSel(pos)
  202.                 continue
  203.         
  204.         self.OnListEvent(self.IDC_LIST, win32con.LBN_SELCHANGE)
  205.         self.listCtrl.SetRedraw(1)
  206.  
  207.     
  208.     def OnListEvent(self, id, code):
  209.         if code == win32con.LBN_SELCHANGE or code == win32con.LBN_SELCANCEL:
  210.             pos = self.listCtrl.GetCurSel()
  211.             if pos >= 0:
  212.                 data = self.data[self.listCtrl.GetItemData(pos)][2]
  213.                 canstart = self.data[self.listCtrl.GetItemData(pos)][1] == win32service.SERVICE_STOPPED
  214.             else:
  215.                 data = 0
  216.                 canstart = 0
  217.             self.GetDlgItem(self.IDC_START).EnableWindow(canstart)
  218.             self.GetDlgItem(self.IDC_STOP).EnableWindow(data & win32service.SERVICE_ACCEPT_STOP)
  219.             self.GetDlgItem(self.IDC_PAUSE).EnableWindow(data & win32service.SERVICE_ACCEPT_PAUSE_CONTINUE)
  220.             self.GetDlgItem(self.IDC_CONTINUE).EnableWindow(data & win32service.SERVICE_ACCEPT_PAUSE_CONTINUE)
  221.         
  222.  
  223.     
  224.     def GetSelService(self):
  225.         pos = self.listCtrl.GetCurSel()
  226.         if pos < 0:
  227.             return None
  228.         pos = self.listCtrl.GetItemData(pos)
  229.         return self.data[pos][-2:]
  230.  
  231.     
  232.     def OnStartCmd(self, id, code):
  233.         service = self.GetSelService()
  234.         if not service:
  235.             return None
  236.         s = win32service.OpenService(self.scm, service[1], win32service.SERVICE_ALL_ACCESS)
  237.         win32service.StartService(s, None)
  238.         win32service.CloseServiceHandle(s)
  239.         self.ReloadData()
  240.  
  241.     
  242.     def OnStopCmd(self, id, code):
  243.         service = self.GetSelService()
  244.         if not service:
  245.             return None
  246.         s = win32service.OpenService(self.scm, service[1], win32service.SERVICE_ALL_ACCESS)
  247.         win32service.ControlService(s, win32service.SERVICE_CONTROL_STOP)
  248.         win32service.CloseServiceHandle(s)
  249.         self.ReloadData()
  250.  
  251.     
  252.     def OnPauseCmd(self, id, code):
  253.         service = self.GetSelService()
  254.         if not service:
  255.             return None
  256.         s = win32service.OpenService(self.scm, service[1], win32service.SERVICE_ALL_ACCESS)
  257.         win32service.ControlService(s, win32service.SERVICE_CONTROL_PAUSE)
  258.         win32service.CloseServiceHandle(s)
  259.         self.ReloadData()
  260.  
  261.     
  262.     def OnContinueCmd(self, id, code):
  263.         service = self.GetSelService()
  264.         if not service:
  265.             return None
  266.         s = win32service.OpenService(self.scm, service[1], win32service.SERVICE_ALL_ACCESS)
  267.         win32service.ControlService(s, win32service.SERVICE_CONTROL_CONTINUE)
  268.         win32service.CloseServiceHandle(s)
  269.         self.ReloadData()
  270.  
  271.     
  272.     def OnStartupCmd(self, id, code):
  273.         service = self.GetSelService()
  274.         if not service:
  275.             return None
  276.         s = win32service.OpenService(self.scm, service[1], win32service.SERVICE_ALL_ACCESS)
  277.         if StartupDlg(service[0], s).DoModal() == win32con.IDOK:
  278.             self.ReloadData()
  279.         
  280.  
  281.     
  282.     def GetResource(self):
  283.         style = win32con.WS_POPUP | win32con.DS_SETFONT | win32con.WS_SYSMENU | win32con.WS_CAPTION | win32con.WS_VISIBLE | win32con.DS_MODALFRAME
  284.         exstyle = None
  285.         t = [
  286.             [
  287.                 'Services',
  288.                 (16, 16, 333, 157),
  289.                 style,
  290.                 exstyle,
  291.                 (8, 'MS Shell Dlg')]]
  292.         t.append([
  293.             130,
  294.             'Ser&vice',
  295.             -1,
  296.             (6, 6, 70, 8),
  297.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.SS_LEFT])
  298.         t.append([
  299.             130,
  300.             'Status',
  301.             -1,
  302.             (164, 6, 42, 8),
  303.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.SS_LEFT])
  304.         t.append([
  305.             130,
  306.             'Startup',
  307.             -1,
  308.             (206, 6, 50, 8),
  309.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.SS_LEFT])
  310.         t.append([
  311.             131,
  312.             '',
  313.             self.IDC_LIST,
  314.             (6, 16, 255, 106),
  315.             win32con.LBS_USETABSTOPS | win32con.LBS_SORT | win32con.LBS_NOINTEGRALHEIGHT | win32con.WS_BORDER | win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_TABSTOP | win32con.LBS_NOTIFY | win32con.WS_VSCROLL])
  316.         t.append([
  317.             128,
  318.             'Close',
  319.             win32con.IDOK,
  320.             (267, 6, 60, 14),
  321.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_GROUP | win32con.WS_TABSTOP | win32con.BS_DEFPUSHBUTTON])
  322.         t.append([
  323.             128,
  324.             '&Start',
  325.             self.IDC_START,
  326.             (267, 27, 60, 14),
  327.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON])
  328.         t.append([
  329.             128,
  330.             'S&top',
  331.             self.IDC_STOP,
  332.             (267, 44, 60, 14),
  333.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON])
  334.         t.append([
  335.             128,
  336.             '&Pause',
  337.             self.IDC_PAUSE,
  338.             (267, 61, 60, 14),
  339.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON])
  340.         t.append([
  341.             128,
  342.             '&Continue',
  343.             self.IDC_CONTINUE,
  344.             (267, 78, 60, 14),
  345.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON])
  346.         t.append([
  347.             128,
  348.             'Sta&rtup...',
  349.             self.IDC_STARTUP,
  350.             (267, 99, 60, 14),
  351.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON])
  352.         t.append([
  353.             128,
  354.             'H&W Profiles...',
  355.             self.IDC_PROFILES,
  356.             (267, 116, 60, 14),
  357.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON])
  358.         t.append([
  359.             128,
  360.             '&Help',
  361.             win32con.IDHELP,
  362.             (267, 137, 60, 14),
  363.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON])
  364.         t.append([
  365.             130,
  366.             'St&artup Parameters:',
  367.             -1,
  368.             (6, 128, 70, 8),
  369.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.SS_LEFT])
  370.         t.append([
  371.             129,
  372.             '',
  373.             self.IDC_PARAMS,
  374.             (6, 139, 247, 12),
  375.             win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_GROUP | win32con.WS_BORDER | win32con.ES_AUTOHSCROLL])
  376.         return t
  377.  
  378.  
  379. if __name__ == '__main__':
  380.     import sys
  381.     machine = ''
  382.     if len(sys.argv) > 1:
  383.         machine = sys.argv[1]
  384.     
  385.     ServiceDlg(machine).DoModal()
  386.  
  387.