473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Detecting OS ? (mono/.NET)

Hi,

I am currently building an application in C# using mono and .NET. I
want to get a MIME type for a specific file, which is why I want to
detect the OS on which the application is running. On Windows, I would
look up the registry, on Linux/OSX/etc. I would look in
/etc/mime-types (or where the mime types are located). How would I
detect the OS ?

I have tried the following:

OperatingSystem os = Environment.OSVersion;
Version vs = os.Version;

This gives me: "5.1.2600" on Linux :-)

Maybe it is better to build a MIME database on my own instead of
relying on the OS ?

Regards,

Christoffer
Nov 15 '05 #1
5 3494
I don't have a lot of details on the underlying implementation of Mono (just
because I haven't downloaded all the source).
However, I have a feeling that for "interoperability reasons", they fool
your code into believing you are running under windows. I can see where that
might come in handy, deceitful as it may be :-)

Perhaps you can try to use the DllImport tag to write a p/invoke function
call to a Windows dll (like perhaps one of the registry API functions). Wrap
this up in a Try-Catch, and if the function fails (because the DLL doesn't
exist), then you are not in Windows. The only catch may be if the system is
using Wine or some windows emulator on Linux.

-Rob Teixeira [MVP]

"Christoffer Soerensen" <sa********@hotmail.com> wrote in message
news:ac**************************@posting.google.c om...
Hi,

I am currently building an application in C# using mono and .NET. I
want to get a MIME type for a specific file, which is why I want to
detect the OS on which the application is running. On Windows, I would
look up the registry, on Linux/OSX/etc. I would look in
/etc/mime-types (or where the mime types are located). How would I
detect the OS ?

I have tried the following:

OperatingSystem os = Environment.OSVersion;
Version vs = os.Version;

This gives me: "5.1.2600" on Linux :-)

Maybe it is better to build a MIME database on my own instead of
relying on the OS ?

Regards,

Christoffer

Nov 15 '05 #2
OperatingSystem os = Environment.OSVersion;
MessageBox.Show("OS:" + os.Platform + "\nVer:" + os.Version +
"\nToString:" + os.ToString());

sa********@hotmail.com (Christoffer Soerensen) wrote in
news:ac**************************@posting.google.c om:
Hi,

I am currently building an application in C# using mono and .NET. I
want to get a MIME type for a specific file, which is why I want to
detect the OS on which the application is running. On Windows, I would
look up the registry, on Linux/OSX/etc. I would look in
/etc/mime-types (or where the mime types are located). How would I
detect the OS ?

I have tried the following:

OperatingSystem os = Environment.OSVersion;
Version vs = os.Version;

This gives me: "5.1.2600" on Linux :-)

Maybe it is better to build a MIME database on my own instead of
relying on the OS ?

Regards,

Christoffer


Nov 15 '05 #3
> > This gives me: "5.1.2600" on Linux :-)

You are having this problem because Mono is simulating a Windows XP
environment.

"chris" <so**@one.com> wrote in message
news:OI**************@TK2MSFTNGP09.phx.gbl...
OperatingSystem os = Environment.OSVersion;
MessageBox.Show("OS:" + os.Platform + "\nVer:" + os.Version +
"\nToString:" + os.ToString());

sa********@hotmail.com (Christoffer Soerensen) wrote in
news:ac**************************@posting.google.c om:
Hi,

I am currently building an application in C# using mono and .NET. I
want to get a MIME type for a specific file, which is why I want to
detect the OS on which the application is running. On Windows, I would
look up the registry, on Linux/OSX/etc. I would look in
/etc/mime-types (or where the mime types are located). How would I
detect the OS ?

I have tried the following:

OperatingSystem os = Environment.OSVersion;
Version vs = os.Version;

Maybe it is better to build a MIME database on my own instead of
relying on the OS ?

Regards,

Christoffer

Nov 15 '05 #4
thats the version number...and is the same as what i get on xp pro so it
doesnt look good, but what does the platform property return?

im omw to install the runtime on my mandrake box tonight...
"Nick" <ne**@zigamorph.com> wrote in news:uE#QvluzDHA.2240
@TK2MSFTNGP10.phx.gbl:
> This gives me: "5.1.2600" on Linux :-)
You are having this problem because Mono is simulating a Windows XP
environment.

"chris" <so**@one.com> wrote in message
news:OI**************@TK2MSFTNGP09.phx.gbl...
OperatingSystem os = Environment.OSVersion;
MessageBox.Show("OS:" + os.Platform + "\nVer:" + os.Version +
"\nToString:" + os.ToString());

sa********@hotmail.com (Christoffer Soerensen) wrote in
news:ac**************************@posting.google.c om:
> Hi,
>
> I am currently building an application in C# using mono and .NET. I
> want to get a MIME type for a specific file, which is why I want to
> detect the OS on which the application is running. On Windows, I would > look up the registry, on Linux/OSX/etc. I would look in
> /etc/mime-types (or where the mime types are located). How would I
> detect the OS ?
>
> I have tried the following:
>
> OperatingSystem os = Environment.OSVersion;
> Version vs = os.Version;
>

>
> Maybe it is better to build a MIME database on my own instead of
> relying on the OS ?
>
> Regards,
>
> Christoffer



Nov 15 '05 #5
chris <so**@one.com> wrote in message news:<OI**************@TK2MSFTNGP09.phx.gbl>...
OperatingSystem os = Environment.OSVersion;
MessageBox.Show("OS:" + os.Platform + "\nVer:" + os.Version +
"\nToString:" + os.ToString());


Thank you!

Output from my C# program using Mono:

"Version: 5.1.2600.0
Platform: 128
ToString: Unix 5.1.2600.0"

I haven't tried using MS .NET but probably the ToString string is
"Windows 5.1.2600.0" on XP.

Thanks for all suggestions.

Christoffer
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lethargy | last post by:
http://www.linuxjournal.com/article.php?sid=7554 The question for the Free Software community to ruminate is this: Is supporting Mono supporting our own desktop downfall? A statement attributed...
8
by: Everything Jute ! | last post by:
Programmers everyday are making a tragic error by not learning mono. Mono is te standard .net implementation for Windos and Linux. Learning mono is the key to writing fast, OOP, cross platform...
11
by: Tony Baker | last post by:
In order for my company to go ahead and use .Net and C# (over java), I need to know how to install and run a C# ASP.Net application not only on Windows, but on Linux. I'm a Windows developer,...
0
by: John Bailo | last post by:
http://www.onlamp.com/pub/wlg/7468 "Mono Live was released on May 24, 2005. Although there are several Live Linux CDs with Mono, they are all based on Knoppix and use KDE as the default Linux...
1
by: anonymous | last post by:
So, I was able to compile my Csharp program using Mono (http://www.go-mono.com/). It seems to still rely on .NET though. Is there a way to compile it so it will run independent of .NET?
3
by: Sanghyeon Seo | last post by:
I took some time to write this HOWTO: http://sparcs.kaist.ac.kr/~tinuviel/fepy/howto/simplehttpserver-ironpython-mono-howto.html IronPython seems to get much less interest than it deserves. This...
4
by: Vincent Courcelle | last post by:
Hello, Does someone experimented running ASP.NET 2 under Mono ? What about performances and compatibility ? I would like to run my application under windows but I can't (because of my hoster). ...
6
by: Twig | last post by:
Hi, Can I use strictly for C# development without missing anything from MS? Twig
2
by: flagos | last post by:
Hi to all! Any of you know if it's possible to use the Cairo graphics library in a WIN32 c# application? I know there is a binding made for Mono but my app will run on win32 so obviously I wont...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.