def get_system_time(): ''' Get the system time. Returns: str: Returns the system time in HH:MM:SS AM/PM format. CLI Example: .. code-block:: bash salt 'minion-id' system.get_system_time ''' now = win32api.GetLocalTime() meridian = 'AM' hours = int(now[4]) if hours == 12: meridian = 'PM' elif hours == 0: hours = 12 elif hours > 12: hours = hours - 12 meridian = 'PM' return '{0:02d}:{1:02d}:{2:02d} {3}'.format(hours, now[5], now[6], meridian)
def get_system_time(): """ Get the system time. Returns: str: Returns the system time in HH:MM:SS AM/PM format. CLI Example: .. code-block:: bash salt 'minion-id' system.get_system_time """ now = win32api.GetLocalTime() meridian = "AM" hours = int(now[4]) if hours == 12: meridian = "PM" elif hours == 0: hours = 12 elif hours > 12: hours = hours - 12 meridian = "PM" return "{0:02d}:{1:02d}:{2:02d} {3}".format(hours, now[5], now[6], meridian)
def set_system_date_time(years=None, months=None, days=None, hours=None, minutes=None, seconds=None): ''' Set the system date and time. Each argument is an element of the date, but not required. If an element is not passed, the current system value for that element will be used. For example, if you don't pass the year, the current system year will be used. (Used by set_system_date and set_system_time) Args: years (int): Years digit, ie: 2015 months (int): Months digit: 1 - 12 days (int): Days digit: 1 - 31 hours (int): Hours digit: 0 - 23 minutes (int): Minutes digit: 0 - 59 seconds (int): Seconds digit: 0 - 59 Returns: bool: ``True`` if successful, otherwise ``False`` CLI Example: .. code-block:: bash salt '*' system.set_system_date_ time 2015 5 12 11 37 53 ''' # Get the current date/time try: date_time = win32api.GetLocalTime() except win32api.error as exc: (number, context, message) = exc log.error('Failed to get local time') log.error('nbr: {0}'.format(number)) log.error('ctx: {0}'.format(context)) log.error('msg: {0}'.format(message)) return False # Check for passed values. If not passed, use current values if years is None: years = date_time[0] if months is None: months = date_time[1] if days is None: days = date_time[3] if hours is None: hours = date_time[4] if minutes is None: minutes = date_time[5] if seconds is None: seconds = date_time[6] try: class SYSTEMTIME(ctypes.Structure): _fields_ = [('wYear', ctypes.c_int16), ('wMonth', ctypes.c_int16), ('wDayOfWeek', ctypes.c_int16), ('wDay', ctypes.c_int16), ('wHour', ctypes.c_int16), ('wMinute', ctypes.c_int16), ('wSecond', ctypes.c_int16), ('wMilliseconds', ctypes.c_int16)] system_time = SYSTEMTIME() system_time.wYear = int(years) system_time.wMonth = int(months) system_time.wDay = int(days) system_time.wHour = int(hours) system_time.wMinute = int(minutes) system_time.wSecond = int(seconds) system_time_ptr = ctypes.pointer(system_time) succeeded = ctypes.windll.kernel32.SetLocalTime(system_time_ptr) if succeeded is not 0: return True else: log.error('Failed to set local time') raise CommandExecutionError( win32api.FormatMessage(succeeded).rstrip()) except OSError as err: log.error('Failed to set local time') raise CommandExecutionError(err)
def set_system_date_time(years=None, months=None, days=None, hours=None, minutes=None, seconds=None): ''' Set the system date and time. Each argument is an element of the date, but not required. If an element is not passed, the current system value for that element will be used. For example, if you don't pass the year, the current system year will be used. (Used by set_system_date and set_system_time) :param int years: Years digit, ie: 2015 :param int months: Months digit: 1 - 12 :param int days: Days digit: 1 - 31 :param int hours: Hours digit: 0 - 23 :param int minutes: Minutes digit: 0 - 59 :param int seconds: Seconds digit: 0 - 59 :return: True if successful. Otherwise False. :rtype: bool CLI Example: .. code-block:: bash salt '*' system.set_system_date_ time 2015 5 12 11 37 53 ''' # Get the current date/time try: date_time = win32api.GetLocalTime() except win32api.error as exc: (number, context, message) = exc log.error('Failed to get local time') log.error('nbr: {0}'.format(number)) log.error('ctx: {0}'.format(context)) log.error('msg: {0}'.format(message)) return False # Check for passed values. If not passed, use current values if not years: years = date_time[0] if not months: months = date_time[1] if not days: days = date_time[3] if not hours: hours = date_time[4] if not minutes: minutes = date_time[5] if not seconds: seconds = date_time[6] # Create the time tuple to be passed to SetLocalTime, including day_of_week time_tuple = (years, months, days, hours, minutes, seconds, 0) try: win32api.SetLocalTime(time_tuple) except win32api.error as exc: (number, context, message) = exc log.error('Failed to set local time') log.error('nbr: {0}'.format(number)) log.error('ctx: {0}'.format(context)) log.error('msg: {0}'.format(message)) return False return True
def test_1_min(self): local_time = win32api.GetLocalTime() set_time._win_set_time(60) local_time2 = win32api.GetLocalTime() #print('Time 1: ' +str(local_time) + '\nTime 2' + str(local_time2)) self.assertEqual(local_time[5] + 1, local_time2[5])
import win32con as con for disk in "CDEF": F = api.GetDiskFreeSpace(disk + ":") rest = F[0] * F[1] * F[2] / 1e9 total = F[0] * F[1] * F[3] / 1e9 print("Rest:", rest, "G", "Total:", total, "G") print(api.GetComputerName()) print(api.GetConsoleTitle()) print(api.GetCommandLine()) print(api.GetCursorPos()) print(api.GetDomainName()) print(api.GetEnvironmentVariable('path')) print(api.GetFileAttributes('.')) print(api.GetFileVersionInfo('C:\\windows\\system32\\cmd.exe', "\\")) print(api.GetFullPathName('.')) print(api.GetLocalTime()) print(api.GetLogicalDriveStrings().replace('\x00', ' ')) print(api.GetLogicalDrives()) print(api.GetLongPathName('C:')) print(api.GetModuleFileName(0)) print(api.GetNativeSystemInfo()) print(hex(api.GetSysColor(con.COLOR_WINDOW))) print(api.GetSystemDirectory()) print(api.GetSystemInfo()) print(api.GetSystemMetrics(con.SM_CXSCREEN)) print(api.GetSystemTime()) print(api.GetTickCount()) # print(api.GetTimeZoneInformation()) print(api.GetUserDefaultLangID()) print(api.GetUserName()) print(api.GetVersion())