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
Solved

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

Posted on 2011-03-24
8
911 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 53

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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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 53

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

765 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