本文整理汇总了Python中win32file.FILE_SHARE_READ属性的典型用法代码示例。如果您正苦于以下问题:Python win32file.FILE_SHARE_READ属性的具体用法?Python win32file.FILE_SHARE_READ怎么用?Python win32file.FILE_SHARE_READ使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类win32file
的用法示例。
在下文中一共展示了win32file.FILE_SHARE_READ属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _OpenFileForRead
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_SHARE_READ [as 别名]
def _OpenFileForRead(self, path):
try:
fhandle = self.fhandle = win32file.CreateFile(
path,
win32file.GENERIC_READ,
win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
None,
win32file.OPEN_EXISTING,
win32file.FILE_ATTRIBUTE_NORMAL,
None)
self._closer = weakref.ref(
self, lambda x: win32file.CloseHandle(fhandle))
self.write_enabled = False
return fhandle
except pywintypes.error as e:
raise IOError("Unable to open %s: %s" % (path, e))
示例2: _OpenFileForWrite
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_SHARE_READ [as 别名]
def _OpenFileForWrite(self, path):
try:
fhandle = self.fhandle = win32file.CreateFile(
path,
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
None,
win32file.OPEN_EXISTING,
win32file.FILE_ATTRIBUTE_NORMAL,
None)
self.write_enabled = True
self._closer = weakref.ref(
self, lambda x: win32file.CloseHandle(fhandle))
return fhandle
except pywintypes.error as e:
raise IOError("Unable to open %s: %s" % (path, e))
示例3: setUp
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_SHARE_READ [as 别名]
def setUp(self):
self.watcher_threads = []
self.watcher_thread_changes = []
self.dir_names = []
self.dir_handles = []
for i in range(self.num_test_dirs):
td = tempfile.mktemp("-test-directory-changes-%d" % i)
os.mkdir(td)
self.dir_names.append(td)
hdir = win32file.CreateFile(td,
ntsecuritycon.FILE_LIST_DIRECTORY,
win32con.FILE_SHARE_READ,
None, # security desc
win32con.OPEN_EXISTING,
win32con.FILE_FLAG_BACKUP_SEMANTICS |
win32con.FILE_FLAG_OVERLAPPED,
None)
self.dir_handles.append(hdir)
changes = []
t = threading.Thread(target=self._watcherThreadOverlapped,
args=(td, hdir, changes))
t.start()
self.watcher_threads.append(t)
self.watcher_thread_changes.append(changes)
示例4: CreateFile
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_SHARE_READ [as 别名]
def CreateFile(self, fname, mode="r", bufsize=-1):
"Open a file the same way a File Directory migration engine would."
fname = cygwin2nt(fname)
UserLog.msg("CreateFile", fname)
if mode == "r":
wmode = win32file.GENERIC_READ
elif mode == "w":
wmode = win32file.GENERIC_WRITE
elif mode in ( 'r+', 'w+', 'a+'):
wmode = win32file.GENERIC_READ | win32file.GENERIC_WRITE
else:
raise ValueError, "invalid file mode"
h = win32file.CreateFile(
fname, # CTSTR lpFileName,
wmode, # DWORD dwDesiredAccess,
win32file.FILE_SHARE_DELETE | win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE, # DWORD dwShareMode,
None, # LPSECURITY_ATTRIBUTES lpSecurityAttributes,
win32file.OPEN_EXISTING, # DWORD dwCreationDisposition,
win32file.FILE_ATTRIBUTE_NORMAL, # DWORD dwFlagsAndAttributes,
0, # HANDLE hTemplateFile
)
self._files[int(h)] = h
return int(h)
示例5: csv_export_ram
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_SHARE_READ [as 别名]
def csv_export_ram(self):
"""Dump ram using winpmem"""
hSvc = create_driver_service(self.logger)
start_service(hSvc, self.logger)
try:
fd = win32file.CreateFile(
"\\\\.\\pmem",
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
None,
win32file.OPEN_EXISTING,
win32file.FILE_ATTRIBUTE_NORMAL,
None)
try:
t = time.time()
image = _Image(fd)
self.logger.info("Imaging to " + self.output_dir + '\\' + self.computer_name + '_memdump.raw')
image.DumpWithRead(self.output_dir + '\\' + self.computer_name + '_memdump.raw')
self.logger.info("Completed in %s seconds" % (time.time() - t))
finally:
win32file.CloseHandle(fd)
finally:
stop_and_delete_driver_service(hSvc)
示例6: win_tun_alloc
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_SHARE_READ [as 别名]
def win_tun_alloc(self, dev, flags):
TAP_IOCTL_SET_MEDIA_STATUS = self.WIN_TAP_CONTROL_CODE(6, 0)
import pywintypes
guid = self.WIN_get_device_guid()
if not guid:
common.internal_print("Please install OpenVPN's Windows TAP driver (NDIS 6) to use XFLTReaT\r\nhttps://openvpn.net/index.php/open-source/downloads.html", -1)
sys.exit(-1)
# create a win32file for manipulating the TUN/TAP interface
try:
self.wintun = win32file.CreateFile("\\\\.\\Global\\{0}.tap".format(guid),
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
None, win32file.OPEN_EXISTING,
win32file.FILE_ATTRIBUTE_SYSTEM | win32file.FILE_FLAG_NO_BUFFERING | win32file.FILE_FLAG_OVERLAPPED,
None)
except pywintypes.error as e:
if e.args[0] == 31: # A device attached to the system is not functioning.
common.internal_print("The TUN device is already in use. Maybe another XFLTReaT is running.", -1)
sys.exit(-1)
# have Windows consider the interface now connected
win32file.DeviceIoControl(self.wintun, TAP_IOCTL_SET_MEDIA_STATUS, '\x01\x00\x00\x00', 1, None)
return self.wintun
示例7: testMoreFiles
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_SHARE_READ [as 别名]
def testMoreFiles(self):
# Create a file in the %TEMP% directory.
testName = os.path.join( win32api.GetTempPath(), "win32filetest.dat" )
desiredAccess = win32file.GENERIC_READ | win32file.GENERIC_WRITE
# Set a flag to delete the file automatically when it is closed.
fileFlags = win32file.FILE_FLAG_DELETE_ON_CLOSE
h = win32file.CreateFile( testName, desiredAccess, win32file.FILE_SHARE_READ, None, win32file.CREATE_ALWAYS, fileFlags, 0)
# Write a known number of bytes to the file.
data = str2bytes("z") * 1025
win32file.WriteFile(h, data)
self.failUnless(win32file.GetFileSize(h) == len(data), "WARNING: Written file does not have the same size as the length of the data in it!")
# Ensure we can read the data back.
win32file.SetFilePointer(h, 0, win32file.FILE_BEGIN)
hr, read_data = win32file.ReadFile(h, len(data)+10) # + 10 to get anything extra
self.failUnless(hr==0, "Readfile returned %d" % hr)
self.failUnless(read_data == data, "Read data is not what we wrote!")
# Now truncate the file at 1/2 its existing size.
newSize = len(data)//2
win32file.SetFilePointer(h, newSize, win32file.FILE_BEGIN)
win32file.SetEndOfFile(h)
self.failUnlessEqual(win32file.GetFileSize(h), newSize)
# GetFileAttributesEx/GetFileAttributesExW tests.
self.failUnlessEqual(win32file.GetFileAttributesEx(testName), win32file.GetFileAttributesExW(testName))
attr, ct, at, wt, size = win32file.GetFileAttributesEx(testName)
self.failUnless(size==newSize,
"Expected GetFileAttributesEx to return the same size as GetFileSize()")
self.failUnless(attr==win32file.GetFileAttributes(testName),
"Expected GetFileAttributesEx to return the same attributes as GetFileAttributes")
h = None # Close the file by removing the last reference to the handle!
self.failUnless(not os.path.isfile(testName), "After closing the file, it still exists!")
示例8: get_physical_drive_size
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_SHARE_READ [as 别名]
def get_physical_drive_size(drive="\\\\.\\PhysicalDrive0"):
"""Uses IOCTL to get physical drives size"""
handle = win32file.CreateFile(drive, 0, win32file.FILE_SHARE_READ, None, win32file.OPEN_EXISTING, 0, 0)
if handle:
IOCTL_DISK_GET_DRIVE_GEOMETRY = 0x00070000
info = win32file.DeviceIoControl(handle, IOCTL_DISK_GET_DRIVE_GEOMETRY, '', 24)
win32file.CloseHandle(handle)
if info:
(cyl_lo, cyl_hi, media_type, tps, spt, bps) = struct.unpack('6L', info)
mediasize = ((cyl_hi << 32) + cyl_lo) * tps * spt * bps
"""print mediasize, 'bytes'
print mediasize/10**3, 'kbytes'
print mediasize/10**6, 'Mbytes'
print mediasize/10**9, 'Gbytes'"""
return mediasize
示例9: __init__
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_SHARE_READ [as 别名]
def __init__(self, base, config, **kwargs):
self.as_assert(base == None, 'Must be first Address Space')
addrspace.AbstractRunBasedMemory.__init__(self, base, config, **kwargs)
self.fhandle = win32file.CreateFile(
"\\\\.\\pmem",
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
None,
win32file.OPEN_EXISTING,
win32file.FILE_ATTRIBUTE_NORMAL,
None)
self.ParseMemoryRuns()
示例10: openTunTap
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_SHARE_READ [as 别名]
def openTunTap():
'''
\brief Open a TUN/TAP interface and switch it to TUN mode.
\return The handler of the interface, which can be used for later
read/write operations.
'''
# retrieve the ComponentId from the TUN/TAP interface
componentId = get_tuntap_ComponentId()
print('componentId = {0}'.format(componentId))
# create a win32file for manipulating the TUN/TAP interface
tuntap = win32file.CreateFile(
r'\\.\Global\%s.tap' % componentId,
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
None,
win32file.OPEN_EXISTING,
win32file.FILE_ATTRIBUTE_SYSTEM | win32file.FILE_FLAG_OVERLAPPED,
None
)
print('tuntap = {0}'.format(tuntap.handle))
# have Windows consider the interface now connected
win32file.DeviceIoControl(
tuntap,
TAP_IOCTL_SET_MEDIA_STATUS,
'\x00\x00\x00\x00',
None
)
# prepare the parameter passed to the TAP_IOCTL_CONFIG_TUN commmand.
# This needs to be a 12-character long string representing
# - the tun interface's IPv4 address (4 characters)
# - the tun interface's IPv4 network address (4 characters)
# - the tun interface's IPv4 network mask (4 characters)
configTunParam = []
configTunParam += TUN_IPv4_ADDRESS
configTunParam += TUN_IPv4_NETWORK
configTunParam += TUN_IPv4_NETMASK
configTunParam = ''.join([chr(b) for b in configTunParam])
# switch to TUN mode (by default the interface runs in TAP mode)
win32file.DeviceIoControl(
tuntap,
TAP_IOCTL_CONFIG_TUN,
configTunParam,
None
)
# return the handler of the TUN interface
return tuntap
#=== misc
示例11: open_sparse_file
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_SHARE_READ [as 别名]
def open_sparse_file(path, mode, length=0, overlapped=False):
supported = get_sparse_files_support(path)
flags = 0
# some day I might support sparse files elsewhere
if not supported and os.name != 'nt':
return file(path, mode, 0)
flags = win32file.FILE_FLAG_RANDOM_ACCESS
if overlapped:
flags |= win32file.FILE_FLAG_OVERLAPPED
# If the hFile handle is opened with the
# FILE_FLAG_NO_BUFFERING flag set, an application can move the
# file pointer only to sector-aligned positions. A
# sector-aligned position is a position that is a whole number
# multiple of the volume sector size. An application can
# obtain a volume sector size by calling the GetDiskFreeSpace
# function.
#flags |= win32file.FILE_FLAG_NO_BUFFERING
access = win32file.GENERIC_READ
# Shared write is necessary because lock is assigned
# per file handle. --Dave
share = win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE
#share = win32file.FILE_SHARE_READ #| win32file.FILE_SHARE_WRITE
if is_open_for_write(mode):
access |= win32file.GENERIC_WRITE
if isinstance(path, unicode):
CreateFile = win32file.CreateFileW
else:
CreateFile = win32file.CreateFile
handle = CreateFile(path, access, share, None,
win32file.OPEN_ALWAYS,
flags, None)
if supported and is_open_for_write(mode):
_sparse_magic(handle, length)
fd = win32file._open_osfhandle(handle, os.O_BINARY)
handle.Detach()
f = os.fdopen(fd, mode)
return f