Solved

vbscript to clear Program Files Read-Only Attribute in Windows 7

Posted on 2011-03-24
8
913 Views
Last Modified: 2012-05-11
Is it possible to do this?
  vbscript to clear Program Files Read-Only Attribute in Windows 7
0
Comment
Question by:schmir1
  • 3
  • 3
  • 2
8 Comments
 
LVL 54

Expert Comment

by:Bill Prew
ID: 35211593
It is as long as you have administrative access to Program Files.  It would also be very easy in a BAT script or from the command line with a single command of:

ATTRIB -R "c:\program files\*.*" /S

~bp
0
 
LVL 13

Assisted Solution

by:Daz_1234
Daz_1234 earned 250 total points
ID: 35213893
Hi schmir1,

The sample below shows how to clear the Read Only attribute in VBScript.

Hope this helps,
Daz.


strFile = "C:\temp\test.log"

Set fso = CreateObject("Scripting.FileSystemObject")

Set objFile = fso.GetFile(strFile)

If objFile.Attributes And 1 Then 
    '# File is Read Only, so let's clear that
    objFile.Attributes = objFile.Attributes - 1
End If

MsgBox "Done!"

Open in new window

0
 
LVL 13

Expert Comment

by:Daz_1234
ID: 35213899
Actually this question:

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23153955.html

... answered by RobSampson, also includes an explanation of how the 'attributes' property works in VBScript.

Regards,
Daz.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:schmir1
ID: 35215783
Bill,

The following line doesn't work in Windows 7.  Has to be run as administrator.  How could I call a batch file containing ATTRIB -R "c:\program files\*.*" /S from vbScript and run it as administrator?

Daz,
I don't think your example will not work.   I need to do it for Windows 7 as administrator and it has to be for the "Program files" folder to allow a subfolder with my db to work.
0
 
LVL 13

Expert Comment

by:Daz_1234
ID: 35216046
The program files folder is not set to read only by default.  Are you sure that it is read only?  When you right-click the C:\Program Files folder and select properties, is the read-only attribute ticked? (and I don't mean just filled in a shade of blue or grey)

What is the actual folder that you need to have write access to?  It sounds like folder permissions, not read only attributes.

Regards,
Daz.
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 250 total points
ID: 35217448
You should be able to use the RUNAS command , something like:

RUNAS /user:%COMPUTERNAME%\Administrator cmd /c ATTRIB -R "c:\program files\*.*" /S

But this will of course prompt for the Administrator password.

~bp
0
 

Author Comment

by:schmir1
ID: 35396118
I turned this over to my IT people.  Nothing worked.  For now, he can't even clear the read-only.
0
 

Author Closing Comment

by:schmir1
ID: 35396145
thanks to you both.  the VBScript will help in the future.  For now, I just need it to work like Bill decribed with a DOS command.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question