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?

Improve company productivity with a Business Account.Sign Up

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
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.