- openfiles
- openfiles /disconnect
- Syntax
- Parameters
- Examples
- openfiles /query
- Syntax
- Parameters
- Examples
- openfiles /local
- Syntax
- Parameters
- Examples
- OpenFile function (winbase.h)
- Syntax
- Parameters
- Return value
- Remarks
- «Access Denied» or other errors when you access or work with files and folders in Windows
- Summary
- Resolution
openfiles
Enables an administrator to query, display, or disconnect files and directories that have been opened on a system. This command also enables or disables the system Maintain Objects List global flag.
openfiles /disconnect
Enables an administrator to disconnect files and folders that have been opened remotely through a shared folder.
Syntax
Parameters
Parameter | Description |
---|---|
/s | Specifies the remote system to connect to (by name or IP address). Don’t use backslashes. If you don’t use the /s option, the command is run on the local computer by default. This parameter applies to all files and folders that are specified in the command. |
/u [ \] | Runs the command using the permissions of the specified user account. If you don’t use the /u option, system permissions are used by default. |
/p [ |
]
Note: You can use the openfiles /query command to find the file ID.
Examples
To disconnect all open files with the file ID 26843578, type:
To disconnect all open files and directories accessed by the user hiropln, type:
To disconnect all open files and directories with read/write mode, type:
To disconnect the directory with the open file name *C:\testshare*, regardless of who is accessing it, type:
To disconnect all open files on the remote computer srvmain that are being accessed by the user hiropln, regardless of their ID, type:
openfiles /query
Queries and displays all open files.
Syntax
Parameters
Parameter | Description |
---|---|
/s | Specifies the remote system to connect to (by name or IP address). Don’t use backslashes. If you don’t use the /s option, the command is run on the local computer by default. This parameter applies to all files and folders that are specified in the command. |
/u [ \] | Runs the command using the permissions of the specified user account. If you don’t use the /u option, system permissions are used by default. |
/p [ |
]
Displays the output in the specified format. Valid values include:
| |
/nh | Suppresses column headers in the output. Valid only when the /fo parameter is set to TABLE or CSV. |
/v | Specifies that detailed (verbose) information be displayed in the output. |
/? | Displays help at the command prompt. |
Examples
To query and display all open files, type:
To query and display all open files in table format without headers, type:
To query and display all open files in list format with detailed information, type:
To query and display all open files on the remote system srvmain by using the credentials for the user hiropln on the maindom domain, type:
In this example, the password is supplied on the command line. To prevent displaying the password, leave out the /p option. You’ll be prompted for the password, which won’t be echoed to the screen.
openfiles /local
Enables or disables the system Maintain Objects List global flag. If used without parameters, openfiles /local displays the current status of the Maintain Objects List global flag.
Changes made by using the on or off option don’t take effect until you restart the system. Enabling the Maintain Objects List global flag might slow down your system.
Syntax
Parameters
Parameter | Description |
---|---|
[on | off] | Enables or disables the system Maintain Objects List global flag, which tracks local file handles. |
/? | Displays help at the command prompt. |
Examples
To check the current status of the Maintain Objects List global flag, type:
By default, the Maintain Objects List global flag is disabled, and the following message appears, INFO: The system global flag ‘maintain objects list’ is currently disabled.
To enable the Maintain Objects List global flag, type:
The following message appears when the global flag is enabled, SUCCESS: The system global flag ‘maintain objects list’ is enabled. This will take effect after the system is restarted.
To disable the Maintain Objects List global flag, type:
OpenFile function (winbase.h)
Creates, opens, reopens, or deletes a file.
Syntax
Parameters
The name of the file.
The string must consist of characters from the 8-bit Windows character set. The OpenFile function does not support Unicode file names or opening named pipes.
A pointer to the OFSTRUCT structure that receives information about a file when it is first opened.
The structure can be used in subsequent calls to the OpenFile function to see an open file.
The OFSTRUCT structure contains a path string member with a length that is limited to OFS_MAXPATHNAME characters, which is 128 characters. Because of this, you cannot use the OpenFile function to open a file with a path length that exceeds 128 characters. The CreateFile function does not have this path length limitation.
The action to be taken.
This parameter can be one or more of the following values.
Value | Meaning |
---|---|
OF_CANCEL 0x00000800 | Ignored. To produce a dialog box containing a Cancel button, use OF_PROMPT. |
OF_CREATE 0x00001000 | Creates a new file. If the file exists, it is truncated to zero (0) length. |
OF_DELETE 0x00000200 | Deletes a file. |
OF_EXIST 0x00004000 | Opens a file and then closes it. Use this to test for the existence of a file. |
OF_PARSE 0x00000100 | Fills the OFSTRUCT structure, but does not do anything else. |
OF_PROMPT 0x00002000 | Displays a dialog box if a requested file does not exist. A dialog box informs a user that the system cannot find a file, and it contains Retry and Cancel buttons. The Cancel button directs OpenFile to return a file-not-found error message. |
OF_READ 0x00000000 | Opens a file for reading only. |
OF_READWRITE 0x00000002 | Opens a file with read/write permissions. |
OF_REOPEN 0x00008000 | Opens a file by using information in the reopen buffer. |
OF_SHARE_COMPAT 0x00000000 | For MS-DOS–based file systems, opens a file with compatibility mode, allows any process on a specified computer to open the file any number of times. Other efforts to open a file with other sharing modes fail. This flag is mapped to the FILE_SHARE_READ|FILE_SHARE_WRITE flags of the CreateFile function. |
OF_SHARE_DENY_NONE 0x00000040 | Opens a file without denying read or write access to other processes. On MS-DOS-based file systems, if the file has been opened in compatibility mode by any other process, the function fails. This flag is mapped to the FILE_SHARE_READ|FILE_SHARE_WRITE flags of the CreateFile function. |
OF_SHARE_DENY_READ 0x00000030 | Opens a file and denies read access to other processes. On MS-DOS-based file systems, if the file has been opened in compatibility mode, or for read access by any other process, the function fails. This flag is mapped to the FILE_SHARE_WRITE flag of the CreateFile function. |
OF_SHARE_DENY_WRITE 0x00000020 | Opens a file and denies write access to other processes. On MS-DOS-based file systems, if a file has been opened in compatibility mode, or for write access by any other process, the function fails. This flag is mapped to the FILE_SHARE_READ flag of the CreateFile function. |
OF_SHARE_EXCLUSIVE 0x00000010 | Opens a file with exclusive mode, and denies both read/write access to other processes. If a file has been opened in any other mode for read/write access, even by the current process, the function fails. |
OF_VERIFY | Verifies that the date and time of a file are the same as when it was opened previously. This is useful as an extra check for read-only files. |
OF_WRITE 0x00000001 | Opens a file for write access only. |
Return value
If the function succeeds, the return value specifies a file handle to use when performing file I/O. To close the file, call the CloseHandle function using this handle.
If the function fails, the return value is HFILE_ERROR. To get extended error information, call GetLastError.
Remarks
If the lpFileName parameter specifies a file name and extension only, this function searches for a matching file in the following directories and the order shown:
- The directory where an application is loaded.
- The current directory.
- The Windows system directory.
Use the GetSystemDirectory function to get the path of this directory.
The 16-bit Windows system directory.
There is not a function that retrieves the path of this directory, but it is searched.
The Windows directory.
Use the GetWindowsDirectory function to get the path of this directory.
The lpFileName parameter cannot contain wildcard characters.
The OpenFile function does not support the OF_SEARCH flag that the 16-bit Windows OpenFile function supports. The OF_SEARCH flag directs the system to search for a matching file even when a file name includes a full path. Use the SearchPath function to search for a file.
A sharing violation occurs if an attempt is made to open a file or directory for deletion on a remote machine when the value of the uStyle parameter is the OF_DELETE access flag OR’ed with any other access flag, and the remote file or directory has not been opened with FILE_SHARE_DELETE share access. To avoid the sharing violation in this scenario, open the remote file or directory with OF_DELETE access only, or call DeleteFile without first opening the file or directory for deletion.
In WindowsВ 8 and Windows ServerВ 2012, this function is supported by the following technologies.
Technology | Supported |
---|---|
Server Message Block (SMB) 3.0 protocol | Yes |
SMB 3.0 Transparent Failover (TFO) | Yes |
SMB 3.0 with Scale-out File Shares (SO) | Yes |
Cluster Shared Volume File System (CsvFS) | Yes |
Resilient File System (ReFS) | Yes |
В
CsvFs will do redirected IO for compressed files.
«Access Denied» or other errors when you access or work with files and folders in Windows
Summary
When you try to access or work with files and folders in Windows, you experience one or more of the following issues:
Issue 1: You receive an «Access Denied» error message or a similar message.
Issue 2: You cannot access, change, save, or delete files and folders.
Issue 3: You cannot open a file or folder after you install a new version of Windows.
Resolution
To resolve a particular issue, follow the steps for the issue that best describes your situation. Use the method for your version of Windows.
Note You may not always receive an “Access Denied” error message for these kinds of issues. If particular steps do not resolve the issue, try a different set of steps.
Cause An «Access Denied» error message can occur for one or more of the following reasons:
The folder ownership has changed.
You do not have the appropriate permissions.
The file is encrypted.
You may not have ownership of a file or folder If you recently upgraded your computer to Windows 8 from an earlier version of Windows, some of your account information may have changed. Therefore, you may no longer have ownership of some files or folders. You might be able to resolve this issue by restoring your ownership of the files and folders.
To take ownership of a file or folder, follow these steps:
Press and hold the folder that you want to take ownership of, then tap Properties. (If you are using a mouse, right-click the folder, and then click Properties.)
Tap or click the Security tab, tap or click Advanced, then tap or click Change. If you are prompted for an administrator password or for confirmation, type the password or provide confirmation.
Type the name of the person that you want to give ownership to, and then click Check Names.
Note The account name for the person that you are assigning ownership to is displayed.
If you want this person to be the owner of the files and subfolders that are contained in this folder, select the Replace owner on subcontainers and objects check box.
You may not have the appropriate permissions Issues that you experience when you try to access files and folders may be related to permissions. Permissions are rules that determine whether you can access or change files and folders. To check permissions on a file or folder, follow these steps:
Press and hold or right-click the file or folder, and then click Properties.
Tap or click the Security tab.
Under Group or user names, tap or click your name to see the permissions that you have.
To open a file, you have to have the Read permission. To change the permissions of a file or folder, follow these steps.
Important You must be logged on as an administrator to change permissions on files and folders.
Press and hold or right-click the file or folder, and then tap or click Properties.
Tap or click the Security tab.
Under Group or user names, tap or click your name to see the permissions that you have.
Tap or click Edit, tap or click your name, select the check boxes for the permissions that you must have, and then click OK.
The file or folder may be encrypted Encryption can help protect files and folders from unwanted access. You cannot open an encrypted file or folder without the certificate that was used to encrypt it. To determine whether a file or folder is encrypted, follow these steps:
Press and hold or right-click the file or folder, and then tap or click Properties.
Tap or click the General tab, and then tap or click Advanced.
If the Encrypt contents to secure data check box is selected, you have to have the certificate that was used to encrypt the file or folder to be able to open it. In this situation, you should obtain the certificate from the person who created or encrypted the file or folder, or have that person decrypt the file or folder.
You may not have ownership of a file or folder If you recently upgraded your computer to Windows 7 from an earlier version of Windows, some of your account information may have changed. Therefore, you may no longer have ownership of some files or folders. You might be able to resolve this issue by restoring your ownership of the files and folders.
To take ownership of a file or a folder, follow these steps:
Right-click the folder that you want to take ownership of, then click Properties.
Click the Security tab, click Advanced, then click the Owner tab.
Note If you are prompted for an administrator password or for confirmation, type the password or provide confirmation.
Click the name of the person that you want to give ownership to.
If you want this person to be the owner of files and subfolders in this folder, select the Replace owner on subcontainers and objects check box.
You may not have the appropriate permissions Issues that you experience when you try to access files and folders may be related to permissions. Permissions are rules that determine whether you can access or change files and folders. To determine the permissions of the file or folder, follow these steps:
Right-click the file or folder, then click Properties.
Click the Security tab.
Under Group or user names, click your name to see the permissions that you have.
To open a file, you have to have the Read permission. To change permissions on a file or folder, follow these steps.
Important You must be logged on as an administrator to change permissions on files and folders.
Right-click the file or folder, and then click Properties.
Click the Security tab.
Under Group or user names, click your name to see the permissions that you have.
Click Edit, click your name, select the check boxes for the permissions that you must have, and then click OK.
For more information about permissions, see What are permissions?.
The file or folder may be encrypted Encryption can help protect files and folders from unwanted access. You cannot open an encrypted file or folder without the certificate that was used to encrypt it. To determine whether a file or folder is encrypted, follow these steps:
Right-click the file or folder, and then click Properties.
Click the General tab, then click Advanced.
If the Encrypt contents to secure data check box is selected, you have to have the certificate that was used to encrypt the file or folder to be able to open it.
You should obtain the certificate from the person who created or encrypted the file or folder, or have that person decrypt the file or folder.
Cause A problem that prevents you from accessing or working with files and folders can occur for one or more of the following reasons:
The folder ownership has changed
You do not have the appropriate permissions
The file is encrypted
The file is corrupted
The user profile is corrupted
You may not have ownership of a file or folder If you recently upgraded your computer to Windows 8 from an earlier version of Windows, some of your account information may have changed. Therefore, you may no longer have ownership of some files or folders. You might be able to resolve this issue by restoring your ownership of the files and folders.
To take ownership of a file or folder, follow these steps:
Press and hold the folder that you want to take ownership of, then tap Properties. (If you are using a mouse, right-click the folder, and then click Properties.)
Tap or click the Security tab, tap or click Advanced, then tap or click Change. If you are prompted for an administrator password or for confirmation, type the password or provide confirmation.
Type the name of the person that you want to give ownership to, and then click Check Names.
Note The account name for the person that you are assigning ownership to is displayed.
If you want this person to be the owner of the files and subfolders that are contained in this folder, select the Replace owner on subcontainers and objects check box.
You may not have the appropriate permissions Issues that you experience when you try to access files and folders may be related to permissions. Permissions are rules that determine whether you can access or change files and folders. To check permissions on a file or a folder, follow these steps:
Press and hold or right-click the file or folder, and then click Properties.
Tap or click the Security tab.
Under Group or user names, tap or click your name to see the permissions that you have.
To open a file, you have to have the Read permission. To change the permissions of a file or folder, follow these steps.
Important You must be logged on as an administrator to change permissions on files and folders.
Press and hold or right-click the file or folder, and then tap or click Properties.
Tap or click the Security tab.
Under Group or user names, tap or click your name to see the permissions that you have.
Tap or click Edit, tap or click your name, select the check boxes for the permissions that you must have, and then click OK.
For more information about permissions, see What are permissions?.
The file or folder may be encrypted Encryption can help protect files and folders from unwanted access. You cannot open an encrypted file or folder without the certificate that was used to encrypt it. To determine whether a file or folder is encrypted, follow these steps:
Press and hold or right-click the file or folder, and then tap or click Properties.
Tap or click the General tab, and then tap or click Advanced.
If the Encrypt contents to secure data check box is selected, you have to have the certificate that was used to encrypt the file or folder to be able to open it. In this situation, you should obtain the certificate from the person who created or encrypted the file or folder, or have that person decrypt the file or folder.
The file or folder may be corrupted Files can become corrupted for several reasons. The most common reason is that you have a file open when your computer crashes or loses power. Most corrupted files cannot be repaired. In this situation, you should either delete the file or restore the file from a backup copy.
For more information about corrupted files and how to fix them, see Corrupted files: frequently asked questions.
Your local user profile may be corrupted Occasionally, Windows might not read your local user profile correctly. This may prevent you from accessing files and folders. In this situation, you may have to use a new local user profile. To create the profile, you must first create a local user account. When the new account is created, the profile is also created. To create a local user account, follow these steps:
Swipe from the right edge of the screen, tap Settings, and then tap Change PC settings. (If you are using a mouse, point to the upper-right corner of the screen, move the mouse pointer down, click Settings, and then click Change PC settings)
In the navigation pane, tap or click Users.
Tap or Click Add a User, then tap or click Can they sign in without a Microsoft account?
Tap or click Local account.
Enter your new account name.
If you want to use a password, enter and verify the password that you want to use. If you decide not to use a password, tap or click Next without entering a password.
Tap or click Finish.
You may not have ownership of a file or folder If you recently upgraded your computer to Windows 7 from an earlier version of Windows, some of your account information may have changed. Therefore, you may no longer have ownership of some files or folders. You might be able to resolve this issue by restoring your ownership of the files and folders.
To take ownership of a file or a folder, follow these steps:
Right-click the folder that you want to take ownership of, and then click Properties.
Click the Security tab, click Advanced, and then click the Owner tab.
Click Edit. If you are prompted for an administrator password or for confirmation, type the password or provide confirmation.
Click the name of the person that you want to give ownership to.
If you want that person to be the owner of files and subfolders in this folder, select the Replace owner on subcontainers and objects check box.
You may not have the appropriate permissions Issues that you experience when you try to access files and folders may be related to permissions. Permissions are rules that determine whether you can access or change files and folders. To check permissions on a file or a folder, follow these steps:
Press and hold or right-click the file or folder, and then click Properties.
Tap or click the Security tab.
Under Group or user names, tap or click your name to see the permissions that you have.
To open a file, you have to have the Read permission. To change permissions on a file or folder, follow these steps.
Important You must be logged on as an administrator to change permissions on files and folders.
Right-click the file or folder, and then click Properties.
Click the Security tab.
Under Group or user names, click your name to see the permissions you have.
Click Edit, click your name, select the check boxes for the permissions that you must have, and then click OK.
For more information about permissions, see What are permissions?.
The file or folder may be encrypted Encryption can help protect files and folders from unwanted access. You cannot open an encrypted file or folder without the certificate that was used to encrypt it. To determine whether a file or folder is encrypted, follow these steps:
Right-click the file, then click Properties.
Click the General tab, and then click Advanced.
If the Encrypt contents to secure data check box is selected, you have to have the certificate that was used to encrypt the file or folder to be able to open it.
You should obtain the certificate from the person who created the file. For more information, see Import or export certificates and private keys.
The file or folder may be corrupted Files can become corrupted for several reasons. The most common reason is that you have a file open when your computer crashes or loses power. Most corrupted files cannot be repaired. In this situation, you should either delete the file or restore the file from a backup copy.
For more information about corrupted files and how to fix them, see Corrupted files: frequently asked questions.
Your user profile may be corrupted Occasionally, Windows might not read your local user profile correctly. This may prevent you from accessing files and folders. In this situation, you may have to use a new local user profile. To create the profile, you must first create a local user account. When the new account is created, the profile is also created.
For more information about how to create user profiles, see Fix a corrupted user profile. After the new user profile is created, you can copy your existing user files to the new profile so that you can access them.
Cause Problems that prevent you from accessing files and folders after you upgrade to a new version of Windows can occur for one or more of the following reasons:
The folder ownership has changed.
The files are being stored in a Windows.old folder from your previous system.
You may not have ownership of a file or folder If you recently upgraded your computer to Windows 8 from an earlier version of Windows, some of your account information may have changed. Therefore, you may no longer have ownership of some files and folders. You might be able to resolve this issue by restoring your ownership of the files and folders.
To take ownership of a file or a folder, follow these steps:
Press and hold the folder that you want to take ownership of, then tap Properties. (If you are using a mouse, right-click the folder, and then click Properties.)
Tap or click the Security tab, tap or click Advanced, then tap or click Change. If you are prompted for an administrator password or for confirmation, type the password or provide confirmation.
Type the name of the person that you want to give ownership to, and then click Check Names.
Note The account name for the person that you are assigning ownership to is displayed.
If you want this person to be the owner of the files and subfolders that are contained in this folder, select the Replace owner on subcontainers and objects check box.
You have to recover files from the Windows.old folder If you recently upgraded your computer to Windows 8 from an earlier version of Windows, and you did not reformat the hard disk, you might still be able to access your old files from the Windows.old folder.
To fix this problem automatically, click the Fix it button or link. In the File Download dialog box, click Run, and then follow the steps in the Fix it Wizard. If you prefer to fix this problem yourself, go to the «Let me fix it myself» section.
This wizard may be in English only. However, the automatic fix also works for other language versions of Windows.
If you are not on the computer that has the problem, save the Fix it solution to a flash drive or a CD, and then run it on the computer that has the problem.
Let me fix it myself To manually retrieve the files, follow these steps:
Open the desktop, tap the folder icon, and then click Computer. Or, press the Windows logo key+E.
Double-tap or double-click the drive that Windows is installed on (typically, drive C).
Double-tap or double-click the Windows.old folder.
Double-tap or double-click the Users folder.
Double-tap or double-click your user name.
Open the folders that contain the files that you want to retrieve. For example, to retrieve files in the Documents folder, double-tap or double-click Documents.
Copy the files that you want from each folder and paste them to a folder in Windows 8. For example, if you want to retrieve everything from the Documents folder, copy all the files and folders from the Documents folder in the Windows.old folder, and then paste them to the Documents library in Windows 8.
Repeat steps 5-7 for each user account on your computer.
For more information about how to recover data from an earlier version of Windows, see Recover lost or deleted files.
You may not have ownership of a file or folder If you recently upgraded your computer to Windows 7 from an earlier version of Windows, some of your account information may have changed. Therefore, you may no longer have ownership of some files and folders. You might be able to resolve this issue by restoring your ownership of the files and folders.
To take ownership of a file or a folder, follow these steps:
Right-click the folder that you want to take ownership of, and then click Properties.
Click the Security tab, click Advanced, and then click the Owner tab.
Click Edit. If you are prompted for an administrator password or confirmation, type the password or provide confirmation.
Click the name of the person that you want to give ownership to.
If you want that person to be the owner of files and subfolders in this folder, select the Replace owner on subcontainers and objects check box.
You may have to recover files from the Windows.old folder If you recently upgraded your computer to Windows 7 from an earlier version of Windows, and you did not reformat your hard disk, you might still be able to access your old files from the Windows.old folder.
To fix this problem automatically, click the Fix it button or link. In the File Download dialog box, click Run, and then follow the steps in the Fix it Wizard.If you prefer to fix this problem yourself, go to the «Let me fix it myself» section.
This wizard may be in English only. However, the automatic fix also works for other language versions of Windows.
If you are not on the computer that has the problem, save the Fix it solution to a flash drive or a CD, and then run it on the computer that has the problem.
Let me fix it myself To manually retrieve the files, follow these steps:
Click Start, then click Computer.
Double-click the drive that Windows is installed on (typically, drive C).
Double-click the Windows.old folder.
Double-click the Users folder.
Double-click your user name.
Open the folders that contain the files that you want to retrieve. For example, to retrieve files in the Documents folder, double-click Documents.
Copy the files that you want from each folder and paste them to a folder in Windows 7. For example, if you want to retrieve everything from the Documents folder, copy all the files and folders from the Documents folder in the Windows.old folder, and then paste them to the Documents library in Windows 7.
Repeat steps 5-7 for each user account on your computer.
For more information about how to recover data from an earlier version of Windows, see Recover lost or deleted files.