Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi Folks,

I'm trying to figure out how to script something that will go through a directory and reset the sychronization bit on a file. Looking at the fsecurity output below I need Sychonrize=1. Frankly I am not a windows programmer and am not sure how the subroutine should look. I would imagine I would need to make use of 'objFile.Attributes' but i'm not really sure. Any help would be appreciated!

VB
Allow - NT AUTHORITY\Authenticated Users - 0x000200a1
   0... .... .... .... .... .... .... .... = Generic Read
   .0.. .... .... .... .... .... .... .... = Generic Write
   ..0. .... .... .... .... .... .... .... = Generic Execute
   ...0 .... .... .... .... .... .... .... = Generic All
   .... ..0. .... .... .... .... .... .... = Maximum Allowed
   .... ...0 .... .... .... .... .... .... = System Security
   .... .... ...0 .... .... .... .... .... = Synchronize
   .... .... .... 0... .... .... .... .... = Write Owner
   .... .... .... .0.. .... .... .... .... = Write DAC
   .... .... .... ..1. .... .... .... .... = Read Control
   .... .... .... ...0 .... .... .... .... = Delete
   .... .... .... .... .... ...0 .... .... = Write Attributes
   .... .... .... .... .... .... 1... .... = Read Attributes
   .... .... .... .... .... .... .0.. .... = Delete Child
   .... .... .... .... .... .... ..1. .... = Execute
   .... .... .... .... .... .... ...0 .... = Write EA
   .... .... .... .... .... .... .... 0... = Read EA
   .... .... .... .... .... .... .... .0.. = Append
   .... .... .... .... .... .... .... ..0. = Write
   .... .... .... .... .... .... .... ...1 = Read
Posted

So it looks like wmiAce.AccessMask needs to be used. I can see how to get the current value, but not sure how to set it. Any suggestions?



Const SYNCHRONIZE = &h100000
'...
If wmiAce.AccessMask And SYNCHRONIZE > 0 Then
 '...
End If
 
Share this answer
 
So I have the making's of a script that should work. But, i'm still missing the concept of how to set the value of the attribute. Any suggestions, Thanks!


Const SYNCHRONIZE = &h100000
strPath = "C:\Windows\Temp"
 
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.FolderExists(strPath) Then 'Make sure folder exists
   Set objFolder = objfso.GetFolder(strPath)
   Set colFiles = objFolder.Files 'Enumerate files
   If colFiles.Count > 0 Then
      For Each objFile In colFiles
         Call SetSYNCFlag(objFile) 'Call subroutine for each file found.
      Next
   Else 'colFiles collection was empty
      WScript.Echo "No files in folder", objFolder.Path
   End If
Else 'Folder path could not be found
   WScript.Echo "The specified folder", strPath, "does not exist"
End If
 
Sub SetSYNCFlag(objFile)
   On Error Resume Next 'Disable automatic error handling
   Err.Clear 'Clear the StdErr object before continuing

   If wmiAce.AccessMask And SYNCHRONIZE > 0 Then
      WScript.Echo "correct attribute already set", objFile
   Else
      <<<<< Need to set the value of SYNCHRONIZE to 1 >>>>>>
	  <<<<< HELP >>>>>
   End If
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900