Hallo zusammen,
ich habe mnir ein kleines Batchfile geschrieben, welches auch funktioniert. Dieses wurde ich gerne in mein C# Programm einbauen und mit einem Button ausführen.
Das Batchfile sieht wie folgt aus ( Ip-Adressen sind hier nur als Beispiel gesetzt und nicht existent):
@echo off
cls
netsh advfirewall firewall add rule name="Test Domains Block" dir=out interface=any
action=block remoteip=165.461.226.11,169.445.226.12,190.367.127.161,182.356.124.169
pause
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
| string parameters = @"netsh advfirewall firewall add rule " + "name={0} " + "dir={1} " + "action={2} " + "interface={3} " + "remoteip={4}"; string rulename = "Test Domains Block"; string direction = "out"; string action = "block"; string interface = "any"; int remoteip = 165.461.226.11,169.445.226.12,190.367.127.161,182.356.124.169; ProcessStartInfo info = new ProcessStartInfo(@"C:\Windows\System32\netsh.exe"); info.Arguments = String.Format(parameters, rulename, direction, action, interface, remoteip); var process = Process.Start(info); |
Leider funktioniert meine obrige Annahme nicht. Kann mir hier jemand Hilfestellung geben ?