Changing the attributes for a hidden system file programmatically

A

Alexandra

Hi,



I have a hidden system file that I need to read.

I am logged in as an administrator.

I can not change the file attributes using the windows explorer.

I can view the file's content.



Opening the file programmatically fails with access is denied.

(If I copy the file I can access it, although it is also hidden.)

Therefore I am trying to change the attributes of that file,
programmatically, to normal.

Getting the attributes succeeds and shows that the file is hidden and
system.

However when I try to set the file attribute to normal it fails and get
last error produces the following string :

Error 183 : Cannot create file when that file already exists.



The MSDN states that for WinXP it is possible to change the attributes
for hidden and system files.

Do I need some special permissions ? Which ones ?



I have logged off and logged in again, the behavior did not change.



Any leads, anyone ?



Thank you!
 
N

Nishant Sivakumar

You may have to remove the system-file attribute before being able to remove
the regular attributes like hidden and readonly.
 
W

William DePalo [MVP VC++ ]

Alexandra said:
I have a hidden system file that I need to read.

I am logged in as an administrator.
OK.

I can not change the file attributes using the windows explorer.

I can view the file's content.
OK.

Opening the file programmatically fails with access is denied.

Important bits of information that you don't offer are the parameters to
CreateFile(). Are you specifying an access mode of GENERIC_READ and a share
mode of FILE_SHARE_READ?
(If I copy the file I can access it, although it is also hidden.)

Therefore I am trying to change the attributes of that file,
programmatically, to normal.

Getting the attributes succeeds and shows that the file is hidden and
system.

However when I try to set the file attribute to normal it fails and get
last error produces the following string :

Error 183 : Cannot create file when that file already exists.

Hmm. I think you'll need to post a _short_ snippet of code here that causes
the error if the previous suggestion does not work for you.

Regards,
Will
 
N

Nishant Sivakumar

BTW I am talking about doing it via Explorer (which only allows you to set
readonly and hidden). You'll have to use attrib.exe to set the system
attribute.

--
Regards,
Nish [VC++ MVP]


Nishant Sivakumar said:
You may have to remove the system-file attribute before being able to
remove the regular attributes like hidden and readonly.

--
Regards,
Nish [VC++ MVP]


Alexandra said:
Hi,



I have a hidden system file that I need to read.

I am logged in as an administrator.

I can not change the file attributes using the windows explorer.

I can view the file's content.



Opening the file programmatically fails with access is denied.

(If I copy the file I can access it, although it is also hidden.)

Therefore I am trying to change the attributes of that file,
programmatically, to normal.

Getting the attributes succeeds and shows that the file is hidden and
system.

However when I try to set the file attribute to normal it fails and get
last error produces the following string :

Error 183 : Cannot create file when that file already exists.



The MSDN states that for WinXP it is possible to change the attributes
for hidden and system files.

Do I need some special permissions ? Which ones ?



I have logged off and logged in again, the behavior did not change.



Any leads, anyone ?



Thank you!
 
G

Gary Chanson

Alexandra said:
Hi,



I have a hidden system file that I need to read.

I am logged in as an administrator.

I can not change the file attributes using the windows explorer.

I can view the file's content.



Opening the file programmatically fails with access is denied.

(If I copy the file I can access it, although it is also hidden.)

Therefore I am trying to change the attributes of that file,
programmatically, to normal.

Getting the attributes succeeds and shows that the file is hidden and
system.

However when I try to set the file attribute to normal it fails and get
last error produces the following string :

Error 183 : Cannot create file when that file already exists.



The MSDN states that for WinXP it is possible to change the attributes
for hidden and system files.

Do I need some special permissions ? Which ones ?



I have logged off and logged in again, the behavior did not change.

I think your real problem is that the file is in use by another program.
 
A

Alexandra

I am trying to open the file in write and read mode.
This the code :

DWORD attrs = GetFileAttributes((LPCSTR)path);
attrs = FILE_ATTRIBUTE_NORMAL;
if(SetFileAttributes((LPCSTR)path,attrs))
LogMessage("Set to FILE_ATTRIBUTE_NORMAL");

CFileException e;
int res = file.Open(sPath + DBFileNewLocation,CFile::modeReadWrite,&e);
 
A

Alexandra

I have the same feeling.
This file is used by a service which is logged in as a system account.
However I have stopped the service, disabled it actually, logged out and
logged in again.
The service is disabled, stopped, I have checked.

If I copy this file I can open the copy of that file...

