Solved

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

Posted on 2011-03-24
8
907 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 52

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I want to make a copying program for vbs 1 39
Need to rewrite code for checking if a file exists 3 58
Messed up my code 6 34
Compile Error 7 41
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

22 Experts available now in Live!

Get 1:1 Help Now