Solved

.vbs script creat read/write folder problem

Posted on 2004-09-01
6
2,305 Views
Last Modified: 2013-12-03
i am writing a script to crete a folder and populate it with some logs. Simple enough right? whenever I create this folder via .vbs, it is set to read-only attribute, and I can't write anything to it. I need this changed with script though, because it is part of another script running on 300 or so computers.  Here is the following two methods i've already used that keep defaulting to read only access

1#
Set FSO = CreateObject("Scripting.FileSystemObject")
   FSO.CreateFolder(c:\dufftest65)

2#
folder= "emma04fix"
path= "c:\"&folder
duffcmd= "cmd /c md "& path
Call Wshshell.run(duffcmd,0,0)

Any help as to something I need to add or change would be greatly appreciated! I think 125 pts should be more then enough but hopefully that will get me some quick answers!
0
Comment
Question by:duffbk4
[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
6 Comments
 
LVL 1

Author Comment

by:duffbk4
ID: 11952194
Ok, I have pushed the points up cause I need this as soon as possible.  Thanks for any help!
0
 
LVL 16

Accepted Solution

by:
nonubik earned 500 total points
ID: 11952759
It is strange that is created read-only. You can set folder's attribute

Set FSO = CreateObject("Scripting.FileSystemObject")
   FSO.CreateFolder(c:\dufftest65)
   If FSO.attributes and 1 Then
      FSO.attributes = FSO.attributes - 1


1 is the value for readonly
0
 
LVL 86

Expert Comment

by:jkr
ID: 11952843
That should just work fine using

Function CreateFolderDemo
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.CreateFolder("c:\New Folder")
   CreateFolderDemo = f.Path
End Function

But, if the parent folder is set to 'read only' for your account and these settings are to be inherited by the contained objects, you'll end up with a newly created read-only folder. To change that, you could use

Function ToggleReadOnlyBit(filespec)
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder(filespec)
   If f.attributes and 1 Then
      f.attributes = f.attributes - 1
      ToggleReadOnlyBit = "ReadOnly bit is cleared."
   Else
      f.attributes = f.attributes + 1
      ToggleReadOnlyBit = "ReadOnly bit is set."
   End If
End Function

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 16

Expert Comment

by:nonubik
ID: 11952888
heh, I was a little bit faster :o)
0
 
LVL 1

Author Comment

by:duffbk4
ID: 11953519
Thanks for the help! Both of you.
0
 

Expert Comment

by:uber-goober
ID: 12126948
I am having exactly the same problem.  My directory has the read-only flag blocked out, (not checked) and I get the permissions error when I try to copy a file to it.  I have used the following code to explicitly set the bits to 16 for my directory (directory - not read-only).  Can someone help?

Set BinFolder = FolderObject.CreateFolder(InstallDir & "\Support\" & EnvLabel & "\BIN")
                        
BinFolder.Attributes = NOT 239 'set attributes to 16
msgbox "BinFolder.Attributes = " & BinFolder.Attributes,,"DEBUG" 'verify attribute setting
      
FolderObject.CopyFile CurrentInstallDir & "\BIN\winstore.sec", BinFolder, TRUE 'HOSED!@

0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error email attachment VB2010 5 58
Best way to accomplish this task? 3 97
Dialogbox API leak? 18 119
Need a complete list of ASP.NET page load events 3 73
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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