views:

189

answers:

1

Hello,

I have a little vb.net script that will copy a file, set its attributes to Normal, update the file time, and then set back the attributes to match those of the source file.

If IO.File.Exists(Destination) Then IO.File.SetAttributes(Destination, IO.FileAttributes.Normal)
IO.File.Copy(Source, Destination, True)

IO.File.SetAttributes(Destination, IO.FileAttributes.Normal)
IO.File.SetLastWriteTimeUtc(Destination, IO.File.GetLastWriteTimeUtc(Destination).AddHours(1))

IO.File.SetAttributes(Destination, IO.File.GetAttributes(Source))

I however I'm encountering a quite strange problem. On some configurations, IO.File.SetLastWriteTimeUtc triggers an UnauthorizedAccess error, although the IO.File.Copy instruction worked very well.

I'm totally puzzled: I've checked, and file attributes are set to 128 (ie. Normal) successfully. The problem seems to be with the very SetLastWriteTimeUtc. But what is it?

Any ideas?
Thanks a lot!

A: 

If you are using Vista or Windows 7, you will need to run it as adminitrator, because of UAC. Try running it elevated and it shuold work fine

icemanind
Thanks! But do you know the reasons why this happens? I'm not experimenting this problem on my own 7 machine, with guest account.
CFP
UAC didn't solve the problem...
CFP