This isn't easy :-(
What you want to do is:
Code:
Set oShell = WScript.CreateObject("WScript.Shell")
Set oSpecialFolders = oShell.SpecialFolders
sMyDocs=oSpecialFolders("MyDocuments")
sINI=sMyDocs & "\desktop.ini"
scmd="cacls " & sINI & " /e /r administrators"
oShell.run sCmd,,true as part of the user login script. What this does is find the location of "my documents" (it will return \\server\users$\username or whatever the redirected location is). It then works out the full path name for desktop.ini and builds a command to run cacls on it.
So far, so good ...
It all falls over because you'll get "access denied" when you try and run cacls - even though a normal user will have permission to reset the permissions on the file, UAC will prevent this from running.
I'd guess what you're trying to do is stop having hundreds of folders all of which appear to be called "documents" so let's change the desktop.ini content so that it does just that - what we want is to make each folder show the user name.
Plan B:
Code:
on error resume next
set oFSO=createobject("scripting.filesystemobject")
Set oShell = WScript.CreateObject("WScript.Shell")
set oNet=wscript.createobject("wscript.network")
'get the name of the logged on user
sUser=oNet.username
'find the "mydocs" directory
Set oSpecialFolders = oShell.SpecialFolders
sMyDocs=oSpecialFolders("MyDocuments")
'and the desktop.ini
sINI=sMyDocs & "\desktop.ini"
'delete it if it's there (true forces delete)
if ofso.fileexists(sINI) then ofso.deletefile sINI,true
'create it. "True" says overwrite if present - belt and braces!
set oFile=ofso.createtextfile(sIni,true)
'write the content
oFile.writeline "[.ShellClassInfo]"
oFile.writeline "LocalizedResourceName=" & sUser
oFile.close
I think you could actually stop after the delete statement - you then won't have a desktop.ini and Windows will just show the username for each folder (because that's what the folder is called!) but this just puts in a desktop.ini containing what you want. You could add more - eg you could add an icon, you could look up the user's full name and so on - but hopefully this will work for the basics you need.