cmd dnscmd .net c#

Hi

Been trying to tidy up DNS server in windows by delting unneeded zone files

Have found that using command window and issuing the command
> dnscmd /zonedelete domainnametodelete.tld /f

will delete zone very quickly but I want to ru this inside a .net c# form as want to access the database with the names of the zone to delete

Any ideas on how to run this code inside a c# .net application please
Rgds
stephen
stephenwildeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
käµfm³d 👽Connect With a Mentor Commented:
Yes. You have to redirect output before you can read it, though. Here is an example. Be sure to leave "UseShellExecute = false", otherwise you will get an error when you try to redirect.
using System.Diagnostics;

...

ProcessStartInfo info = new ProcessStartInfo("cmd", "dnscmd /zonedelete domainnametodelete.tld /f");

info.UseShellExecute = false;
info.RedirectStandardOutput = true;

Process p = Process.Start(info);

p.WaitForExit();

string output = p.StandardOutput.ReadToEnd();

Open in new window

0
 
käµfm³d 👽Commented:

System.Diagnostics.Process.Start("dnscmd", "/zonedelete domainnametodelete.tld /f");

Open in new window

0
 
käµfm³d 👽Commented:
Or possibly:
System.Diagnostics.Process.Start("cmd", "dnscmd /zonedelete domainnametodelete.tld /f");

Open in new window

0
Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

 
stephenwildeAuthor Commented:
Thanks

Is there a way to capture the response text from the cmd?

Rgds
stephen
0
 
stephenwildeAuthor Commented:
Thanks very much
0
 
käµfm³d 👽Commented:
NP. Glad to help  :)
0
All Courses

From novice to tech pro — start learning today.