当前位置: 首页>>代码示例>>Python>>正文


Python win32file.CreateFile方法代码示例

本文整理汇总了Python中win32file.CreateFile方法的典型用法代码示例。如果您正苦于以下问题:Python win32file.CreateFile方法的具体用法?Python win32file.CreateFile怎么用?Python win32file.CreateFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32file的用法示例。


在下文中一共展示了win32file.CreateFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [as 别名]
def __init__(self, filename):
        self._hfile = win32file.CreateFile(filename,
                                           win32con.GENERIC_READ | win32con.GENERIC_WRITE,
                                           win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
                                           win32security.SECURITY_ATTRIBUTES(),
                                           win32con.OPEN_EXISTING,
                                           win32con.FILE_FLAG_OVERLAPPED,
                                           0)
        self._read_ovrlpd = pywintypes.OVERLAPPED()
        self._read_ovrlpd.hEvent = win32event.CreateEvent(None, True,
                                                          False, None)
        self._write_ovrlpd = pywintypes.OVERLAPPED()
        self._write_ovrlpd.hEvent = win32event.CreateEvent(None, True,
                                                           False, None)
        self._bufs = []
        self._n = 0 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:18,代码来源:windows_support.py

示例2: _openHandle

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [as 别名]
def _openHandle(path, bWriteAccess, bWriteShare,
                logfunc = lambda s: None):
    TIMEOUT, NUM_RETRIES = 10, 20
    for retry_count in range(6):
        try:
            access_flag = win32con.GENERIC_READ | \
                          (bWriteAccess and win32con.GENERIC_WRITE or 0)
            share_flag = win32con.FILE_SHARE_READ | \
                         (bWriteShare and win32con.FILE_SHARE_WRITE or 0)
            handle = win32file.CreateFile(
                path, access_flag, share_flag, None,
                win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL, None)
            nth = { 0: 'first', 1:'second', 2:'third'}
            logfunc("Opening [%s]: success at the %s iteration" %
                    (path, nth.get(retry_count, '%sth' % (retry_count+1))))
            return handle
        except pywintypes.error as e:
            logfunc('Exception=>'+str(e))
            if NUM_RETRIES/3 < retry_count:
                bWriteShare = True
        time.sleep(TIMEOUT / float(NUM_RETRIES))
    else:
        raise RuntimeError("Couldn't open handle for %s." % path) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:25,代码来源:win32.py

示例3: _OpenFileForRead

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [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)) 
开发者ID:google,项目名称:rekall,代码行数:21,代码来源:win32.py

示例4: _OpenFileForWrite

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [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)) 
开发者ID:google,项目名称:rekall,代码行数:20,代码来源:win32.py

示例5: SimpleFileDemo

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [as 别名]
def SimpleFileDemo():
    testName = os.path.join( win32api.GetTempPath(), "win32file_demo_test_file")
    if os.path.exists(testName): os.unlink(testName)
    # Open the file for writing.
    handle = win32file.CreateFile(testName, 
                                  win32file.GENERIC_WRITE, 
                                  0, 
                                  None, 
                                  win32con.CREATE_NEW, 
                                  0, 
                                  None)
    test_data = "Hello\0there".encode("ascii")
    win32file.WriteFile(handle, test_data)
    handle.Close()
    # Open it for reading.
    handle = win32file.CreateFile(testName, win32file.GENERIC_READ, 0, None, win32con.OPEN_EXISTING, 0, None)
    rc, data = win32file.ReadFile(handle, 1024)
    handle.Close()
    if data == test_data:
        print "Successfully wrote and read a file"
    else:
        raise Exception("Got different data back???")
    os.unlink(testName) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:win32fileDemo.py

示例6: testTransactNamedPipeBlocking

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [as 别名]
def testTransactNamedPipeBlocking(self):
        event = threading.Event()
        self.startPipeServer(event)
        open_mode = win32con.GENERIC_READ | win32con.GENERIC_WRITE

        hpipe = win32file.CreateFile(self.pipename,
                                     open_mode,
                                     0, # no sharing
                                     None, # default security
                                     win32con.OPEN_EXISTING,
                                     0, # win32con.FILE_FLAG_OVERLAPPED,
                                     None)

        # set to message mode.
        win32pipe.SetNamedPipeHandleState(
                        hpipe, win32pipe.PIPE_READMODE_MESSAGE, None, None)

        hr, got = win32pipe.TransactNamedPipe(hpipe, str2bytes("foo\0bar"), 1024, None)
        self.failUnlessEqual(got, str2bytes("bar\0foo"))
        event.wait(5)
        self.failUnless(event.isSet(), "Pipe server thread didn't terminate") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_win32pipe.py

