def update_bm(stu_id): reg = Reg.Reg() print u"你要更改学校为:" stu_school = raw_input() reg.setStu_id(stu_id) conn.execute("UPDATE " + table_1 + " SET stu_school=" + "'" + stu_school + "'" + "where stu_id=" + "'" + reg.getStu_id() + "'") print u"学号为:" + reg.getStu_id() + "的学校信息已经更改,是否继续(y/n):" op2 = raw_input() if op2 == "Y" or op2 == "y": update_bm() else: print u"是否查看学生的报名信息:(y/n)" op1 = raw_input() if op1 == "Y" or op1 == "y": coo = conn.execute("SELECT * FROM " + table_1 + " WHERE stu_id=" + "'" + reg.getStu_id() + "'") print u"姓名 学号(ID) 身份证\t 学校\t 系别 专业 (ID)密码\t性别\n" #此处空格比较多便于好看 for row in coo: print row[0], " ", row[1], " ", row[2], " ", row[3], " ", row[ 4], " ", row[5], " ", row[6], " ", row[7], "\n" print u"是否返回上一个菜单(y/n)" op1 = raw_input() if op1 == "Y" or op1 == "y": see_bmmess(stu_id) else: update_bm(stu_id) else: see_bmmess()
def build(self): screen_manager = ScreenManager() screen_manager.add_widget(Log.LogPage(name="LogPage")) screen_manager.add_widget(Reg.RegPage(name="RegPage")) screen_manager.add_widget(Account.Account(name="Account")) return screen_manager
def stu_login(): reg = Reg.Reg() print u"请输入你的学号" stu_id = raw_input() temp = conn.execute("select stu_id from " + table_1 + " where stu_id=" + "'" + stu_id + "'") print u"请输入你的密码:" stu_password = raw_input() temp_1 = conn.execute("select stu_password from " + table_1 + " where stu_id=" + "'" + stu_id + "'") temp_new = 0 temp_old = 0 for re in temp: temp_new = re[0] for re_1 in temp_1: temp_old = re_1[0] if stu_id == temp_new: if stu_password == temp_old: print u"欢迎学号", stu_id if True: reg.setStu_id(stu_id) showmenu5(stu_id) else: stu_login() else: print u"你的密码错误,请重新输入" stu_login() else: print u"你的学号错误,请重新输入:" stu_login()
def destroy(self): sid = self.getSid() if sid is None: return succefulDelete = False try: win32profile.DeleteProfile(sid) succefulDelete = True except: pass if not succefulDelete: if not self.unload(sid): Logger.error("Unable to unload User reg key for user %s" % (self.name)) return False try: win32profile.DeleteProfile(sid) succefulDelete = True except Exception, e: Logger.warn("Unable to unload user reg: %s" % (str(e))) try: path = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%s" % ( sid) Reg.DeleteTree(win32con.HKEY_LOCAL_MACHINE, path) except Exception, err: Logger.warn("RegDeleteTree of %s return: %s" % (path, str(err))) return False
def see_bm(stu_id): reg = Reg.Reg() reg.setStu_id(stu_id) coo = conn.execute("SELECT * FROM " + table_1 + " WHERE stu_id=" + "'" + reg.getStu_id() + "'") print u"姓名 学号(ID) 身份证\t 学校\t 系别 专业 (ID)密码\t性别\n" #此处空格比较多便于好看 for row in coo: print row[0], " ", row[1], " ", row[2], " ", row[3], " ", row[ 4], " ", row[5], " ", row[6], " ", row[7], "\n" print u"是否返回上一个菜单(y/n)" op1 = raw_input() if op1 in ['Y', 'y', ' ']: see_bmmess(stu_id) else: showmenu3()
def configure_nici(): path = r"Software\Novell\NICI" hkey = None try: Reg.CreateKeyR(win32con.HKEY_LOCAL_MACHINE, path) hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, path, 0, win32con.KEY_SET_VALUE) win32api.RegSetValueEx(hkey, "EnableUserProfileDirectory", 0, win32con.REG_DWORD, 1) except: return False finally: if hkey is not None: win32api.RegCloseKey(hkey) return True
def R2lambda(dataset1, dataset2, lambdas): Franklamb = Reg.regression(dataset1, dataset2, n) R2ridge = [] R2lasso = [] R2OLS = [] for lambd in lambdas: betasR = Franklamb.ridge(lambd) zRidge = np.dot(X, betasR) R2ridge.append(r2_score(z, zRidge)) betasL = Franklamb.lasso(lambd) zLasso = np.dot(X, betasL) R2lasso.append(r2_score(z, zLasso)) betasOLS = Franklamb.OLS() zOLS = np.dot(X, betasOLS) R2OLS.append(r2_score(z, zOLS)) return R2OLS, R2ridge, R2lasso
def doCustomizeRegistry(self, hive): if self.zenworks: return True path = hive + r"\Software\Ulteo\ovd\novell" Reg.CreateKeyR(win32con.HKEY_USERS, path) hkey = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) for item in self.account.keys(): win32api.RegSetValueEx(hkey, item, 0, win32con.REG_SZ, self.account[item]) win32api.RegCloseKey(hkey) # http://www.novell.com/support/viewContent.do?externalId=3576402&sliceId=1 # Problem when autogenerate users with same login but different SID if self.is_nici_well_configured(): return True return self.configure_nici()
def destroy(self): sid = self.getSid() if sid is None: return succefulDelete = False try: win32profile.DeleteProfile(sid) succefulDelete = True except: pass if not succefulDelete: if not self.unload(sid): Logger.error("Unable to unload User reg key for user %s" % (self.name)) return False try: win32profile.DeleteProfile(sid) succefulDelete = True except Exception: Logger.exception("Unable to unload user reg") try: path = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%s" % ( sid) Reg.DeleteTree(win32con.HKEY_LOCAL_MACHINE, path) except Exception: Logger.exception("RegDeleteTree of %s return: " % path) return False # Todo: remove the directory #Platform.DeleteDirectory(userdir) try: win32net.NetUserDel(None, self.name) except Exception: Logger.exception("Unable to delete user") return False return True
def see_ex(stu_id): reg = Reg.Reg() reg.setStu_id(stu_id) print u"\n你的准考证信息:" co = conn.execute("select * from " + table_4 + " where stu_name in " + "(select stu_name from " + table_1 + " where stu_id=" + "'" + reg.getStu_id() + "'" + ")") for row in co: print u"姓 名:", row[0] print u"身 份 证:", row[1] print u"学校名称:", row[2] print u"准考证号:", row[3] print u"考场地点:", row[4] print u"考场编号:", row[5] print u"座位号码:", row[6] print u"科目名称:", row[7] if True: print u"是否返回上一个菜单:(y/n)" op1 = raw_input() if op1 == "Y" or op1 == "y": showmenu5(stu_id) else: see_ex()
def get_surname(message): Reg.get_surname(message)
def register(self): self.log.withdraw() nw = Toplevel(self.log) Reg.Reg(nw)
def copySessionStart(self): d = shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0) profile_tmp_dir = os.path.join(d, "ulteo", "profile", self.session.user.name) profile_tmp_dir = System.local_encode(profile_tmp_dir) profile_filter = System.local_encode(Config.profile_filters_filename) for f in [self.DesktopDir, self.DocumentsDir]: d = os.path.join(self.mountPoint, "Data", f) trial = 5 while not os.path.exists(d): try: os.makedirs(d) except OSError: trial -= 1 if trial == 0: Logger.exception("Failed to create directory %s" % d) return False time.sleep(random.randint(1, 10) / 100.0) Logger.debug2( "Profile mkdir failed (concurrent access because of more than one ApS)" ) continue d = os.path.join(self.mountPoint, "conf.Windows.%s" % System.getWindowsVersionName()) if os.path.exists(d): # clean temporary file used by windows to load registry dirs = None try: dirs = os.listdir(d) except Exception: Logger.exception("Unable to list content of the directory %s" % d) return for content in dirs: if content.startswith(r"NTUSER.DAT.LOG") or content.startswith( r"NTUSER.DAT{"): try: path = os.path.join(d, content) os.remove(path) except Exception: Logger.exception("Unable to delete %s" % path) # Copy user registry src = os.path.join(d, "NTUSER.DAT") if os.path.exists(src): dst = os.path.join(self.session.windowsProfileDir, "NTUSER.DAT") rand = random.randrange(10000, 50000) hiveName_src = "OVD_%s_%d" % (str(self.session.id), rand) win32api.RegLoadKey(win32con.HKEY_USERS, hiveName_src, src) hiveName_dst = "OVD_%s_%d" % (str(self.session.id), rand + 1) win32api.RegLoadKey(win32con.HKEY_USERS, hiveName_dst, dst) hkey_src = win32api.RegOpenKey(win32con.HKEY_USERS, r"%s" % (hiveName_src), 0, win32con.KEY_ALL_ACCESS) hkey_dst = win32api.RegOpenKey(win32con.HKEY_USERS, r"%s" % (hiveName_dst), 0, win32con.KEY_ALL_ACCESS) Reg.CopyTree(hkey_src, "Software", hkey_dst, self.registry_copy_blacklist) win32api.RegCloseKey(hkey_src) win32api.RegCloseKey(hkey_dst) win32api.RegUnLoadKey(win32con.HKEY_USERS, hiveName_src) win32api.RegUnLoadKey(win32con.HKEY_USERS, hiveName_dst) # Copy configuration File if self.profile['profile_mode'] == 'standard': cmd = self.getRsyncMethod(Profile.toCygPath(d), Profile.toCygPath(profile_tmp_dir), Profile.toCygPath(profile_filter)) Logger.debug("rsync cmd '%s'" % (cmd)) p = System.execute(cmd) if p.returncode is not 0: Logger.error("Unable to copy conf from profile") Logger.debug( "Unable to copy conf from profile, cmd '%s' return %d: %s" % (cmd, p.returncode, p.stdout.read())) if os.path.exists(profile_tmp_dir): System.rchown(profile_tmp_dir, self.session.user.name)
def overrideRegistry(self, hiveName, username): fileservers = [] username_motif = r"u([a-zA-Z0-9\x00]{31}_\x00A\x00P\x00S\x00)" subpath = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook" if (self.profile is not None and self.mountPoint is not None) or len(self.sharedFolders) > 0: Reg.CreateKeyR(win32con.HKEY_USERS, hiveName + r"\Software\Ulteo") key = win32api.RegOpenKey(win32con.HKEY_USERS, hiveName + r"\Software\Ulteo", 0, win32con.KEY_ALL_ACCESS) Reg.DeleteTree(key, r"ovd", False) win32api.RegCloseKey(key) if self.profile is not None and self.mountPoint is not None: path = hiveName + r"\Software\Ulteo\ovd\profile" Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) win32api.RegSetValueEx(key, "rid", 0, win32con.REG_SZ, self.profile["rid"]) win32api.RegSetValueEx(key, "uri", 0, win32con.REG_SZ, self.profile["uri"]) if self.profile.has_key("login"): win32api.RegSetValueEx(key, "login", 0, win32con.REG_SZ, self.profile["login"]) if self.profile.has_key("password"): win32api.RegSetValueEx(key, "password", 0, win32con.REG_SZ, self.profile["password"]) win32api.RegCloseKey(key) # Set the name u = urlparse.urlparse(self.profile["uri"]) path = hiveName + r"\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##%s#%s" % ( u.netloc, u.path[1:].replace("/", "#")) Reg.CreateKeyR(win32con.HKEY_USERS, path) fileservers.append(u.netloc) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) win32api.RegSetValueEx(key, "_LabelFromReg", 0, win32con.REG_SZ, "Personal User Profile") win32api.RegCloseKey(key) lastUsername = Reg.TreeSearchExpression(hiveName, subpath, username_motif) if lastUsername is not None: uni_username = username.encode("UTF-16LE") Reg.TreeReplace(hiveName, subpath, lastUsername, uni_username) shareNum = 0 for share in self.sharedFolders: path = hiveName + r"\Software\Ulteo\ovd\%s" % (share["rid"]) Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) win32api.RegSetValueEx(key, "rid", 0, win32con.REG_SZ, share["rid"]) win32api.RegSetValueEx(key, "uri", 0, win32con.REG_SZ, share["uri"]) if share.has_key("login"): win32api.RegSetValueEx(key, "login", 0, win32con.REG_SZ, share["login"]) if share.has_key("password"): win32api.RegSetValueEx(key, "password", 0, win32con.REG_SZ, share["password"]) win32api.RegCloseKey(key) # Set the name u = urlparse.urlparse(share["uri"]) # No need to authorize shortcut in sharedFolder ?? #if u.netloc not in fileservers: # fileservers.append(u.netloc) # path = hiveName + r"\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##%s#%s" % ( u.netloc, u.path[1:].replace("/", "#")) Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) win32api.RegSetValueEx(key, "_LabelFromReg", 0, win32con.REG_SZ, share["name"]) win32api.RegCloseKey(key) shareNum += 1 if self.profile is not None: # Redirect the Shell Folders to the remote profile d = shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0) path = hiveName + r"\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" base = os.path.join(d, r"ulteo\profile", self.session.user.name) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) win32api.RegSetValueEx(key, "Desktop", 0, win32con.REG_SZ, r"U:\Data\%s" % (self.DesktopDir)) win32api.RegSetValueEx(key, "Personal", 0, win32con.REG_SZ, r"U:\Data\%s" % (self.DocumentsDir)) win32api.RegSetValueEx(key, "AppData", 0, win32con.REG_SZ, os.path.join(base, "CSIDL_APPDATA")) win32api.RegSetValueEx(key, "Local AppData", 0, win32con.REG_SZ, os.path.join(base, "CSIDL_LOCAL_APPDATA")) win32api.RegCloseKey(key) # Register file server rangeNumber = 1 for address in fileservers: path = hiveName + r"\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range%i" % ( rangeNumber) Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) win32api.RegSetValueEx(key, "file", 0, win32con.REG_DWORD, 1) win32api.RegSetValueEx(key, ":Range", 0, win32con.REG_SZ, address) rangeNumber += 1
for item in items: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 0) win32api.RegCloseKey(key) # Overwrite Active Setup: works partially try: Reg.UpdateActiveSetup(self.user.name, hiveName, r"Software\Microsoft\Active Setup") # On 64 bits architecture, Active Setup is already present in path "Software\Wow6432Node\Microsoft\Active Setup" if "PROGRAMW6432" in os.environ.keys(): Reg.UpdateActiveSetup(self.user.name, hiveName, r"Software\Wow6432Node\Microsoft\Active Setup") except Exception, err: Logger.warn("Unable to reset ActiveSetup") Logger.debug("Unable to reset ActiveSetup: " + str(err)) if self.profile is not None: self.profile.overrideRegistry(hiveName, self.user.name) self.domain.doCustomizeRegistry(hiveName) # Timezone override if self.parameters.has_key("timezone"): tz_name = Langs.getWinTimezone(self.parameters["timezone"]) ret = Reg.setTimezone(hiveName, tz_name) if ret is False: Logger.warn("Unable to set TimeZone (%s, %s)" % (self.parameters["timezone"], tz_name)) # Unload the hive win32api.RegUnLoadKey(win32con.HKEY_USERS, hiveName)
def get_car_model(message): Reg.get_car_model(message)
def get_number_car(message): Reg.get_number_car(message) bot.register_next_step_handler(message, get_car_model)
def overwriteDefaultRegistry(self, directory): registryFile = os.path.join(directory, "NTUSER.DAT") hiveName = "OVD_%s_%d" % (str(self.id), random.randrange(10000, 50000)) # Load the hive win32api.RegLoadKey(win32con.HKEY_USERS, hiveName, registryFile) # Set the OVD Environnment path = r"%s\Environment" % (hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) hkey = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: hkey = None if hkey is None: Logger.error("Unable to open key '%s'" % (path)) else: win32api.RegSetValueEx(hkey, "OVD_SESSION_DIR", 0, win32con.REG_SZ, self.user_session_dir) win32api.RegCloseKey(hkey) # Set the language if self.parameters.has_key("locale"): cl = Langs.getLCID(self.parameters["locale"]) wl = Langs.unixLocale2WindowsLocale(self.parameters["locale"]) path = r"%s\Control Panel\Desktop" % (hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) hkey = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: hkey = None if hkey is None: Logger.error("Unable to open key '%s'" % (path)) else: win32api.RegSetValueEx(hkey, "MUILanguagePending", 0, win32con.REG_SZ, "%08X" % (cl)) win32api.RegSetValueEx(hkey, "PreferredUILanguagesPending", 0, win32con.REG_MULTI_SZ, [wl]) win32api.RegCloseKey(hkey) # Policies update path = r"%s\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" % ( hiveName) restrictions = [ "DisableFavoritesDirChange", "DisableLocalMachineRun", "DisableLocalMachineRunOnce", "DisableMachineRunOnce", "DisableMyMusicDirChange", "DisableMyPicturesDirChange", "DisablePersonalDirChange", "EnforceShellExtensionSecurity", #"ForceStartMenuLogOff", "Intellimenus", "NoChangeStartMenu", "NoClose", "NoCommonGroups", "NoControlPanel", "NoDFSTab", "NoFind", "NoFolderOptions", "NoHardwareTab", "NoInstrumentation", "NoIntellimenus", "NoInternetIcon", # remove the IE icon "NoManageMyComputerVerb", "NonEnum", "NoNetworkConnections", "NoResolveSearch", "NoSetFolders", "NoSetTaskbar", #"NoStartMenuSubFolders", # should remove the folders from startmenu but doesn't work + On 2008, start menu is empty if this key is set "NoSMBalloonTip", "NoStartMenuEjectPC", "NoStartMenuNetworkPlaces", "NoTrayContextMenu", "NoWindowsUpdate", #"NoViewContextMenu", # Mouse right clic #"StartMenuLogOff", ] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: for item in restrictions: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 1) win32api.RegCloseKey(key) # Hide local drives value = 0 drives = win32api.GetLogicalDriveStrings() drives = drives.split('\000')[:-1] for drive in drives: t = win32file.GetDriveType(drive) if t not in [ win32con.DRIVE_CDROM, win32con.DRIVE_REMOVABLE, win32con.DRIVE_FIXED ]: continue # Transform the drive letter into a bit value according to # http://technet.microsoft.com/en-us/library/cc959437.aspx value += 1 << (ord(drive.lower()[0]) - 97) path = r"%s\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" % ( hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: win32api.RegSetValueEx(key, "NoDrives", 0, win32con.REG_DWORD, value) # win32api.RegSetValueEx(key, "NoViewOnDrive", 0, win32con.REG_DWORD, value) win32api.RegCloseKey(key) # Enable to use of lnk file from share without popup path = r"%s\Software\Microsoft\Windows\CurrentVersion\Policies\Associations" % ( hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: win32api.RegSetValueEx(key, "ModRiskFileTypes", 0, win32con.REG_SZ, ".exe;.msi;.vbs") win32api.RegCloseKey(key) # start menu customization path = r"%s\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" % ( hiveName) restrictions = [ "Start_ShowRun", "StartMenuAdminTools", "Start_AdminToolsRoot" ] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: for item in restrictions: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 0) win32api.RegCloseKey(key) if self.profile is not None: # http://support.microsoft.com/kb/810869 # Do not show recycle bin path = r"%s\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" % ( hiveName) restrictions = ["{645FF040-5081-101B-9F08-00AA002F954E}"] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: for item in restrictions: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 1) win32api.RegCloseKey(key) path = r"%s\Software\Microsoft\Windows\CurrentVersion\Policies\System" % ( hiveName) restrictions = [ "DisableRegistryTools", "DisableTaskMgr", "DisableLockWorkstation", "NoDispCPL", ] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: for item in restrictions: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 1) win32api.RegCloseKey(key) # Remove Windows startup sound keys = [ "WindowsLogon", "WindowsLogoff", "SystemStart", # old Windows 2003, not used anymore in 2008 ] for k in keys: path = r"%s\AppEvents\Schemes\Apps\.Default\%s\.Current" % ( hiveName, k) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: win32api.RegSetValueEx(key, None, 0, win32con.REG_EXPAND_SZ, "") win32api.RegCloseKey(key) # Desktop customization path = r"%s\Control Panel\Desktop" % (hiveName) items = ["ScreenSaveActive", "ScreenSaverIsSecure"] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: for item in items: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 0) win32api.RegCloseKey(key) # Overwrite Active Setup: works partially try: Reg.UpdateActiveSetup(self.user.name, hiveName, r"Software\Microsoft\Active Setup") # On 64 bits architecture, Active Setup is already present in path "Software\Wow6432Node\Microsoft\Active Setup" if "PROGRAMW6432" in os.environ.keys(): Reg.UpdateActiveSetup( self.user.name, hiveName, r"Software\Wow6432Node\Microsoft\Active Setup") except Exception: Logger.exception("Unable to reset ActiveSetup") if self.profile is not None: self.profile.overrideRegistry(hiveName, self.user.name) self.domain.doCustomizeRegistry(hiveName) # Timezone override if self.parameters.has_key("timezone"): tz_name = Langs.getWinTimezone(self.parameters["timezone"]) ret = Reg.setTimezone(hiveName, tz_name) if ret is False: Logger.warn("Unable to set TimeZone (%s, %s)" % (self.parameters["timezone"], tz_name)) # Hack for Windows 2012R2 relative to StartScreen integration. path = r"%s\Software\Microsoft\Windows\CurrentVersion\Explorer\StartPage" % ( hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: win32api.RegSetValueEx(key, "MakeAllAppsDefault", 0, win32con.REG_DWORD, 1) win32api.RegCloseKey(key) # Unload the hive win32api.RegUnLoadKey(win32con.HKEY_USERS, hiveName)
def main(): draw = True args = sys.argv[1:] if len(args)== 3 or len(args)==2: if len(args) == 3: draw = True elif len(args) == 2: draw = False else: print 'you should input the correct arguments such as "[-v]" <regex> <textFile>' exit(0) regex = sys.argv[-2] f_name = sys.argv[-1] reg = Reg.Reg() #regex = '(010)^((a|b)+c+)*(b..c)(m*n)*(000)$' reg.setExp(regex) reg.genRule() RuleSets = {} for r in reg.RuleSets: RuleSets[r] = reg.RuleSets[r] print 'the Regular for regex '+regex+' is:' print RuleSets #generate a NFA by rules generated by the regex if draw: nfa = NFA.nfa() nfa.setExp(regex) nfa.genRule() nfa.genNFA() print 'the NFA generated from regex '+regex+' is' print nfa.RuleNFA nfa.drawNFA() f = open(f_name) lines = f.readlines() print 'the Result of checkRule from textfile fname is :' longest = False # print lines linelist = [] lenlist = {} x=[] for line in lines: if line == '\n': continue line = line.replace('\n','') lineset = line.split(' ') for word in lineset: if checkRule('S',word,RuleSets): print 'the line: '+line print 'the column: '+str(line.find(word)) print 'the string: '+word print '' longest = True linelist.append(word) if longest: for r in linelist: lenlist[len(r)]=r x.append(len(r)) x.sort() print 'the longest string is: '+lenlist[x[-1]] string = lenlist[x[-1]] for line in lines: line = line.replace('\n','') lineset = line.split(' ') if string in line: for word in lineset: if string == word: print 'it\'s in the line: '+line print 'the column is: '+str(line.find(string))
rand = random.randrange(10000, 50000) hiveName_src = "OVD_%s_%d" % (str(self.session.id), rand) win32api.RegLoadKey(win32con.HKEY_USERS, hiveName_src, src) hiveName_dst = "OVD_%s_%d" % (str(self.session.id), rand + 1) win32api.RegLoadKey(win32con.HKEY_USERS, hiveName_dst, dst) hkey_src = win32api.RegOpenKey(win32con.HKEY_USERS, r"%s" % (hiveName_src), 0, win32con.KEY_ALL_ACCESS) hkey_dst = win32api.RegOpenKey(win32con.HKEY_USERS, r"%s" % (hiveName_dst), 0, win32con.KEY_ALL_ACCESS) Reg.CopyTree(hkey_src, "Software", hkey_dst, self.registry_copy_blacklist) win32api.RegCloseKey(hkey_src) win32api.RegCloseKey(hkey_dst) win32api.RegUnLoadKey(win32con.HKEY_USERS, hiveName_src) win32api.RegUnLoadKey(win32con.HKEY_USERS, hiveName_dst) # Copy AppData src = os.path.join(d, "AppData") if os.path.exists(src): dst = self.session.appDataDir try: Util.copyDirOverride(src, dst, [ "Protect", "Start Menu", "Crypto", "ulteo",
def get_phone_dr(message): Reg.get_phone(message) bot.register_next_step_handler(message, get_name_dr)
def new_stu(): reg = Reg.Reg() exam = Examinee.Examinee() #学生姓名输入 while True: print u"请输入你的姓名:" stu_name = raw_input() if stu_name: reg.setStu_name(stu_name) break else: print u"请重新输入:" continue #学生学号的注册,包含以后登录用户 while True: print u"请输入你的学号(ID):" stu_id = raw_input() if True: reg.setStu_id(stu_id) break else: print u"学号必须为9位数" continue #学生身份证的输入 while True: print u"请输入你的身份证号码:" stu_indentify = raw_input() if True: reg.setStu_indentify(stu_indentify) break else: print u"身份证必须为18位数" continue #学生的学校信息输入 while True: print u"请输入你的学校信息:" stu_school = raw_input() if stu_school: reg.setStu_school(stu_school) break else: print u"请重新输入:" continue #学生的院系的输入 while True: print u"请输入你的院系:" stu_institute = raw_input() reg.setStu_institute(stu_institute) break #学生的专业的输入 while True: print u"请输入你的专业:" stu_major = raw_input() if stu_major: reg.setStu_major(stu_major) break else: print u"请重新输入:" continue #学生的账号密码的输入 while True: print u"请输入你的账号密码:" stu_password = raw_input() if stu_password: reg.setStu_password(stu_password) break else: print u"请重新输入:" continue #学生的性别输入 while True: print u"请输入你的性别:" stu_sex = raw_input() if stu_sex: reg.setStu_sex(stu_sex) break else: print u"请重新输入:" continue #学生的报名信息的显示 print u"姓名 学号(ID) 身份证\t 学校\t 系别 专业 (ID)密码\t性别\n" #此处空格比较多便于好看 print reg.getStu_name(), " ", reg.getStu_id(), " ", reg.getStu_indentify( ), " ", reg.getStu_school(), " ", reg.getStu_institute( ), " ", reg.getStu_major(), " ", reg.getStu_password( ), " ", reg.getStu_sex() #在sql中增加学生信息中文的输入记住要.decode('gbk') conn.execute("insert into " + table_1 + " values (?,?,?,?,?,?,?,?)", (reg.getStu_name().decode('gbk'), reg.getStu_id(), reg.getStu_indentify(), reg.getStu_school().decode('gbk'), reg.getStu_institute().decode('gbk'), reg.getStu_major().decode('gbk'), reg.getStu_password(), reg.getStu_sex().decode('gbk'))) conn.commit() print u"请选择你要报名的科目:\n(1)四级(2)六级" exam = Examinee.Examinee() nowTime = datetime.datetime.now().strftime("%Y%m%d%H%M%S") #生成当前时间 exam_seat = random.randint(1, 25) if exam_seat < 10: exam_seat = str(0) + str(exam_seat) exam.setExam_seat(exam_seat) ex = raw_input() exam_room_4 = random.randint(1, 10) exam_room_6 = random.randint(11, 20) exam_place = 'buiding 8' exam.setExam_major(exam_place) if ex == '1': print u"你报名的是四级,考场号:", exam_room_4 exam_major = "cet4" exam.setExam_major(exam_major) exam.setExam_room(exam_room_4) exam_id = str(nowTime) + "Z" + str(exam_room_4) + str(exam_seat) exam.setExam_id(exam_id) print u"你的准考证号是:", exam.getExam_id() print u"你的座位号位:", exam.getExam_seat() else: print u"你报名的是六级,考场号:", exam_room_6 exam_major = "cet6" exam.setExam_major(exam_major) exam.setExam_room(exam_room_6) exam_id = str(nowTime) + "Z" + str(exam_room_6) + str(exam_seat) exam.setExam_id(exam_id) print u"你的准考证号是:", exam.getExam_id() print u"你的座位号位:", exam.getExam_seat() exam_place = u"八大楼" conn.execute("insert into " + table_4 + " values (?,?,?,?,?,?,?,?)", (reg.getStu_name().decode('gbk'), reg.getStu_indentify(), reg.getStu_school().decode('gbk'), exam.getExam_id(), exam_place, exam.getExam_room(), exam.getExam_seat(), exam.getExam_major().decode('gbk'))) conn.commit() print u"注册成功!是否查看自己的准考证信息:(y/n),n返回上一个菜单" ou = raw_input() #注册成功后显示学生的准考证信息 if ou in ['Y', 'y', ' ']: co = conn.execute("select * from " + table_4 + " where exam_id=" + "'" + exam.getExam_id() + "'") for row in co: print u"姓 名:", row[0] print u"身 份 证:", row[1] print u"学校名称:", row[2] print u"准考证号:", row[3] print u"考场地点:", row[4] print u"考场编号:", row[5] print u"座位号码:", row[6] print u"科目名称:", row[7] print u"准考证信息显示完成是否返回上一个菜单(y/n)" op1 = raw_input() if op1 in ['Y', 'y', ' ']: stu() else: stu() else: print u"是否退出系统:(y/n)" op = raw_input() if op == "Y" or op == "y" or op == "": sys.exit(0) conn.close() else: showmenu1()
def overrideRegistry(self, hiveName, username): username_motif = r"u([a-zA-Z0-9\x00]{31}_\x00A\x00P\x00S\x00)" subpath = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook" if self.profile is not None or len(self.sharedFolders) > 0: Reg.CreateKeyR(win32con.HKEY_USERS, hiveName + r"\Software\Ulteo") key = win32api.RegOpenKey(win32con.HKEY_USERS, hiveName + r"\Software\Ulteo", 0, win32con.KEY_ALL_ACCESS) Reg.DeleteTree(key, r"ovd", False) win32api.RegCloseKey(key) if self.profile is not None: path = hiveName + r"\Software\Ulteo\ovd\profile" Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) win32api.RegSetValueEx(key, "host", 0, win32con.REG_SZ, self.profile["server"]) win32api.RegSetValueEx(key, "directory", 0, win32con.REG_SZ, self.profile["dir"]) win32api.RegSetValueEx(key, "login", 0, win32con.REG_SZ, self.profile["login"]) win32api.RegSetValueEx(key, "password", 0, win32con.REG_SZ, self.profile["password"]) win32api.RegCloseKey(key) # Set the name path = hiveName + r"\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##%s#%s" % ( self.profile["server"], self.profile["dir"]) Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) win32api.RegSetValueEx(key, "_LabelFromReg", 0, win32con.REG_SZ, "Personal User Profile") win32api.RegCloseKey(key) lastUsername = Reg.TreeSearchExpression(hiveName, subpath, username_motif) if lastUsername is not None: uni_username = username.encode("UTF-16LE") Reg.TreeReplace(hiveName, subpath, lastUsername, uni_username) shareNum = 0 for share in self.sharedFolders: path = hiveName + r"\Software\Ulteo\ovd\share_%d" % (shareNum) Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) win32api.RegSetValueEx(key, "host", 0, win32con.REG_SZ, share["server"]) win32api.RegSetValueEx(key, "directory", 0, win32con.REG_SZ, share["dir"]) win32api.RegSetValueEx(key, "login", 0, win32con.REG_SZ, share["login"]) win32api.RegSetValueEx(key, "password", 0, win32con.REG_SZ, share["password"]) win32api.RegCloseKey(key) # Set the name path = hiveName + r"\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##%s#%s" % ( share["server"], share["dir"]) Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) win32api.RegSetValueEx(key, "_LabelFromReg", 0, win32con.REG_SZ, share["name"]) win32api.RegCloseKey(key) shareNum += 1 if self.profile is not None: # Redirect the Shell Folders to the remote profile path = hiveName + r"\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) win32api.RegSetValueEx(key, "Desktop", 0, win32con.REG_SZ, r"U:\%s" % (self.DesktopDir)) win32api.RegSetValueEx(key, "Personal", 0, win32con.REG_SZ, r"U:\%s" % (self.DocumentsDir)) win32api.RegCloseKey(key)
def get_name(message): Reg.get_name(message) bot.register_next_step_handler(message, get_surname)
def get_surname_dr(message): Reg.get_surname_dr(message) bot.register_next_step_handler(message, get_color_car)
n = 200 deg = 5 x = np.sort((np.random.rand(n))) y = np.sort((np.random.rand(n))) x, y = np.meshgrid(x, y) x1d = x.reshape((n**2, 1)) y1d = y.reshape((n**2, 1)) error = 0.1 * np.random.randn(n**2, 1) z = FRANK(x1d, y1d) + error X = Reg.polynomial_this(x1d, y1d, deg) def KfoldCrossVal(dataset, dataset2, Numbfold): indices = np.arange(len(dataset[:, 0])) random_indices = np.random.choice(indices, size=len(dataset[:, 0]), replace=False) interval = int(len(dataset[:, 0]) / Numbfold) datasetsplit = [] dataset2split = [] for k in range(Numbfold): datasetsplit.append(dataset[random_indices[interval * k:interval * (k + 1)]]) dataset2split.append(dataset2[random_indices[interval * k:interval * (k + 1)]])
# Overwrite Active Setup: works partially try: Reg.UpdateActiveSetup(self.user.name, hiveName, r"Software\Microsoft\Active Setup") # On 64 bits architecture, Active Setup is already present in path "Software\Wow6432Node\Microsoft\Active Setup" if "PROGRAMW6432" in os.environ.keys(): Reg.UpdateActiveSetup( self.user.name, hiveName, r"Software\Wow6432Node\Microsoft\Active Setup") except Exception, err: Logger.warn("Unable to reset ActiveSetup") Logger.debug("Unable to reset ActiveSetup: " + str(err)) if self.profile is not None: self.profile.overrideRegistry(hiveName, self.user.name) self.domain.doCustomizeRegistry(hiveName) # Timezone override if self.parameters.has_key("timezone"): tz_name = Langs.getWinTimezone(self.parameters["timezone"]) ret = Reg.setTimezone(hiveName, tz_name) if ret is False: Logger.warn("Unable to set TimeZone (%s, %s)" % (self.parameters["timezone"], tz_name)) # Unload the hive win32api.RegUnLoadKey(win32con.HKEY_USERS, hiveName)
def reg_pas(call): if passenger_change == 0: Reg.get_reg(call.message) elif passenger_change == 1: Reg.get_update_reg(call.message)
def reg_dr(call): if drive_change == 0: Reg.get_reg_dr(call.message) elif drive_change == 1: Reg.get_update_reg_dr(call.message)
def overwriteDefaultRegistry(self, directory): registryFile = os.path.join(directory, "NTUSER.DAT") hiveName = "OVD_%s_%d" % (str(self.id), random.randrange(10000, 50000)) # Load the hive win32api.RegLoadKey(win32con.HKEY_USERS, hiveName, registryFile) # Set the OVD Environnment path = r"%s\Environment" % (hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) hkey = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: hkey = None if hkey is None: Logger.error("Unable to open key '%s'" % (path)) else: win32api.RegSetValueEx( hkey, "OVD_SESSION_DIR", 0, win32con.REG_SZ, os.path.join(self.appDataDir, "ulteo", "ovd")) win32api.RegCloseKey(hkey) # Set the language if self.parameters.has_key("locale"): cl = Langs.getLCID(self.parameters["locale"]) wl = Langs.unixLocale2WindowsLocale(self.parameters["locale"]) path = r"%s\Control Panel\Desktop" % (hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) hkey = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: hkey = None if hkey is None: Logger.error("Unable to open key '%s'" % (path)) else: win32api.RegSetValueEx(hkey, "MUILanguagePending", 0, win32con.REG_SZ, "%08X" % (cl)) win32api.RegSetValueEx(hkey, "PreferredUILanguagesPending", 0, win32con.REG_MULTI_SZ, [wl]) win32api.RegCloseKey(hkey) # Policies update path = r"%s\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" % ( hiveName) restrictions = [ "DisableFavoritesDirChange", "DisableLocalMachineRun", "DisableLocalMachineRunOnce", "DisableMachineRunOnce", "DisableMyMusicDirChange", "DisableMyPicturesDirChange", "DisablePersonalDirChange", "EnforceShellExtensionSecurity", #"ForceStartMenuLogOff", "Intellimenus", "NoChangeStartMenu", "NoClose", "NoCommonGroups", "NoControlPanel", "NoDFSTab", "NoFind", "NoFolderOptions", "NoHardwareTab", "NoInstrumentation", "NoIntellimenus", "NoInternetIcon", # remove the IE icon "NoManageMyComputerVerb", "NonEnum", "NoNetworkConnections", "NoResolveSearch", "NoSetFolders", "NoSetTaskbar", #"NoStartMenuSubFolders", # should remove the folders from startmenu but doesn't work + On 2008, start menu is empty if this key is set "NoSMBalloonTip", "NoStartMenuEjectPC", "NoStartMenuNetworkPlaces", "NoTrayContextMenu", "NoWindowsUpdate", #"NoViewContextMenu", # Mouse right clic #"StartMenuLogOff", ] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: for item in restrictions: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 1) win32api.RegCloseKey(key) # Enable to use of lnk file from share without popup path = r"%s\Software\Microsoft\Windows\CurrentVersion\Policies\Associations" % ( hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: win32api.RegSetValueEx(key, "ModRiskFileTypes", 0, win32con.REG_SZ, ".exe;.msi;.vbs") win32api.RegCloseKey(key) # start menu customization path = r"%s\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" % ( hiveName) restrictions = [ "Start_ShowRun", "StartMenuAdminTools", "Start_AdminToolsRoot" ] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: for item in restrictions: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 0) win32api.RegCloseKey(key) if self.profile is not None: # http://support.microsoft.com/kb/810869 # Do not show recycle bin path = r"%s\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" % ( hiveName) restrictions = ["{645FF040-5081-101B-9F08-00AA002F954E}"] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: for item in restrictions: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 1) win32api.RegCloseKey(key) path = r"%s\Software\Microsoft\Windows\CurrentVersion\Policies\System" % ( hiveName) restrictions = [ "DisableRegistryTools", "DisableTaskMgr", "DisableLockWorkstation", "NoDispCPL", ] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: for item in restrictions: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 1) win32api.RegCloseKey(key) # Remove Windows startup sound keys = [ "WindowsLogon", "WindowsLogoff", "SystemStart", # old Windows 2003, not used anymore in 2008 ] for k in keys: path = r"%s\AppEvents\Schemes\Apps\.Default\%s\.Current" % ( hiveName, k) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: win32api.RegSetValueEx(key, None, 0, win32con.REG_EXPAND_SZ, "") win32api.RegCloseKey(key) # Desktop customization path = r"%s\Control Panel\Desktop" % (hiveName) items = ["ScreenSaveActive", "ScreenSaverIsSecure"] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'" % (path)) else: for item in items: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 0) win32api.RegCloseKey(key) # Overwrite Active Setup: works partially try: Reg.UpdateActiveSetup(self.user.name, hiveName, r"Software\Microsoft\Active Setup") # On 64 bits architecture, Active Setup is already present in path "Software\Wow6432Node\Microsoft\Active Setup" if "PROGRAMW6432" in os.environ.keys(): Reg.UpdateActiveSetup( self.user.name, hiveName, r"Software\Wow6432Node\Microsoft\Active Setup") except Exception, err: Logger.warn("Unable to reset ActiveSetup") Logger.debug("Unable to reset ActiveSetup: " + str(err))
def overwriteDefaultRegistry(self, directory): registryFile = os.path.join(directory, "NTUSER.DAT") hiveName = "OVD_%s_%d"%(str(self.id), random.randrange(10000, 50000)) # Load the hive win32api.RegLoadKey(win32con.HKEY_USERS, hiveName, registryFile) # Set the OVD Environnment path = r"%s\Environment"%(hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) hkey = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: hkey = None if hkey is None: Logger.error("Unable to open key '%s'"%(path)) else: win32api.RegSetValueEx(hkey, "OVD_SESSION_DIR", 0, win32con.REG_SZ, self.user_session_dir) win32api.RegCloseKey(hkey) # Set the language if self.parameters.has_key("locale"): cl = Langs.getLCID(self.parameters["locale"]) wl = Langs.unixLocale2WindowsLocale(self.parameters["locale"]) path = r"%s\Control Panel\Desktop"%(hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) hkey = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: hkey = None if hkey is None: Logger.error("Unable to open key '%s'"%(path)) else: win32api.RegSetValueEx(hkey, "MUILanguagePending", 0, win32con.REG_SZ, "%08X"%(cl)) win32api.RegSetValueEx(hkey, "PreferredUILanguagesPending", 0, win32con.REG_MULTI_SZ, [wl]) win32api.RegCloseKey(hkey) # Policies update path = r"%s\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"%(hiveName) restrictions = ["DisableFavoritesDirChange", "DisableLocalMachineRun", "DisableLocalMachineRunOnce", "DisableMachineRunOnce", "DisableMyMusicDirChange", "DisableMyPicturesDirChange", "DisablePersonalDirChange", "EnforceShellExtensionSecurity", #"ForceStartMenuLogOff", "Intellimenus", "NoChangeStartMenu", "NoClose", "NoCommonGroups", "NoControlPanel", "NoDFSTab", "NoFind", "NoFolderOptions", "NoHardwareTab", "NoInstrumentation", "NoIntellimenus", "NoInternetIcon", # remove the IE icon "NoManageMyComputerVerb", "NonEnum", "NoNetworkConnections", "NoResolveSearch", "NoSetFolders", "NoSetTaskbar", #"NoStartMenuSubFolders", # should remove the folders from startmenu but doesn't work + On 2008, start menu is empty if this key is set "NoSMBalloonTip", "NoStartMenuEjectPC", "NoStartMenuNetworkPlaces", "NoTrayContextMenu", "NoWindowsUpdate", #"NoViewContextMenu", # Mouse right clic #"StartMenuLogOff", ] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'"%(path)) else: for item in restrictions: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 1) win32api.RegCloseKey(key) # Hide local drives value = 0 drives = win32api.GetLogicalDriveStrings() drives = drives.split('\000')[:-1] for drive in drives: t = win32file.GetDriveType(drive) if t not in [win32con.DRIVE_CDROM, win32con.DRIVE_REMOVABLE, win32con.DRIVE_FIXED]: continue # Transform the drive letter into a bit value according to # http://technet.microsoft.com/en-us/library/cc959437.aspx value += 1 << (ord(drive.lower()[0]) - 97) path = r"%s\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"%(hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'"%(path)) else: win32api.RegSetValueEx(key, "NoDrives", 0, win32con.REG_DWORD, value) # win32api.RegSetValueEx(key, "NoViewOnDrive", 0, win32con.REG_DWORD, value) win32api.RegCloseKey(key) # Enable to use of lnk file from share without popup path = r"%s\Software\Microsoft\Windows\CurrentVersion\Policies\Associations"%(hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'"%(path)) else: win32api.RegSetValueEx(key, "ModRiskFileTypes", 0, win32con.REG_SZ, ".exe;.msi;.vbs") win32api.RegCloseKey(key) # start menu customization path = r"%s\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"%(hiveName) restrictions = ["Start_ShowRun", "StartMenuAdminTools", "Start_AdminToolsRoot"] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'"%(path)) else: for item in restrictions: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 0) win32api.RegCloseKey(key) if self.profile is not None: # http://support.microsoft.com/kb/810869 # Do not show recycle bin path = r"%s\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel"%(hiveName) restrictions = ["{645FF040-5081-101B-9F08-00AA002F954E}"] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'"%(path)) else: for item in restrictions: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 1) win32api.RegCloseKey(key) path = r"%s\Software\Microsoft\Windows\CurrentVersion\Policies\System"%(hiveName) restrictions = ["DisableRegistryTools", "DisableTaskMgr", "DisableLockWorkstation", "NoDispCPL", ] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'"%(path)) else: for item in restrictions: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 1) win32api.RegCloseKey(key) # Remove Windows startup sound keys = ["WindowsLogon", "WindowsLogoff", "SystemStart", # old Windows 2003, not used anymore in 2008 ] for k in keys: path = r"%s\AppEvents\Schemes\Apps\.Default\%s\.Current"%(hiveName, k) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'"%(path)) else: win32api.RegSetValueEx(key, None, 0, win32con.REG_EXPAND_SZ, "") win32api.RegCloseKey(key) # Desktop customization path = r"%s\Control Panel\Desktop"%(hiveName) items = ["ScreenSaveActive", "ScreenSaverIsSecure"] try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'"%(path)) else: for item in items: win32api.RegSetValueEx(key, item, 0, win32con.REG_DWORD, 0) win32api.RegCloseKey(key) # Overwrite Active Setup: works partially try: Reg.UpdateActiveSetup(self.user.name, hiveName, r"Software\Microsoft\Active Setup") # On 64 bits architecture, Active Setup is already present in path "Software\Wow6432Node\Microsoft\Active Setup" if "PROGRAMW6432" in os.environ.keys(): Reg.UpdateActiveSetup(self.user.name, hiveName, r"Software\Wow6432Node\Microsoft\Active Setup") except Exception: Logger.exception("Unable to reset ActiveSetup") if self.profile is not None: self.profile.overrideRegistry(hiveName, self.user.name) self.domain.doCustomizeRegistry(hiveName) # Timezone override if self.parameters.has_key("timezone"): tz_name = Langs.getWinTimezone(self.parameters["timezone"]) ret = Reg.setTimezone(hiveName, tz_name) if ret is False: Logger.warn("Unable to set TimeZone (%s, %s)"%(self.parameters["timezone"], tz_name)) # Hack for Windows 2012R2 relative to StartScreen integration. path = r"%s\Software\Microsoft\Windows\CurrentVersion\Explorer\StartPage"%(hiveName) try: Reg.CreateKeyR(win32con.HKEY_USERS, path) key = win32api.RegOpenKey(win32con.HKEY_USERS, path, 0, win32con.KEY_SET_VALUE) except: key = None if key is None: Logger.error("Unable to open key '%s'"%(path)) else: win32api.RegSetValueEx(key, "MakeAllAppsDefault", 0, win32con.REG_DWORD, 1) win32api.RegCloseKey(key) # Unload the hive win32api.RegUnLoadKey(win32con.HKEY_USERS, hiveName)