Solved

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

Posted on 2011-03-24
8
914 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 55

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 55

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

Independent Software Vendors: 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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

719 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