Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2005

Tip: Looking for answers? Try searching our database.

Changing the attributes for a hidden system file programmatically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alexandra - 16 Nov 2005 19:08 GMT
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!
Nishant Sivakumar - 16 Nov 2005 19:43 GMT
You may have to remove the system-file attribute before being able to remove
the regular attributes like hidden and readonly.

Signature

Regards,
Nish [VC++ MVP]

> Hi,
>
[quoted text clipped - 31 lines]
>
> Thank you!
Nishant Sivakumar - 16 Nov 2005 19:49 GMT
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.

Signature

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.
[quoted text clipped - 34 lines]
>>
>> Thank you!
Alexandra - 16 Nov 2005 20:25 GMT
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
[quoted text clipped - 46 lines]
> >>
> >> Thank you!
Nishant Sivakumar - 16 Nov 2005 20:37 GMT
Looks like that file is in use.

Signature

Regards,
Nish [VC++ MVP]

> Just tried the attrib.exe.
> Same problem.
[quoted text clipped - 54 lines]
>> >>
>> >> Thank you!
Alexandra - 16 Nov 2005 21:10 GMT
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.
>
[quoted text clipped - 60 lines]
> >> >>
> >> >> Thank you!
William DePalo [MVP VC++ ] - 16 Nov 2005 19:43 GMT
> 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.)
>
[quoted text clipped - 8 lines]
>
> 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
Alexandra - 16 Nov 2005 20:12 GMT
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);   

> > I have a hidden system file that I need to read.
> >
[quoted text clipped - 32 lines]
> Regards,
> Will
William DePalo [MVP VC++ ] - 16 Nov 2005 20:22 GMT
>I am trying to open the file in write and read mode.
> This the code :
[quoted text clipped - 6 lines]
> 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
Gary Chanson - 16 Nov 2005 19:54 GMT
> Hi,
>
[quoted text clipped - 27 lines]
>
> 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.

Signature

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

Alexandra - 16 Nov 2005 20:15 GMT
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,
> >
[quoted text clipped - 35 lines]
> - http://www.mvps.org/ArcaneIncantations/consulting.htm
> -gchanson@mvps.org
CheckAbdoul - 16 Nov 2005 20:18 GMT
   Use the process explorer tool from www.sysinternals.com to find out the
process that is using the file.

Signature

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

> I have the same feeling.
> This file is used by a service which is logged in as a system account.
[quoted text clipped - 48 lines]
> > - http://www.mvps.org/ArcaneIncantations/consulting.htm
> > -gchanson@mvps.org
Alexandra - 16 Nov 2005 20:56 GMT
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.
[quoted text clipped - 59 lines]
> > > - http://www.mvps.org/ArcaneIncantations/consulting.htm
> > > -gchanson@mvps.org
Max - 17 Nov 2005 08:13 GMT
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

> Hi,
>
[quoted text clipped - 31 lines]
>
> Thank you!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.