Archived from groups: microsoft.public.windowsxp.basics (More info?)
Hello,
I wrote a little c program which calls "GetFileAttributesExW" for the
file c:\pagefile.sys. The method returns with error 32, which means
"The process cannot access the file because it is being used by
another process."
(The program is attached in the end of this message).
I want to create a situation like that on a file of my own. I.e. - to
create a file "c:\dir1\my_file.txt" that if I run this program on it I
will get that "GetFileAttributesExW" fails with the same error.
I tried to write a program that opens a file "c:\dir1\my_file.txt"
with:
fh2 = _sopen(fileName2, _O_RDWR, _SH_DENYRW, _S_IREAD | _S_IWRITE);
and locks a part of it with:
_locking( fh2, LK_NBLCK, 30L )
and then sleep 10 minutes (i.e. - the file is locked ten minutes and
during
that time I run the program that calls "GetFileAttributesExW" ).
It didnt work ("GetFileAttributesExW" succeeded).
I also tried to play with the permissions of "c:\dir1\my_file.txt",
but it didnt work too.
I guess that the operating system locks "c:\pagefile.sys" in a special
way, a severe lock that causes this error to happen.
Does any one know how can I create this situation on a text file of my
own?
Attached the program that calls "GetFileAttributesExW" for
c:\pagefile.sys:
#include <stdio.h>
#include <winsock.h>
int gf_path_to_wpath(char *path, WCHAR *wpath)
{
char tmp_path[100];
sprintf(tmp_path, "\\\\?\\%s", path);
if (0 == MultiByteToWideChar(CP_ACP , 0 , tmp_path , -1 , wpath,
100))
{
printf("Failed in MultiByteToWideChar with error: <%d>\n",
GetLastError());
return 0;
}
return 1;
}
int main(char **argv, int argc)
{
char fileName[] = "C:\\pagefile.sys";
WCHAR wpath[100];
WIN32_FILE_ATTRIBUTE_DATA win32_file_attrib;
DWORD error;
int status;
gf_path_to_wpath(fileName, wpath);
status = GetFileAttributesExW(wpath , GetFileExInfoStandard ,
&win32_file_attrib);
if ( !status )
{
error = GetLastError ();
printf("GetFileAttributesEx failed for file <%s>, error is:
<%d>\n",
fileName, error);
}
else
printf("GetFileAttributesEx succeeded for file <%s>\n\n",
fileName);
}
You are about to answer a thread that has been inactive for more than 6 months. If you still wish to proceed, please ensure that your posting is original and does not duplicate or overlap any prior responses to this thread.