![]() String DNS = ("Whats the DNS server IP?(Input required, 8.8.4.4 has already been set as secondary)", "", "", 100, 100) String DEFAULTGATEWAY = ("Whats the Default gateway?", "", "", 100, 100) These open pop up boxes which ask for user input You will need this for it to work public static void SetIPStatic() This is for setting the computer IP as static but asking the user what the IP, gateway, and dns server is. IF you want user input then you could try something like this. Using (StreamWriter outputFile = new StreamWriter(Path.Combine(docPath, "test.bat"))) "del \"%~f0\"" //do not put a comma on the last line remember its "", the comma separates the lines this is the path the document or in our case batch file will be placedĮnvironment.GetFolderPath() Here is an example, In this case the function is for a push button in windows forum app that clears the print queue. ![]() it will take trial and error with this way because its like controlling a puppet with another puppet. If you want user input you could place the input into a variable and have c# write it into the file. If it can be done with a batch file then the maybe over complicated work around is have c# write a. And this is my tried and tested way of doing this, there may be a simpler way but this is from me throwing code at a wall and seeing what stuck This may be a bit of a read so im sorry in advance. ObjThread.Priority = ThreadPriority.AboveNormal Thread objThread = new Thread(new ParameterizedThreadStart(ExecuteCommandSync)) Asynchronously start the Thread to process the Execute command request. Public static void ExecuteCommandAsync(string command) String result = () Ĭonsole.WriteLine("ExecuteCommandSync failed" + objException.Message) ![]() Now we create a process, assign its ProcessStartInfo and start it ProcStartInfo.RedirectStandardOutput = true This means that it will be redirected to the Process.StandardOutput StreamReader. The following commands are needed to redirect the standard output. procStartInfo = new ("cmd", "/c " + command) Incidentally, /c tells cmd that we want it to execute the command that follows, and then exit. create the ProcessStartInfo using "cmd" as the program to be run, and "/c " as the parameters. Public static void ExecuteCommandSync(object command) / Executes a shell command synchronously. you can you this class: public static class ExecuteCmd If you want to run the command in async mode - and print the results.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |