本文整理汇总了Python中ctypes.WinError方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.WinError方法的具体用法?Python ctypes.WinError怎么用?Python ctypes.WinError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes
的用法示例。
在下文中一共展示了ctypes.WinError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _is_gui_available
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def _is_gui_available():
UOI_FLAGS = 1
WSF_VISIBLE = 0x0001
class USEROBJECTFLAGS(ctypes.Structure):
_fields_ = [("fInherit", ctypes.wintypes.BOOL),
("fReserved", ctypes.wintypes.BOOL),
("dwFlags", ctypes.wintypes.DWORD)]
dll = ctypes.windll.user32
h = dll.GetProcessWindowStation()
if not h:
raise ctypes.WinError()
uof = USEROBJECTFLAGS()
needed = ctypes.wintypes.DWORD()
res = dll.GetUserObjectInformationW(h,
UOI_FLAGS,
ctypes.byref(uof),
ctypes.sizeof(uof),
ctypes.byref(needed))
if not res:
raise ctypes.WinError()
return bool(uof.dwFlags & WSF_VISIBLE)
示例2: _create_windows
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def _create_windows(source, destination, link_type):
"""Creates hardlink at destination from source in Windows."""
if link_type == HARDLINK:
import ctypes
from ctypes.wintypes import BOOL
CreateHardLink = ctypes.windll.kernel32.CreateHardLinkW
CreateHardLink.argtypes = [
ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_void_p
]
CreateHardLink.restype = BOOL
res = CreateHardLink(destination, source, None)
if res == 0:
raise ctypes.WinError()
else:
raise NotImplementedError("Link type unrecognized.")
示例3: enum_pids
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def enum_pids():
max_array = c_ulong * 4096 # define long array to capture all the processes
pProcessIds = max_array() # array to store the list of processes
pBytesReturned = c_ulong() # the number of bytes returned in the array
#EnumProcess
res = EnumProcesses(
ctypes.byref(pProcessIds),
ctypes.sizeof(pProcessIds),
ctypes.byref(pBytesReturned)
)
if res == 0:
logging.error(WinError(get_last_error()))
return []
# get the number of returned processes
nReturned = int(pBytesReturned.value/ctypes.sizeof(c_ulong()))
return [i for i in pProcessIds[:nReturned]]
#https://msdn.microsoft.com/en-us/library/windows/desktop/ms683217(v=vs.85).aspx
示例4: enum_process_names
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def enum_process_names():
pid_to_name = {}
for pid in enum_pids():
pid_to_name[pid] = 'Not found'
process_handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, False, pid)
if process_handle is None:
logging.debug('[Enum Processes]Failed to open process PID: %d Reason: %s ' % (pid, WinError(get_last_error())))
continue
image_name = (ctypes.c_char*MAX_PATH)()
max_path = DWORD(4096)
#res = GetProcessImageFileName(process_handle, image_name, MAX_PATH)
res = QueryFullProcessImageName(process_handle, 0 ,image_name, ctypes.byref(max_path))
if res == 0:
logging.debug('[Enum Proceses]Failed GetProcessImageFileName on PID: %d Reason: %s ' % (pid, WinError(get_last_error())))
continue
pid_to_name[pid] = image_name.value.decode()
return pid_to_name
示例5: hide_file
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def hide_file(path):
"""
Set the hidden attribute on a file or directory.
From http://stackoverflow.com/questions/19622133/
`path` must be text.
"""
__import__('ctypes.wintypes')
SetFileAttributes = ctypes.windll.kernel32.SetFileAttributesW
SetFileAttributes.argtypes = ctypes.wintypes.LPWSTR, ctypes.wintypes.DWORD
SetFileAttributes.restype = ctypes.wintypes.BOOL
FILE_ATTRIBUTE_HIDDEN = 0x02
ret = SetFileAttributes(path, FILE_ATTRIBUTE_HIDDEN)
if not ret:
raise ctypes.WinError()
示例6: EnumWindows
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def EnumWindows():
_EnumWindows = windll.user32.EnumWindows
_EnumWindows.argtypes = [WNDENUMPROC, LPARAM]
_EnumWindows.restype = bool
EnumFunc = __EnumWndProc()
lpEnumFunc = WNDENUMPROC(EnumFunc)
if not _EnumWindows(lpEnumFunc, NULL):
errcode = GetLastError()
if errcode not in (ERROR_NO_MORE_FILES, ERROR_SUCCESS):
raise ctypes.WinError(errcode)
return EnumFunc.hwnd
# BOOL CALLBACK EnumChildProc(
# HWND hwnd,
# LPARAM lParam
# );
示例7: EnumChildWindows
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def EnumChildWindows(hWndParent=NULL):
_EnumChildWindows = windll.user32.EnumChildWindows
_EnumChildWindows.argtypes = [HWND, WNDENUMPROC, LPARAM]
_EnumChildWindows.restype = bool
EnumFunc = __EnumChildProc()
lpEnumFunc = WNDENUMPROC(EnumFunc)
SetLastError(ERROR_SUCCESS)
_EnumChildWindows(hWndParent, lpEnumFunc, NULL)
errcode = GetLastError()
if errcode != ERROR_SUCCESS and errcode not in \
(ERROR_NO_MORE_FILES, ERROR_SUCCESS):
raise ctypes.WinError(errcode)
return EnumFunc.hwnd
# int WINAPI GetWindowText(
# __in HWND hWnd,
# __out LPTSTR lpString,
# __in int nMaxCount
# );
示例8: GetWindowTextA
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def GetWindowTextA(hWnd):
_GetWindowTextA = windll.user32.GetWindowTextA
_GetWindowTextA.argtypes = [HWND, LPSTR, ctypes.c_int]
_GetWindowTextA.restype = ctypes.c_int
nMaxCount = 0x1000
dwCharSize = sizeof(CHAR)
while 1:
lpString = ctypes.create_string_buffer(nMaxCount)
nCount = _GetWindowTextA(hWnd, lpString, nMaxCount)
if nCount == 0:
raise ctypes.WinError()
if nCount < nMaxCount - dwCharSize:
break
nMaxCount += 0x1000
return str(lpString.value)
示例9: GetWindowTextW
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def GetWindowTextW(hWnd):
_GetWindowTextW = windll.user32.GetWindowTextW
_GetWindowTextW.argtypes = [HWND, LPWSTR, ctypes.c_int]
_GetWindowTextW.restype = ctypes.c_int
nMaxCount = 0x1000
dwCharSize = sizeof(CHAR)
while 1:
lpString = ctypes.create_string_buffer(nMaxCount)
nCount = _GetWindowTextW(hWnd, lpString, nMaxCount)
if nCount == 0:
raise ctypes.WinError()
if nCount < nMaxCount - dwCharSize:
break
nMaxCount += 0x1000
return str(lpString.value)
示例10: GetClassNameA
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def GetClassNameA(hWnd):
_GetClassNameA = windll.user32.GetClassNameA
_GetClassNameA.argtypes = [HWND, LPSTR, ctypes.c_int]
_GetClassNameA.restype = ctypes.c_int
nMaxCount = 0x1000
dwCharSize = sizeof(CHAR)
while 1:
lpClassName = ctypes.create_string_buffer(nMaxCount)
nCount = _GetClassNameA(hWnd, lpClassName, nMaxCount)
if nCount == 0:
raise ctypes.WinError()
if nCount < nMaxCount - dwCharSize:
break
nMaxCount += 0x1000
return str(lpClassName.value)
示例11: QueryValueEx
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def QueryValueEx(key, value_name):
"""This calls the Windows QueryValueEx function in a Unicode safe way."""
size = 256
data_type = ctypes.wintypes.DWORD()
while True:
tmp_size = ctypes.wintypes.DWORD(size)
buf = ctypes.create_string_buffer(size)
rc = RegQueryValueEx(key.handle, value_name, LPDWORD(),
ctypes.byref(data_type), ctypes.cast(buf, LPBYTE),
ctypes.byref(tmp_size))
if rc != ERROR_MORE_DATA:
break
# We limit the size here to ~10 MB so the response doesn't get too big.
if size > 10 * 1024 * 1024:
raise WindowsError("Value too big to be read.")
size *= 2
if rc != ERROR_SUCCESS:
raise ctypes.WinError(2)
return (Reg2Py(buf, tmp_size.value, data_type.value), data_type.value)
示例12: get_windows_env_var
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def get_windows_env_var(key):
"""Get an env var.
Raises:
WindowsError
"""
if not isinstance(key, text_type):
raise TypeError("%r not of type %r" % (key, text_type))
buf = ctypes.create_unicode_buffer(32767)
stored = winapi.GetEnvironmentVariableW(key, buf, 32767)
if stored == 0:
raise ctypes.WinError()
return buf[:stored]
示例13: set_windows_env_var
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def set_windows_env_var(key, value):
"""Set an env var.
Raises:
WindowsError
"""
if not isinstance(key, text_type):
raise TypeError("%r not of type %r" % (key, text_type))
if not isinstance(value, text_type):
raise TypeError("%r not of type %r" % (value, text_type))
status = winapi.SetEnvironmentVariableW(key, value)
if status == 0:
raise ctypes.WinError()
示例14: _terminal_size
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def _terminal_size(handle):
csbi = CONSOLE_SCREEN_BUFFER_INFO()
if not WINAPI._GetConsoleScreenBufferInfo(handle, byref(csbi)):
raise ctypes.WinError() # Subclass of OSError.
else:
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1
rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1
return columns, rows
示例15: _check_count
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import WinError [as 别名]
def _check_count(result, func, args):
if result == 0:
raise ctypes.WinError(ctypes.get_last_error())
return args