How can I find out if any other program is using that file ?
Any suggestions you might have would be greatly appreciated...

Thanks!!!

Hi,



I have a hidden system file that I need to read.

I am logged in as an administrator.

I can not change the file attributes using the windows explorer.

I can view the file's content.



Opening the file programmatically fails with access is denied.

(If I copy the file I can access it, although it is also hidden.)

Therefore I am trying to change the attributes of that file,
programmatically, to normal.

Getting the attributes succeeds and shows that the file is hidden and
system.

However when I try to set the file attribute to normal it fails and get
last error produces the following string :

Error 183 : Cannot create file when that file already exists.



The MSDN states that for WinXP it is possible to change the attributes
for hidden and system files.

Do I need some special permissions ? Which ones ?



I have logged off and logged in again, the behavior did not change.


I think your real problem is that the file is in use by another program.

--
-GJC [MS Windows SDK MVP]
-Software Consultant (Embedded systems and Real Time Controls)
- http://www.mvps.org/ArcaneIncantations/consulting.htm
(e-mail address removed)
 
C

CheckAbdoul

Use the process explorer tool from www.sysinternals.com to find out the
process that is using the file.

--
Cheers
Check Abdoul
-----------------

Alexandra said:
I have the same feeling.
This file is used by a service which is logged in as a system account.
However I have stopped the service, disabled it actually, logged out and
logged in again.
The service is disabled, stopped, I have checked.

If I copy this file I can open the copy of that file...

How can I find out if any other program is using that file ?
Any suggestions you might have would be greatly appreciated...

Thanks!!!

Hi,



I have a hidden system file that I need to read.

I am logged in as an administrator.

I can not change the file attributes using the windows explorer.

I can view the file's content.



Opening the file programmatically fails with access is denied.

(If I copy the file I can access it, although it is also hidden.)

Therefore I am trying to change the attributes of that file,
programmatically, to normal.

Getting the attributes succeeds and shows that the file is hidden and
system.

However when I try to set the file attribute to normal it fails and get
last error produces the following string :

Error 183 : Cannot create file when that file already exists.



The MSDN states that for WinXP it is possible to change the attributes
for hidden and system files.

Do I need some special permissions ? Which ones ?



I have logged off and logged in again, the behavior did not change.


I think your real problem is that the file is in use by another program.

--
-GJC [MS Windows SDK MVP]
-Software Consultant (Embedded systems and Real Time Controls)
- http://www.mvps.org/ArcaneIncantations/consulting.htm
(e-mail address removed)
 
W

William DePalo [MVP VC++ ]

Alexandra said:
I am trying to open the file in write and read mode.
This the code :

DWORD attrs = GetFileAttributes((LPCSTR)path);
attrs = FILE_ATTRIBUTE_NORMAL;
if(SetFileAttributes((LPCSTR)path,attrs))
LogMessage("Set to FILE_ATTRIBUTE_NORMAL");

CFileException e;
int res = file.Open(sPath + DBFileNewLocation,CFile::modeReadWrite,&e);

Well, if understood your post correctly, you said that you were able to read
the file interactively. You never said that you were able to _write_
interactively but rather that you were copying the file data to a new
location.

If I have that right, I'd suggest that you change CFile::modeReadWrite to
CFile::modeRead.

Regards,
Will
 
A

Alexandra

Just tried the attrib.exe.
Same problem.
Access denied.

How can I find out what is preventing me from accessing that file ???

BTW I am talking about doing it via Explorer (which only allows you to set
readonly and hidden). You'll have to use attrib.exe to set the system
attribute.

--
Regards,
Nish [VC++ MVP]


You may have to remove the system-file attribute before being able to
remove the regular attributes like hidden and readonly.

--
Regards,
Nish [VC++ MVP]


Hi,



I have a hidden system file that I need to read.

I am logged in as an administrator.

I can not change the file attributes using the windows explorer.

I can view the file's content.



Opening the file programmatically fails with access is denied.

(If I copy the file I can access it, although it is also hidden.)

Therefore I am trying to change the attributes of that file,
programmatically, to normal.

Getting the attributes succeeds and shows that the file is hidden and
system.

However when I try to set the file attribute to normal it fails and get
last error produces the following string :

Error 183 : Cannot create file when that file already exists.



The MSDN states that for WinXP it is possible to change the attributes
for hidden and system files.

Do I need some special permissions ? Which ones ?



I have logged off and logged in again, the behavior did not change.



