<s> from pywin . mfc import dialog <EOL> import win32ui <EOL> import win32con <EOL> import win32service <EOL> class StartupDlg ( dialog . Dialog ) : <EOL> IDC_LABEL = <NUM_LIT> <EOL> IDC_DEVICE = <NUM_LIT> <EOL> IDC_BOOT = <NUM_LIT> <EOL> IDC_SYSTEM = <NUM_LIT> <EOL> IDC_AUTOMATIC = <NUM_LIT> <EOL> IDC_MANUAL = <NUM_LIT> <EOL> IDC_DISABLED = <NUM_LIT> <EOL> def __init__ ( self , displayname , service ) : <EOL> dialog . Dialog . __init__ ( self , self . GetResource ( ) ) <EOL> self . name = displayname <EOL> self . service = service <EOL> def __del__ ( self ) : <EOL> win32service . CloseServiceHandle ( self . service ) <EOL> def OnInitDialog ( self ) : <EOL> cfg = win32service . QueryServiceConfig ( self . service ) <EOL> self . GetDlgItem ( self . IDC_BOOT + cfg [ <NUM_LIT:1> ] ) . SetCheck ( <NUM_LIT:1> ) <EOL> status = win32service . QueryServiceStatus ( self . service ) <EOL> if ( ( status [ <NUM_LIT:0> ] & win32service . SERVICE_KERNEL_DRIVER ) or <EOL> ( status [ <NUM_LIT:0> ] & win32service . SERVICE_FILE_SYSTEM_DRIVER ) ) : <EOL> self . GetDlgItem ( self . IDC_LABEL ) . SetWindowText ( '<STR_LIT>' ) <EOL> else : <EOL> self . GetDlgItem ( self . IDC_LABEL ) . SetWindowText ( '<STR_LIT>' ) <EOL> self . GetDlgItem ( self . IDC_BOOT ) . EnableWindow ( <NUM_LIT:0> ) <EOL> self . GetDlgItem ( self . IDC_SYSTEM ) . EnableWindow ( <NUM_LIT:0> ) <EOL> self . GetDlgItem ( self . IDC_DEVICE ) . SetWindowText ( str ( self . name ) ) <EOL> return dialog . Dialog . OnInitDialog ( self ) <EOL> def OnOK ( self ) : <EOL> self . BeginWaitCursor ( ) <EOL> starttype = self . GetCheckedRadioButton ( self . IDC_BOOT , self . IDC_DISABLED ) - self . IDC_BOOT <EOL> try : <EOL> win32service . ChangeServiceConfig ( self . service , win32service . SERVICE_NO_CHANGE , starttype , <EOL> win32service . SERVICE_NO_CHANGE , None , None , <NUM_LIT:0> , None , None , None , None ) <EOL> except : <EOL> self . MessageBox ( '<STR_LIT>' , None , <EOL> win32con . MB_ICONEXCLAMATION ) <EOL> self . EndWaitCursor ( ) <EOL> return dialog . Dialog . OnOK ( self ) <EOL> def GetResource ( self ) : <EOL> style = win32con . WS_POPUP | win32con . DS_SETFONT | win32con . WS_SYSMENU | win32con . WS_CAPTION | win32con . WS_VISIBLE | win32con . DS_MODALFRAME <EOL> exstyle = None <EOL> t = [ [ "<STR_LIT>" , ( <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , style , exstyle , ( <NUM_LIT:8> , '<STR_LIT>' ) ] , ] <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_LABEL , ( <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:8> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . SS_LEFT ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_DEVICE , ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:8> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . SS_LEFT ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , - <NUM_LIT:1> , ( <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_GROUP | win32con . BS_GROUPBOX ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_BOOT , ( <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:10> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_AUTORADIOBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_SYSTEM , ( <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:10> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_AUTORADIOBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_AUTOMATIC , ( <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:10> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_AUTORADIOBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_MANUAL , ( <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:10> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_AUTORADIOBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_DISABLED , ( <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:10> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_AUTORADIOBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT:OK>" , win32con . IDOK , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . WS_GROUP | win32con . BS_DEFPUSHBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , win32con . IDCANCEL , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_PUSHBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , win32con . IDHELP , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_PUSHBUTTON ] ) <EOL> return t <EOL> class ServiceDlg ( dialog . Dialog ) : <EOL> IDC_LIST = <NUM_LIT> <EOL> IDC_START = <NUM_LIT> <EOL> IDC_STOP = <NUM_LIT> <EOL> IDC_PAUSE = <NUM_LIT> <EOL> IDC_CONTINUE = <NUM_LIT> <EOL> IDC_STARTUP = <NUM_LIT> <EOL> IDC_PROFILES = <NUM_LIT> <EOL> IDC_PARAMS = <NUM_LIT> <EOL> def __init__ ( self , machineName = '<STR_LIT>' ) : <EOL> dialog . Dialog . __init__ ( self , self . GetResource ( ) ) <EOL> self . HookCommand ( self . OnListEvent , self . IDC_LIST ) <EOL> self . HookCommand ( self . OnStartCmd , self . IDC_START ) <EOL> self . HookCommand ( self . OnStopCmd , self . IDC_STOP ) <EOL> self . HookCommand ( self . OnPauseCmd , self . IDC_PAUSE ) <EOL> self . HookCommand ( self . OnContinueCmd , self . IDC_CONTINUE ) <EOL> self . HookCommand ( self . OnStartupCmd , self . IDC_STARTUP ) <EOL> self . machineName = machineName <EOL> self . scm = win32service . OpenSCManager ( self . machineName , None , win32service . SC_MANAGER_ALL_ACCESS ) <EOL> def __del__ ( self ) : <EOL> win32service . CloseServiceHandle ( self . scm ) <EOL> def OnInitDialog ( self ) : <EOL> self . listCtrl = self . GetDlgItem ( self . IDC_LIST ) <EOL> self . listCtrl . SetTabStops ( [ <NUM_LIT> , <NUM_LIT:200> ] ) <EOL> if self . machineName : <EOL> self . SetWindowText ( "<STR_LIT>" % self . machineName ) <EOL> self . ReloadData ( ) <EOL> return dialog . Dialog . OnInitDialog ( self ) <EOL> def ReloadData ( self ) : <EOL> service = self . GetSelService ( ) <EOL> self . listCtrl . SetRedraw ( <NUM_LIT:0> ) <EOL> self . listCtrl . ResetContent ( ) <EOL> svcs = win32service . EnumServicesStatus ( self . scm ) <EOL> i = <NUM_LIT:0> <EOL> self . data = [ ] <EOL> for svc in svcs : <EOL> try : <EOL> status = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) [ svc [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] ] <EOL> except : <EOL> status = '<STR_LIT>' <EOL> s = win32service . OpenService ( self . scm , svc [ <NUM_LIT:0> ] , win32service . SERVICE_ALL_ACCESS ) <EOL> cfg = win32service . QueryServiceConfig ( s ) <EOL> try : <EOL> startup = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) [ cfg [ <NUM_LIT:1> ] ] <EOL> except : <EOL> startup = '<STR_LIT>' <EOL> win32service . CloseServiceHandle ( s ) <EOL> pos = self . listCtrl . AddString ( str ( svc [ <NUM_LIT:1> ] ) + '<STR_LIT:\t>' + status + '<STR_LIT:\t>' + startup ) <EOL> self . listCtrl . SetItemData ( pos , i ) <EOL> self . data . append ( tuple ( svc [ <NUM_LIT:2> ] ) + ( svc [ <NUM_LIT:1> ] , svc [ <NUM_LIT:0> ] , ) ) <EOL> i = i + <NUM_LIT:1> <EOL> if service and service [ <NUM_LIT:1> ] == svc [ <NUM_LIT:0> ] : <EOL> self . listCtrl . SetCurSel ( pos ) <EOL> self . OnListEvent ( self . IDC_LIST , win32con . LBN_SELCHANGE ) <EOL> self . listCtrl . SetRedraw ( <NUM_LIT:1> ) <EOL> def OnListEvent ( self , id , code ) : <EOL> if code == win32con . LBN_SELCHANGE or code == win32con . LBN_SELCANCEL : <EOL> pos = self . listCtrl . GetCurSel ( ) <EOL> if pos >= <NUM_LIT:0> : <EOL> data = self . data [ self . listCtrl . GetItemData ( pos ) ] [ <NUM_LIT:2> ] <EOL> canstart = ( self . data [ self . listCtrl . GetItemData ( pos ) ] [ <NUM_LIT:1> ] == win32service . SERVICE_STOPPED ) <EOL> else : <EOL> data = <NUM_LIT:0> <EOL> canstart = <NUM_LIT:0> <EOL> self . GetDlgItem ( self . IDC_START ) . EnableWindow ( canstart ) <EOL> self . GetDlgItem ( self . IDC_STOP ) . EnableWindow ( data & win32service . SERVICE_ACCEPT_STOP ) <EOL> self . GetDlgItem ( self . IDC_PAUSE ) . EnableWindow ( data & win32service . SERVICE_ACCEPT_PAUSE_CONTINUE ) <EOL> self . GetDlgItem ( self . IDC_CONTINUE ) . EnableWindow ( data & win32service . SERVICE_ACCEPT_PAUSE_CONTINUE ) <EOL> def GetSelService ( self ) : <EOL> pos = self . listCtrl . GetCurSel ( ) <EOL> if pos < <NUM_LIT:0> : <EOL> return None <EOL> pos = self . listCtrl . GetItemData ( pos ) <EOL> return self . data [ pos ] [ - <NUM_LIT:2> : ] <EOL> def OnStartCmd ( self , id , code ) : <EOL> service = self . GetSelService ( ) <EOL> if not service : <EOL> return <EOL> s = win32service . OpenService ( self . scm , service [ <NUM_LIT:1> ] , win32service . SERVICE_ALL_ACCESS ) <EOL> win32service . StartService ( s , None ) <EOL> win32service . CloseServiceHandle ( s ) <EOL> self . ReloadData ( ) <EOL> def OnStopCmd ( self , id , code ) : <EOL> service = self . GetSelService ( ) <EOL> if not service : <EOL> return <EOL> s = win32service . OpenService ( self . scm , service [ <NUM_LIT:1> ] , win32service . SERVICE_ALL_ACCESS ) <EOL> win32service . ControlService ( s , win32service . SERVICE_CONTROL_STOP ) <EOL> win32service . CloseServiceHandle ( s ) <EOL> self . ReloadData ( ) <EOL> def OnPauseCmd ( self , id , code ) : <EOL> service = self . GetSelService ( ) <EOL> if not service : <EOL> return <EOL> s = win32service . OpenService ( self . scm , service [ <NUM_LIT:1> ] , win32service . SERVICE_ALL_ACCESS ) <EOL> win32service . ControlService ( s , win32service . SERVICE_CONTROL_PAUSE ) <EOL> win32service . CloseServiceHandle ( s ) <EOL> self . ReloadData ( ) <EOL> def OnContinueCmd ( self , id , code ) : <EOL> service = self . GetSelService ( ) <EOL> if not service : <EOL> return <EOL> s = win32service . OpenService ( self . scm , service [ <NUM_LIT:1> ] , win32service . SERVICE_ALL_ACCESS ) <EOL> win32service . ControlService ( s , win32service . SERVICE_CONTROL_CONTINUE ) <EOL> win32service . CloseServiceHandle ( s ) <EOL> self . ReloadData ( ) <EOL> def OnStartupCmd ( self , id , code ) : <EOL> service = self . GetSelService ( ) <EOL> if not service : <EOL> return <EOL> s = win32service . OpenService ( self . scm , service [ <NUM_LIT:1> ] , win32service . SERVICE_ALL_ACCESS ) <EOL> if StartupDlg ( service [ <NUM_LIT:0> ] , s ) . DoModal ( ) == win32con . IDOK : <EOL> self . ReloadData ( ) <EOL> def GetResource ( self ) : <EOL> style = win32con . WS_POPUP | win32con . DS_SETFONT | win32con . WS_SYSMENU | win32con . WS_CAPTION | win32con . WS_VISIBLE | win32con . DS_MODALFRAME <EOL> exstyle = None <EOL> t = [ [ "<STR_LIT>" , ( <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> ) , style , exstyle , ( <NUM_LIT:8> , '<STR_LIT>' ) ] , ] <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , - <NUM_LIT:1> , ( <NUM_LIT:6> , <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT:8> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . SS_LEFT ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , - <NUM_LIT:1> , ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT:8> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . SS_LEFT ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , - <NUM_LIT:1> , ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:50> , <NUM_LIT:8> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . SS_LEFT ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_LIST , ( <NUM_LIT:6> , <NUM_LIT:16> , <NUM_LIT:255> , <NUM_LIT> ) , 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 ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , win32con . IDOK , ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_GROUP | win32con . WS_TABSTOP | win32con . BS_DEFPUSHBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_START , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_PUSHBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_STOP , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_PUSHBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_PAUSE , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_PUSHBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_CONTINUE , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_PUSHBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_STARTUP , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_PUSHBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_PROFILES , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_PUSHBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , win32con . IDHELP , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_TABSTOP | win32con . BS_PUSHBUTTON ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , - <NUM_LIT:1> , ( <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . SS_LEFT ] ) <EOL> t . append ( [ <NUM_LIT> , "<STR_LIT>" , self . IDC_PARAMS , ( <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:12> ) , win32con . WS_VISIBLE | win32con . WS_CHILD | win32con . WS_GROUP | win32con . WS_BORDER | win32con . ES_AUTOHSCROLL ] ) <EOL> return t <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> machine = '<STR_LIT>' <EOL> if len ( sys . argv ) > <NUM_LIT:1> : <EOL> machine = sys . argv [ <NUM_LIT:1> ] <EOL> ServiceDlg ( machine ) . DoModal ( ) </s>
