[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 988
  • Last Modified:

VB Script to change folder permission on the fly in Vista?

I am doing huge volume of OCRing.  My OCR program insists on saving untitled folders in my User\Mike\AppData\Local\Temp folder.  I discovered this when it hit 10K folders and the software would no longer run.  I have a VBS that deletes the Untiled folders and contents, but get "permission denied" errors unless I first uncheck "read only" in the Properties dialog, and keep the OCR from running while the script deletes the folders.  Because the SW keeps making these (maybe 8 to ten an hour) I cannot use some command line / startup command.  What I need is a method to incorportate into my deleting program that, just before it tries to delete a folder, it resets the permission away from Read Only.

I tried all of the UAC, global permissions, etc, tricks, and the only thing that works is to reset the folder and file attributes.

OS = Vista32 Biz
0
Mike Caldwell
Asked:
Mike Caldwell
  • 2
  • 2
1 Solution
 
Todd GerbertIT ConsultantCommented:
The command "attrib -s -h -r * /S /D" will recursively remove the System, Hidden and Read-only attributes from every file/folder.

0
 
Mike CaldwellDirector of Business Development, AnaquaAuthor Commented:
Can it be limited to the \Temp folder?  Can it be done with a .BAT file?
0
 
Mike CaldwellDirector of Business Development, AnaquaAuthor Commented:
Wow; works like a champion! Thank you.
0
 
Todd GerbertIT ConsultantCommented:
Yes, and yes.  Put this in a .bat, it will remove ALL contents of temp directory.

c:
cd users\mike\appdata\local\temp
attrib -s -h -r * /S /D
for /D %%i in (*) do rmdir /s /q %%i
del /F /S /Q *
0
 
winthropjCommented:
Mike - Here's your old code with the attribute change/permission mods built in. I've never pasted code so hopefully it shows up legible. I'll repaste otherwise.
'******  	DELETE UNTITLED FOLDERS ********************
Const strSourceFolderName = "C:\Users\Mike\AppData\Local\Temp\"
Set objFSO = CreateObject("Scripting.fileSystemObject")
Set objFolder = objFSO.GetFolder(strSourceFolderName)
Set WshShell = WScript.CreateObject("WScript.Shell")
	For each objSubFolder In objFolder.Subfolders			
		FN = objSubFolder.Name
			if left(FN,8) = "Untitled" Then
				intReturn = WshShell.Run("Icacls C:\Users\Mike\AppData\Local\Temp\ /T /grant everyone:(F,RA)", 1, TRUE)
				if intReturn = 0 Then
					For Each objFile in objSubFolder.Files
                		If objFile.Attributes = objFile.Attributes AND 1 Then
						objFile.Attributes = objFile.Attributes = 0 
						End If
					Next
				objSubFolder.Delete
				End If
			Else
			End If
	Next

Open in new window

0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now