background preloader

Microsoft Software Dev

Facebook Twitter

C# Code Snippet - Execute Shell Commands from .Net. (C-Sharp) C# code snippet creates a command process and then invokes the command that we want to execute.

C# Code Snippet - Execute Shell Commands from .Net

The result of the command and any errors occurred during execution is stored in a string variables. This is a great method to execute your DOS commands from .Net. This .Net C# code snippet executes a shell command. To use this function simply provide the file/command to execute, command line parameters (optional), string variable to store output and string variable to store errors occurred during execution. The code creates a command process and then invokes the command that we want to execute. Here is a simple example showing how to use above function (ExecuteShellCommand) to execute a simple DOS dir command and show output result in a richtextbox. This example shows how to use above method to execute DOS del command to delete all the ZIP files in c:\temp folder using .Net. C# Keywords Used: ProcessFormatProcessStartInfoEnvironmentSystemDirectoryInvariantCultureWin32ExceptionException. Shell Commands within C#

In this article we will examine a few examples for executing shell commands outside of our program using C#.

Shell Commands within C#

In VB.Net, we can make use of the familiar Shell command to run an executable program. However the Shell function is not available in C#. The Process Class provides access to local and remote processes and enables you to start and stop local system processes. In our example we will create an example for running the following processes from our program. Calculator DOS Batch program - Map a network drive Internet explorer with a specified URL Specified Document in Microsoft Word. C# Application Our basic application is a Winforms Visual C# application and will consist of a Windows Form with button controls to invoke the processes specified in the list.

Add button controls from the toolbox as shown in the figure below. Figure 1: Basic Windows Form Calculator The option to provide a calculator to the end user on the click of a button can be very useful. Map a network Drive. Nilzor's Techblog: Android vs WP7 for developers - a case study. Introduction I started my mobile apps "development career" last year by publishing a couple of tools for the Windows Mobile 6.5 platform.

Nilzor's Techblog: Android vs WP7 for developers - a case study

I quickly grew fond of the whole apps concept - low threshold for getting started and small programs meaning short projects time-wise. Also the platform took care of the distribution and monetary transactions for me, so that I could care about the thing I find most fun - coding. It didn't take very long until I realized I had to start thinking about other platforms, though. The Windows Mobile 6.x platform (WM6.x for short) was already lagging behind Apple and Google user experience-wise, and the nail in the coffin came when Microsoft announced Windows Phone 7.

Microsoft seemed very serious about their new venture. The Android platform, which HTC seemed to embrace here in Scandinavia, was quickly growing in popularity. iPhone had been the sole market leader for a couple of years and I think the public wanted something new and fresh. The App. Lessons from Evernote’s flight from .NET. By tim, on October 27th, 2010 Follow tim on Twitter Evernote has released version 4.0 of its excellent note-taking product.

Lessons from Evernote’s flight from .NET

Software developers have taken particular interest in the blog post announcing its release, because of what it says about .NET, in this case the Windows Presentation Foundation, versus native code: Evernote 4 is a major departure from Evernote 3.5 in every way. While 3.5 added tons of great new features, there were some problems we simply couldn’t fix: the blurry fonts, slow startup times, large memory footprint, and poor support for certain graphics cards were all issues that the technology behind 3.5 (Windows .net and WPF) was incapable of resolving. As a result, we ended up chasing down platform bugs rather than adding the great features our users wanted. A bit of background. WPF is not only based on .NET. So what are the lessons here? It is not so simple. After I tweeted about Evernote’s experience, a couple of Microsoft folk contacted me to make this point.