Solved

.vbs script creat read/write folder problem

Posted on 2004-09-01
6
2,306 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

630 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