Solved

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

Posted on 2011-03-24
8
903 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 51

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 12

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 12

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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 12

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 51

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now