Any leads, anyone ?



Thank you!
 
N

Nishant Sivakumar

Looks like that file is in use.

--
Regards,
Nish [VC++ MVP]


Alexandra said:
Just tried the attrib.exe.
Same problem.
Access denied.

How can I find out what is preventing me from accessing that file ???

BTW I am talking about doing it via Explorer (which only allows you to
set
readonly and hidden). You'll have to use attrib.exe to set the system
attribute.

--
Regards,
Nish [VC++ MVP]


You may have to remove the system-file attribute before being able to
remove the regular attributes like hidden and readonly.

--
Regards,
Nish [VC++ MVP]


news:[email protected]...
Hi,



I have a hidden system file that I need to read.

I am logged in as an administrator.

I can not change the file attributes using the windows explorer.

I can view the file's content.



Opening the file programmatically fails with access is denied.

(If I copy the file I can access it, although it is also hidden.)

Therefore I am trying to change the attributes of that file,
programmatically, to normal.

Getting the attributes succeeds and shows that the file is hidden and
system.

However when I try to set the file attribute to normal it fails and
get
last error produces the following string :

Error 183 : Cannot create file when that file already exists.



The MSDN states that for WinXP it is possible to change the attributes
for hidden and system files.

Do I need some special permissions ? Which ones ?



I have logged off and logged in again, the behavior did not change.



Any leads, anyone ?



Thank you!
 
A

Alexandra

According to this tool no process has the handle to my file...

What else can it be ?

Use the process explorer tool from www.sysinternals.com to find out the
process that is using the file.

--
Cheers
Check Abdoul
-----------------

I have the same feeling.
This file is used by a service which is logged in as a system account.
However I have stopped the service, disabled it actually, logged out and
logged in again.
The service is disabled, stopped, I have checked.

If I copy this file I can open the copy of that file...

How can I find out if any other program is using that file ?
Any suggestions you might have would be greatly appreciated...

Thanks!!!

Hi,



I have a hidden system file that I need to read.

I am logged in as an administrator.

I can not change the file attributes using the windows explorer.

I can view the file's content.



Opening the file programmatically fails with access is denied.

(If I copy the file I can access it, although it is also hidden.)

Therefore I am trying to change the attributes of that file,
programmatically, to normal.

Getting the attributes succeeds and shows that the file is hidden and
system.

However when I try to set the file attribute to normal it fails and
get
last error produces the following string :

Error 183 : Cannot create file when that file already exists.



The MSDN states that for WinXP it is possible to change the attributes
for hidden and system files.

Do I need some special permissions ? Which ones ?



I have logged off and logged in again, the behavior did not change.


I think your real problem is that the file is in use by another program.

--
-GJC [MS Windows SDK MVP]
-Software Consultant (Embedded systems and Real Time Controls)
- http://www.mvps.org/ArcaneIncantations/consulting.htm
(e-mail address removed)
 
A

Alexandra

Just tried the process explorer tool from sysinternals and it does not
show that any process has a handle to my file...

Looks like that file is in use.

--
Regards,
Nish [VC++ MVP]


Just tried the attrib.exe.
Same problem.
Access denied.

How can I find out what is preventing me from accessing that file ???

BTW I am talking about doing it via Explorer (which only allows you to
set
readonly and hidden). You'll have to use attrib.exe to set the system
attribute.

--
Regards,
Nish [VC++ MVP]



You may have to remove the system-file attribute before being able to
remove the regular attributes like hidden and readonly.

--
Regards,
Nish [VC++ MVP]



Hi,



I have a hidden system file that I need to read.

I am logged in as an administrator.

I can not change the file attributes using the windows explorer.

I can view the file's content.



Opening the file programmatically fails with access is denied.

(If I copy the file I can access it, although it is also hidden.)

Therefore I am trying to change the attributes of that file,
programmatically, to normal.

Getting the attributes succeeds and shows that the file is hidden and
system.

However when I try to set the file attribute to normal it fails and
get
last error produces the following string :

Error 183 : Cannot create file when that file already exists.



The MSDN states that for WinXP it is possible to change the attributes
for hidden and system files.

Do I need some special permissions ? Which ones ?



I have logged off and logged in again, the behavior did not change.



Any leads, anyone ?



Thank you!
 
M

Max

Check what permissions do you have on this file and who is the owner of the
file.

Even if you are using an administrator account you might not have necessary
permissions on certain files.

Good Luck,
Max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top