Posts Tagged ‘windows’

.NET MONO Which Operating System is Running?

Monday, June 28th, 2010

Do you want to execute operating system specific code (exes) in the .NET/Mono framework? I’ll go over how you can do that.

Below is part of a class I had written that can determine if Linux or Windows is running. Keep in mind that for the code to properly detect Mac OS, you will need to figure out the proper platform number and modify the code respectively.

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace namespace1
{
 static class HostOS
 {
  /// <summary>
  /// an enumerator that holds a list of possible operating systems
  /// this code can execute on
  /// </summary>
  public enum HostEnviroment
  {
   Windows,
   Linux
  }

  /// <summary>
  /// determine the operating system this program is running on
  /// </summary>
  /// <returns>the current operating system</returns>
  /// <remarks>
  /// the current choices are only linux or windows
  /// it really only checks to see if the OS is linux,
  /// otherwise, it defaults to windows
  /// if other OS are inplemented in the future, this
  /// would need to be changed
  /// </remarks>
  public static HostEnviroment determineHostEnviroment()
  {
   HostEnviroment currentHost;

   int platformNumber = (int)Environment.OSVersion.Platform;

   //determine if the host is a *nix operating system
   //these numbers take into account historic values,
   //do an internet search for details
   if ((platformNumber == 4) || (platformNumber == 6)
   || (platformNumber == 128))
   {
    //running on *nix
    currentHost = HostEnviroment.Linux;
   }
   else
   {
    //not running on *nix (this function defaults to windows)
    currentHost = HostEnviroment.Windows;
   }

   return currentHost;
  }

  //............
 }
}

I had written this class because I have been writing code that I develop on Windows, but needs to run in Linux. Ideally, I wanted it to work in both operating systems for various reasons. The program I was writing needed to call a few console applications that were operating system specific, but had versions for both Windows and Linux. Thanks to the System.Diagnostics namespace, it’s quite easy to run the OS specific code!

Virtualization

Friday, March 20th, 2009

I’ve been interested lately in using virtualization to setup a “computer” to do local web development on. I’m looking to configure it it closely as possible to my paid hosting, so that it will be as easy as possible when I take a project and migrate it over to to the host.

If you haven’t had any experience with virtualization, it’s basically a way of running an operating system inside whatever operating system you are currently using. The nice thing about it these days is that more recent processors have hardware extension to improve performance to the level where it’s quite usable. The software mimics all aspects of a basic computer with standard hardware. So you take your operating system install disk and go through the process as you normally would.

I am currently using Windows Vista Ultimate x64. So looking at the easiest option, I downloaded and installed Microsoft’s free “Virtual PC 2007″ program.

I’ve used it before, but don’t recall doing anything of consequence with it. It’s a simple program, but it seems quite stable and provided everything that I need.

I considered using it with my copy of say… Windows 2000, but that would be pointless as my hosting is Linux based. Seeing as while I’m coding I want to deal with paths as they would be in Linux, I’ve decided to try going that route.

I started by downloading Ubuntu server. I installed it with success, but when the OS restarted, I was greeted by some crazy looking visuals. According to various sites on the net have pointed out, Virtual PC does not support a 24-bit graphics rendering in the virtual video card, and Linux defaults to 24-bit… Seeing as the terminal was nearly unusable, I went back to unbuntu.com and downloaded Xubuntu, which is a lighter weight version that uses XFce. The only negative here is that I will have to manually install and configure the “LAMP” server. A key thing to remember when installing Xubuntu is that when it gives you options before starting the install, select F4 and change the video more to fail-safe mode.

I’ll try to provide updates as I work through the issues.




The Way Of Coding



 
Scott J. Waldron Photography
Stock Photo Website
Tech Learning Site

Popular Article Tags

Archives

Pages