如何从 inno 设置中测试 windows 组是否存在?
How to test if a windows group exists from inno setup?
如何测试 windows 组是否已设置?你能以某种方式使用来自的回复吗:
Exec('net.exe', 'localgroup', '', SW_SHOW, ewWaitUntilTerminated, Result);
哪个会在命令提示符下列出组? (我知道 Result 是一个错误代码,其中 0 表示成功,只是为了清楚。)
有办法吗?有不止一种方法吗?
我没有对此进行测试,也没有时间计算出确切的过程或语法,但您可以使用命令重定向(请参阅 https://technet.microsoft.com/en-us/library/bb490982.aspx),按照您的建议使用 net localgroup
,查找组名并将其输出到文本文件。然后您可以使用 LoadStringFromFile
将其读入 Inno Setup,然后您需要做的就是比较两个字符串。
所以,在更详细地查看了这个之后,要查看 Administrators 组是否存在,您可以使用:
[Run]
Filename: "{cmd}"; Parameters: "/c ""net localgroup | find /i ""Administrators"" > ""{tmp}\groupresult.txt"""""; StatusMsg: "Querying user groups..."; Flags: runhidden
[Code]
var
strGroupResult: String;
begin
LoadStringFromFile(ExpandConstant('{tmp}\groupresult.txt'), strGroupResult);
if strGroupResult = '*Administrators' then
begin
//Code to execute if group exists
...
end;
DeleteFile(ExpandConstant('{tmp}\groupresult.txt'));
end;
注意net localgroup
returns组名前面有星号(*),所以字符串比较需要也包含星号。
如果您需要在 [Run]
部分之前执行此操作,您可以在 [Code]
部分中编写与 运行 相同过程类似的 Exec
行。
如何测试 windows 组是否已设置?你能以某种方式使用来自的回复吗:
Exec('net.exe', 'localgroup', '', SW_SHOW, ewWaitUntilTerminated, Result);
哪个会在命令提示符下列出组? (我知道 Result 是一个错误代码,其中 0 表示成功,只是为了清楚。)
有办法吗?有不止一种方法吗?
我没有对此进行测试,也没有时间计算出确切的过程或语法,但您可以使用命令重定向(请参阅 https://technet.microsoft.com/en-us/library/bb490982.aspx),按照您的建议使用 net localgroup
,查找组名并将其输出到文本文件。然后您可以使用 LoadStringFromFile
将其读入 Inno Setup,然后您需要做的就是比较两个字符串。
所以,在更详细地查看了这个之后,要查看 Administrators 组是否存在,您可以使用:
[Run]
Filename: "{cmd}"; Parameters: "/c ""net localgroup | find /i ""Administrators"" > ""{tmp}\groupresult.txt"""""; StatusMsg: "Querying user groups..."; Flags: runhidden
[Code]
var
strGroupResult: String;
begin
LoadStringFromFile(ExpandConstant('{tmp}\groupresult.txt'), strGroupResult);
if strGroupResult = '*Administrators' then
begin
//Code to execute if group exists
...
end;
DeleteFile(ExpandConstant('{tmp}\groupresult.txt'));
end;
注意net localgroup
returns组名前面有星号(*),所以字符串比较需要也包含星号。
如果您需要在 [Run]
部分之前执行此操作,您可以在 [Code]
部分中编写与 运行 相同过程类似的 Exec
行。