0

有很多帖子有人需要知道如何在使用 VBScript 安装时更改文件夹或文件的权限。我遇到的一个问题是他们都没有解决非英语情况的问题。

这基本上是我到目前为止所拥有的。我检查区域设置是否是特定语言,例如法语的“fr”,然后假设用户组有一个名为 Utilisateurs 的组。然后我调用 cacls 来设置我的文件夹的更改权限。这对英语和法语非常有效,但我不确定其他语言的组是什么。我目前仅限于这六个,因为我不知道其他用户组为其他语言命名的名称。

我希望能够处理所有情况,但是如果您有其他语言的已知用户组列表,这足以让我解决我当前的问题。

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)

这在我运行它以及使用 Visual Studio 的安装向导在自定义操作中设置时有效。我发现了一些伪解决方案,只有在自定义操作之外执行它们才有效。它必须在我的安装的自定义操作中工作。

4

1 回答 1

1

本地用户组有一个众所周知的 SID,因此您可以像这样解析组的名称:

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

附带说明:我强烈建议尽可能使用icaclsover 。cacls

于 2013-03-22T19:35:43.800 回答