示例7: testTransactNamedPipeBlockingBuffer

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [as 别名]
def testTransactNamedPipeBlockingBuffer(self):
        # Like testTransactNamedPipeBlocking, but a pre-allocated buffer is
        # passed (not really that useful, but it exercises the code path)
        event = threading.Event()
        self.startPipeServer(event)
        open_mode = win32con.GENERIC_READ | win32con.GENERIC_WRITE

        hpipe = win32file.CreateFile(self.pipename,
                                     open_mode,
                                     0, # no sharing
                                     None, # default security
                                     win32con.OPEN_EXISTING,
                                     0, # win32con.FILE_FLAG_OVERLAPPED,
                                     None)

        # set to message mode.
        win32pipe.SetNamedPipeHandleState(
                        hpipe, win32pipe.PIPE_READMODE_MESSAGE, None, None)

        buffer = win32file.AllocateReadBuffer(1024)
        hr, got = win32pipe.TransactNamedPipe(hpipe, str2bytes("foo\0bar"), buffer, None)
        self.failUnlessEqual(got, str2bytes("bar\0foo"))
        event.wait(5)
        self.failUnless(event.isSet(), "Pipe server thread didn't terminate") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_win32pipe.py

示例8: testSimpleFiles

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [as 别名]
def testSimpleFiles(self):
        try:
            fd, filename = tempfile.mkstemp()
        except AttributeError:
            self.fail("This test requires Python 2.3 or later")
        os.close(fd)
        os.unlink(filename)
        handle = win32file.CreateFile(filename, win32file.GENERIC_WRITE, 0, None, win32con.CREATE_NEW, 0, None)
        test_data = str2bytes("Hello\0there")
        try:
            win32file.WriteFile(handle, test_data)
            handle.Close()
            # Try and open for read
            handle = win32file.CreateFile(filename, win32file.GENERIC_READ, 0, None, win32con.OPEN_EXISTING, 0, None)
            rc, data = win32file.ReadFile(handle, 1024)
            self.assertEquals(data, test_data)
        finally:
            handle.Close()
            try:
                os.unlink(filename)
            except os.error:
                pass

    # A simple test using normal read/write operations. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_win32file.py

示例9: setUp

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_win32file.py

示例10: CopyFileToCe

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [as 别名]
def CopyFileToCe(src_name, dest_name, progress = None):
    sh = win32file.CreateFile(src_name, win32con.GENERIC_READ, 0, None, win32con.OPEN_EXISTING, 0, None)
    bytes=0
    try:
        dh = wincerapi.CeCreateFile(dest_name, win32con.GENERIC_WRITE, 0, None, win32con.OPEN_ALWAYS, 0, None)
        try:
            while 1:
                hr, data = win32file.ReadFile(sh, 2048)
                if not data:
                    break
                wincerapi.CeWriteFile(dh, data)
                bytes = bytes + len(data)
                if progress is not None: progress(bytes)
        finally:
            pass
            dh.Close()
    finally:
        sh.Close()
    return bytes 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:pysynch.py

示例11: open

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [as 别名]
def open(self, name):
        """
        Direct open devices.

        :param name: Port name.
        :return: 0 on success
        """
        path = self.ports[name]['path']
        try:
            self.files[path] = win32file.CreateFile(path,
                                                    win32file.GENERIC_WRITE |
                                                    win32file.GENERIC_READ,
                                                    0,
                                                    None,
                                                    win32file.OPEN_EXISTING,
                                                    win32file.FILE_ATTRIBUTE_NORMAL,
                                                    None)
        except win32file.error as exc_detail:
            print("%s\nFAIL: Failed open file %s" % (str(exc_detail), name))
            return exc_detail
        print("PASS: All files opened correctly.") 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:23,代码来源:virtio_console_guest.py

示例12: CreateFile

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [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) 
开发者ID:kdart,项目名称:pycopia,代码行数:25,代码来源:WindowsServer.py

示例13: __init__

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [as 别名]
def __init__(self, path):
        if not isinstance(path, basestring):
            raise TypeError("Path argument must be a basestring; instead"
                            " received %r" % (path,))
        self.path = path
        self.handle = win32file.CreateFile(
             self.path,
             0x0001,  # FILE_LIST_DIRECTORY
             win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
             None,
             win32con.OPEN_EXISTING,
             win32con.FILE_FLAG_BACKUP_SEMANTICS | win32con.FILE_FLAG_OVERLAPPED,
             None,
            )
        self.overlapped = win32file.OVERLAPPED()
        self.overlapped.hEvent = win32event.CreateEvent(None, True, 0, None) 
开发者ID:t4ngo,项目名称:dragonfly,代码行数:18,代码来源:dirmon.py

示例14: connect

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [as 别名]
def connect(self):
            """Attempts to connect to the server, but does not block.

            @return: True if the channel is now connected.
            @rtype: bool
            """
            try:
                if win32pipe.WaitNamedPipe(self.__full_pipe_name, 10) != 0:
                    self.__pipe_handle = win32file.CreateFile(
                        self.__full_pipe_name,
                        win32file.GENERIC_READ,
                        0,
                        None,
                        win32file.OPEN_EXISTING,
                        0,
                        None,
                    )
                    return True
                else:
                    return False
            except pywintypes.error as e:
                if e[0] == winerror.ERROR_FILE_NOT_FOUND:
                    return False
                else:
                    raise e 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:27,代码来源:platform_windows.py

示例15: csv_export_ram

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import CreateFile [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) 
开发者ID:SekoiaLab,项目名称:Fastir_Collector,代码行数:25,代码来源:dump.py


注:本文中的win32file.CreateFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。