【发布时间】:2020-06-25 19:59:50
【问题描述】:
我想通过我的 C# 代码更新防火墙规则。我创建了工作正常的 VB 脚本(它以参数为输入)。但是当我通过 C# 代码调用相同的脚本时,防火墙规则没有更新。
请找到我的代码
VB 脚本:
option explicit
' Create the Shell object
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
' Create the FwPolicy2 object.
Dim fwPolicy2
Set fwPolicy2 = CreateObject("HNetCfg.FwPolicy2")
' Get the Rules object
Dim RulesObject
Set RulesObject = fwPolicy2.Rules
Dim Arg
Set Arg = WScript.Arguments
Dim rule
'Set NewRule=Nothing
Set rule = CreateObject("HNetCfg.FWRule")
For Each rule In Rulesobject
if rule.Name = "some rule" then
rule.RemoteAddresses = Arg(0)
exit for
end if
next
C#方法:
string scriptName = @"full path";
ProcessStartInfo ps = new ProcessStartInfo();
ps.FileName = "cscript.exe";
ps.Arguments = string.Format("\"{0}\" \"{1}\"", scriptName, IPRange);
Process p = new Process();
p.StartInfo = ps;
p.Start();
p.WaitForExit();
【问题讨论】:
标签: c# vbscript command-line-arguments