IWDFRemoteTarget::OpenFileByName method

[Warning: UMDF 2 is the latest version of UMDF and supersedes UMDF 1. All new UMDF drivers should be written using UMDF 2. No new features are being added to UMDF 1 and there is limited support for UMDF 1 on newer versions of Windows 10. Universal Windows drivers must use UMDF 2. For more info, see Getting Started with UMDF.]

The OpenFileByName method opens a remote I/O target that is a file.


HRESULT OpenFileByName(
  [in]           PCWSTR                      pszFileName,
  [in]           DWORD                       DesiredAccess,
  [in, optional] PUMDF_IO_TARGET_OPEN_PARAMS pOpenParams


pszFileName [in]

A pointer to a caller-supplied, null-terminated string that represents the name of the file to open. For more information about this member, see the FileName parameter of CreateFile in the Windows SDK.

DesiredAccess [in]

A bitmask that specifies the caller's desired access to the file. For more information about this member, see the dwDesiredAccess parameter of CreateFile in the Windows SDK.

pOpenParams [in, optional]

A pointer to a caller-allocated UMDF_IO_TARGET_OPEN_PARAMS structure that contains additional parameters. This parameter is optional and can be NULL.

Return value

OpenFileByName returns S_OK if the operation succeeds. Otherwise, the method might return the following value:

Return codeDescription

The framework's attempt to allocate memory failed.


This method might return one of the other values that Winerror.h contains.

The framework's verifier reports an error if the framework cannot open the file.


Your driver can use OpenFileByName to open a file, if the driver stack to which your driver belongs does not support the file's device. Use IWDFFileHandleTargetFactory::CreateFileHandleTarget to open a file, if the driver stack to which your driver belongs does support the file's device.

The specified file must be accessible by the account that loaded the UMDF-based driver, which is typically the Local Service account. However, if the driver uses impersonation when it calls OpenFileByName, the file must be accessible by the impersonated account.

Do not call OpenFileByName to open a remote target to a control device object. Instead, open the control device directly by calling CreateFile.

For more information about the OpenFileByName method and remote I/O targets, see General I/O Targets in UMDF.


The following code example creates a remote target object and opens an existing file with read-only access.


// Create a new remote target object and provide a callback 
// object to handle remote target events.
CComPtr<IWDFRemoteTarget> fxTarget;
hr = FxDevice->CreateRemoteTarget(MyRemoteTargetIUnknown,
if (FAILED(hr)) goto Error;

// Open existing file for read-only access.
openParams.dwShareMode = 0;
openParams.dwCreationDisposition = OPEN_EXISTING;
openParams.dwFlagsAndAttributes = FILE_ATTRIBUTE_READONLY;

hr = fxTarget->OpenFileByName(FILE_PATH,


Target platform


End of support

Unavailable in UMDF 2.0 and later.

Minimum UMDF version



Wudfddi.h (include Wudfddi.h)



See also




Send comments about this topic to Microsoft