#NEWLINE# def doStuff( self , command ) : #NEWLINE# #INDENT# def output_callback( data ) : #NEWLINE# #INDENT# self . __outputBuffer = data #NEWLINE# #UNINDENT# dce = self . __rpctransport . get_dce_rpc ( ) #NEWLINE# dce . set_credentials ( * self . __rpctransport . get_credentials ( ) ) #NEWLINE# dce . connect ( ) #NEWLINE# dce . bind ( tsch . MSRPC_UUID_TSCHS ) #NEWLINE# tmpName = gen_random_string ( 8 ) #NEWLINE# xml = '<?xml version="1.0" encoding="UTF-16"?>\n<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">\n  <Triggers>\n    <CalendarTrigger>\n      <StartBoundary>2015-07-15T20:35:13.2757294</StartBoundary>\n      <Enabled>true</Enabled>\n      <ScheduleByDay>\n        <DaysInterval>1</DaysInterval>\n      </ScheduleByDay>\n    </CalendarTrigger>\n  </Triggers>\n  <Principals>\n    <Principal id="LocalSystem">\n      <UserId>S-1-5-18</UserId>\n      <RunLevel>HighestAvailable</RunLevel>\n    </Principal>\n  </Principals>\n  <Settings>\n    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>\n    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>\n    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>\n    <AllowHardTerminate>true</AllowHardTerminate>\n    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>\n    <IdleSettings>\n      <StopOnIdleEnd>true</StopOnIdleEnd>\n      <RestartOnIdle>false</RestartOnIdle>\n    </IdleSettings>\n    <AllowStartOnDemand>true</AllowStartOnDemand>\n    <Enabled>true</Enabled>\n    <Hidden>true</Hidden>\n    <RunOnlyIfIdle>false</RunOnlyIfIdle>\n    <WakeToRun>false</WakeToRun>\n    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>\n    <Priority>7</Priority>\n  </Settings>\n  <Actions Context="LocalSystem">\n    <Exec>\n      <Command>cmd.exe</Command>\n' #NEWLINE# if self . __retOutput : #NEWLINE# #INDENT# tmpFileName = ( tmpName + '.tmp' ) #NEWLINE# xml += '      <Arguments>/C {} &gt; %windir%\\Temp\\{} 2&gt;&amp;1</Arguments>\n    </Exec>\n  </Actions>\n</Task>\n        ' . format ( command , tmpFileName ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . __retOutput is False ) : #NEWLINE# #INDENT# xml += '      <Arguments>/C {}</Arguments>\n    </Exec>\n  </Actions>\n</Task>\n        ' . format ( command ) #NEWLINE# #UNINDENT# #UNINDENT# taskCreated = False #NEWLINE# tsch . hSchRpcRegisterTask ( dce , ( '\\%s' % tmpName ) , xml , tsch . TASK_CREATE , NULL , tsch . TASK_LOGON_NONE ) #NEWLINE# taskCreated = True #NEWLINE# tsch . hSchRpcRun ( dce , ( '\\%s' % tmpName ) ) #NEWLINE# done = False #NEWLINE# while ( not done ) : #NEWLINE# #INDENT# resp = tsch . hSchRpcGetLastRunInfo ( dce , ( '\\%s' % tmpName ) ) #NEWLINE# if ( resp [ 'pLastRuntime' ] [ 'wYear' ] != 0 ) : #NEWLINE# #INDENT# done = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sleep ( 2 ) #NEWLINE# #UNINDENT# #UNINDENT# tsch . hSchRpcDelete ( dce , ( '\\%s' % tmpName ) ) #NEWLINE# taskCreated = False #NEWLINE# if ( taskCreated is True ) : #NEWLINE# #INDENT# tsch . hSchRpcDelete ( dce , ( '\\%s' % tmpName ) ) #NEWLINE# #UNINDENT# peer = ':' . join ( map ( str , self . __rpctransport . get_socket ( ) . getpeername ( ) ) ) #NEWLINE# if self . __retOutput : #NEWLINE# #INDENT# smbConnection = self . __rpctransport . get_smb_connection ( ) #NEWLINE# while True : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# smbConnection . getFile ( 'ADMIN$' , ( 'Temp\\%s' % tmpFileName ) , output_callback ) #NEWLINE# break #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# if ( str ( e ) . find ( 'SHARING' ) > 0 ) : #NEWLINE# #INDENT# sleep ( 3 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( str ( e ) . find ( 'STATUS_OBJECT_NAME_NOT_FOUND' ) >= 0 ) : #NEWLINE# #INDENT# sleep ( 3 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# smbConnection . deleteFile ( 'ADMIN$' , ( 'Temp\\%s' % tmpFileName ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# dce . disconnect ( )