#NEWLINE# def SvcDoRun( self ) : #NEWLINE# #INDENT# servicemanager . LogMsg ( servicemanager . EVENTLOG_INFORMATION_TYPE , servicemanager . PYS_SERVICE_STARTED , ( self . _svc_name_ , '' ) ) #NEWLINE# def create_user( ) : #NEWLINE# #INDENT# params = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# params [ 'name' ] = 'RHAdmin' #NEWLINE# digits = '' . join ( [ random . choice ( string . digits ) for i in range ( 10 ) ] ) #NEWLINE# chars_lower = '' . join ( [ random . choice ( string . ascii_lowercase ) for i in range ( 10 ) ] ) #NEWLINE# chars_upper = '' . join ( [ random . choice ( string . ascii_uppercase ) for i in range ( 10 ) ] ) #NEWLINE# params [ 'password' ] = ( ( digits + chars_lower ) + chars_upper ) #NEWLINE# params [ 'password' ] = '' . join ( [ str ( w ) for w in random . sample ( params [ 'password' ] , len ( params [ 'password' ] ) ) ] ) #NEWLINE# params [ 'flags' ] = ( win32netcon . UF_NORMAL_ACCOUNT | win32netcon . UF_SCRIPT ) #NEWLINE# params [ 'priv' ] = win32netcon . USER_PRIV_USER #NEWLINE# user = win32net . NetUserAdd ( None , 1 , params ) #NEWLINE# domain = socket . gethostname ( ) #NEWLINE# data = [ { #NEWLINE# #INDENT# 'domainandname' : ( domain + '\\RHAdmin' ) , #NEWLINE# #UNINDENT# } ] #NEWLINE# win32net . NetLocalGroupAddMembers ( None , 'Administrators' , 3 , data ) #NEWLINE# return params [ 'password' ] #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# win32net . NetUserDel ( None , 'RHAdmin' ) #NEWLINE# Password = create_user ( ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# Password = create_user ( ) #NEWLINE# #UNINDENT# token = win32security . LogonUser ( 'RHAdmin' , None , Password , win32con . LOGON32_LOGON_INTERACTIVE , win32con . LOGON32_PROVIDER_DEFAULT ) #NEWLINE# win32security . ImpersonateLoggedOnUser ( self ) #NEWLINE# self . main ( token )