Question

There have been many posts where someone needed to know how to change the permissions of a folder or file upon installation using VBScript. The one problem that I have is that none of them have solved it for non-English situations.

This is basically what I have so far. I check to see if the locale is a specific language like "fr" for French and then assume that there is a group called Utilisateurs for the Users group. I then call cacls to set the change permission on my folder. This works quite well for English and French, but I don't know for sure what the groups are for the other languages. I am currently limited to only these six because I don't know what the other Users groups are named for the other languages.

I would like to be able to handle all cases, but if you have a list of known Users groups for other languages that would be sufficient for me to solve my current problem.

Dim nLocale
nLocale = objShell.RegRead("HKEY_USERS\.DEFAULT\Control Panel\International\LocaleName")
Dim nLocaleName, sUserGroup
nLocaleName = Left(nLocale, 2)
'MsgBox "[" & nLocaleName & "] = en" & InStr(1, nLocalName, "en", vbTextCompare)
if InStr(1, nLocaleName, "en", vbTextCompare) = 1 or nLocaleName="en" then
    sUserGroup="Users"
elseif InStr(1, nLocaleName, "fr", vbTextCompare) = 1 then
    sUserGroup="Utilisateurs"
elseif InStr(1, nLocaleName, "de", vbTextCompare) = 1 then
    sUserGroup="Benutzer"
elseif InStr(1, nLocaleName, "es", vbTextCompare) = 1 then
    sUserGroup="Usuarios"
elseif InStr(1, nLocaleName, "it", vbTextCompare) = 1 then
    sUserGroup="Utenti"
elseif InStr(1, nLocaleName, "pt", vbTextCompare) = 1 then
    sUserGroup="Usuários"
else
    MsgBox "To allow other users access to the AUDit Database you will need to give user permissions to " & strHomeFolder, (vbOKOnly + vbExclamation), "Notice of Permissions"
    return
end if

'Wscript.Echo "cacls """ & strHomeFolder & """ /e /c /g " & sUserGroup & ":C "

intRunError = objShell.Run("cacls """ & strHomeFolder & """ /e /c /G """ & sUserGroup & """:C ", 2, True)

This works when I run it and when it is set in a Custom Action using Visual Studio's Setup Wizard. I have found some pseudo solutions that only work if you execute them outside of Custom Actions. It must work in a Custom Action for my installation.

Était-ce utile?

La solution

The local users group has a well-known SID, so you can resolve the name of the group like this:

Set wmi = GetObject("winmgmts://./root/cimv2")
sUserGroup = wmi.Get("Win32_SID.SID='S-1-5-32-545'").AccountName

As a side-note: I strongly recommend using icacls over cacls if at all possible.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top