Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We need to set permissions on users' directories on a Windows 2000 Server. This happens regularly enough and they must also be set in the order below or the backups crap out. This is the basic script:

XCACLS foldername /g Administrators:OF /T /C /Y  
XCACLS foldername /E /g "DOM\Enterprise Admins":OF /T /C /Y  
XCACLS foldername /E /g SYSTEM:OF /T /C /Y  
XCACLS foldername /E /g STAFF\username:ORWEDC /T /C /Y

My problem is that this script doesn't work on all files in some directories. The files it seems to fail on are long filenames and deeply nested directories.

Does anyone know of a script that doesn't mind long filenames and takes large paths in its stride?

I have come across a XCACLS.vbs script from Microsoft, but it works differently and I'm not sure if it works with these large filenames also.

share|improve this question
add comment

1 Answer 1

There is a limit of around 260 characters on the length of filenames, however there is a massively cunning and sneaky way to get round this :-)

The limit is in the Win32 subsystem not in the kernel. If you prefix a file name with \?\ this causes the Win32 subsystem to pass the name directly to the kernel without any preprocessing, and the limit doesn't apply. The kernel still has a limit, but it's somthing silly like 65,553 characters.

So while:

xcacls C:\verylongname.txt

doesn't work you should find:

xcacls \\?\C:\verylongname.txt

does work. If you're using a UNC name the syntax is:

xcacls \\?\UNC\server\share\verylongname.txt

NB this only works with fully qualified names i.e. starting with a drive letter. It doesn't work with all of the command line apps in Windows, but it works with many.

share|improve this answer
    
Oops, just noticed that ServerFault has replaced the double backslash with a single backslash. The filenames should start with two backslashes then ? –  John Rennie May 16 '09 at 6:58
    
Great answer, I'll try it out tomorrow. I'll let you know! –  Seanchán Torpéist May 18 '09 at 21:29
    
How did it go? Did it work? –  John Rennie May 21 '09 at 16:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.