By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,827 Members | 2,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,827 IT Pros & Developers. It's quick & easy.

Changing the attributes for a hidden system file programmatically

P: n/a
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!


Nov 17 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
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" <al***********@gmail.com> wrote in message
news:uw**************@TK2MSFTNGP15.phx.gbl...
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!

Nov 17 '05 #2

P: n/a
"Alexandra" <al***********@gmail.com> wrote in message
news:uw**************@TK2MSFTNGP15.phx.gbl...
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
Nov 17 '05 #3

P: n/a
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" <ni**@nospam.asianetindia.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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" <al***********@gmail.com> wrote in message
news:uw**************@TK2MSFTNGP15.phx.gbl...
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!


Nov 17 '05 #4

P: n/a

"Alexandra" <al***********@gmail.com> wrote in message
news:uw**************@TK2MSFTNGP15.phx.gbl...
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
-g*******@mvps.org

Nov 17 '05 #5

P: n/a
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);

"William DePalo [MVP VC++ ]" <wi***********@mvps.org> wrote in message
news:OI**************@TK2MSFTNGP09.phx.gbl:
"Alexandra" <al***********@gmail.com> wrote in message
news:uw**************@TK2MSFTNGP15.phx.gbl...
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


Nov 17 '05 #6

P: n/a
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!!!

"Gary Chanson" <gjchanson@_NO_SPAM_comcast.net> wrote in message
news:O0**************@TK2MSFTNGP09.phx.gbl:
"Alexandra" <al***********@gmail.com> wrote in message
news:uw**************@TK2MSFTNGP15.phx.gbl...
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
-g*******@mvps.org


Nov 17 '05 #7

P: n/a
Use the process explorer tool from www.sysinternals.com to find out the
process that is using the file.

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

"Alexandra" <al***********@gmail.com> wrote in message
news:uz*************@TK2MSFTNGP09.phx.gbl...
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!!!

"Gary Chanson" <gjchanson@_NO_SPAM_comcast.net> wrote in message
news:O0**************@TK2MSFTNGP09.phx.gbl:
"Alexandra" <al***********@gmail.com> wrote in message
news:uw**************@TK2MSFTNGP15.phx.gbl...
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
-g*******@mvps.org

Nov 17 '05 #8

P: n/a
Just tried the attrib.exe.
Same problem.
Access denied.

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

"Nishant Sivakumar" <ni**@nospam.asianetindia.com> wrote in message
news:uu**************@TK2MSFTNGP14.phx.gbl:
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" <ni**@nospam.asianetindia.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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" <al***********@gmail.com> wrote in message
news:uw**************@TK2MSFTNGP15.phx.gbl...

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!



Nov 17 '05 #9

P: n/a
"Alexandra" <al***********@gmail.com> wrote in message
news:uR**************@tk2msftngp13.phx.gbl...
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
Nov 17 '05 #10

P: n/a
Looks like that file is in use.

--
Regards,
Nish [VC++ MVP]
"Alexandra" <al***********@gmail.com> wrote in message
news:Og*************@TK2MSFTNGP15.phx.gbl...
Just tried the attrib.exe.
Same problem.
Access denied.

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

"Nishant Sivakumar" <ni**@nospam.asianetindia.com> wrote in message
news:uu**************@TK2MSFTNGP14.phx.gbl:
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" <ni**@nospam.asianetindia.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> 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" <al***********@gmail.com> wrote in message
> news:uw**************@TK2MSFTNGP15.phx.gbl...

>> 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!
>>
>>
>>
>>
>

>

Nov 17 '05 #11

P: n/a
According to this tool no process has the handle to my file...

What else can it be ?

"CheckAbdoul" <checkabdoul at mvps dot org> wrote in message
news:#9*************@TK2MSFTNGP10.phx.gbl:
Use the process explorer tool from www.sysinternals.com to find out the
process that is using the file.

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

"Alexandra" <al***********@gmail.com> wrote in message
news:uz*************@TK2MSFTNGP09.phx.gbl...
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!!!

"Gary Chanson" <gjchanson@_NO_SPAM_comcast.net> wrote in message
news:O0**************@TK2MSFTNGP09.phx.gbl:

"Alexandra" <al***********@gmail.com> wrote in message
news:uw**************@TK2MSFTNGP15.phx.gbl...
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
-g*******@mvps.org



Nov 17 '05 #12

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

"Nishant Sivakumar" <ni**@nospam.asianetindia.com> wrote in message
news:#Q**************@TK2MSFTNGP12.phx.gbl:
Looks like that file is in use.

--
Regards,
Nish [VC++ MVP]
"Alexandra" <al***********@gmail.com> wrote in message
news:Og*************@TK2MSFTNGP15.phx.gbl...
Just tried the attrib.exe.
Same problem.
Access denied.

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

"Nishant Sivakumar" <ni**@nospam.asianetindia.com> wrote in message
news:uu**************@TK2MSFTNGP14.phx.gbl:

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" <ni**@nospam.asianetindia.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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" <al***********@gmail.com> wrote in message
> news:uw**************@TK2MSFTNGP15.phx.gbl...
> 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!
>>
>>
>>
>>
>

>



Nov 17 '05 #13

P: n/a
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

"Alexandra" <al***********@gmail.com> wrote in message
news:uw**************@TK2MSFTNGP15.phx.gbl...
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!

Nov 17 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.