Change Current Linux User in a C# Application Running with Mono

Change current Linux user in a C# application running with Mono?

The following works on my box :)

EDIT #1: This should be executed as root. (Snippet taken from : http://msdn.microsoft.com/en-us/library/w070t6ka.aspx)

using System;
using System.Security.Permissions;
using System.Security.Principal;

public class ImpersonationDemo
{
// Test harness.
// If you incorporate this code into a DLL, be sure to demand FullTrust.
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public static void Main (string[] args)
{
try {
// Check the identity.
Console.WriteLine ("Before impersonation: " + WindowsIdentity.GetCurrent ().Name);

// Impersonate a user
using (WindowsIdentity newId = new WindowsIdentity("Your user name"))
using (WindowsImpersonationContext impersonatedUser = newId.Impersonate())
{
// Check the identity.
Console.WriteLine ("After impersonation: " + WindowsIdentity.GetCurrent ().Name);
}

// Releasing the context object stops the impersonation
// Check the identity.
Console.WriteLine ("After closing the context: " + WindowsIdentity.GetCurrent ().Name);
} catch (Exception ex) {
Console.WriteLine ("Exception occurred. " + ex.Message);
}
}
}

Application Settings with Mono under Linux

I found that Mono stores the user settings in ~/.local/share/. There were already settings there(without me knowing) of a different version of the program. I just deleted the folder and Mono saved the new one. Everything worked fine:)

Mono application recording desktop/running application into movie

I would try OBS as it is cross-platform by nature.

It may not be the right fit licensing wise, so pay attention to this front.

As far as the Official development, C# is not the language of choice used to develop OBS, but there are others out there who have made some headway on this front.

I would recommend GoaLitiuM's C# wrapper re-write "libobs-sharp" as a starting point, as Mono is a part of this user's goals in the effort.


Appended Information


If you are not happy with the progress of the open source community's efforts, you can always download the OBS source yourself, and begin to make your own wrapper(s) as well.

This article may be helpful

Feasibility of C# development with Mono

  1. (Strange, markdown starts the enumeration with one, even though I began with 2...)

  2. Yes, you can, but you're limited with 3rd-party components, because the internal implementation is different, and last time I checked (not very long ago), the Mono WinForms implementation made my test app look rather strange (owner-drawn list view). It is not really recommended, though Mono claims that it's now completely WinForms-2.0-compatible.

  3. MonoDevelop is/was a SharpDevelop branch, with the latter having solution support. I don't know if MonoDevelop has. But the cool thing is, you can just develop with Visual Studio and run your compiled apps on Mono. And Mono is, by the way, also available for Windows.

  4. Yes, it does, as far as the CLR goes. As Marc Gravell already wrote, the Windows Foundation libraries are missing, as are a few other (System.Management, for example). But things should mostly work, including ASP.NET 2.0. Mono's application portability guidelines are a good read on this.

Console app works on Windows, doesn't on Linux with Mono

It turns out this problem was only a symptom of something bigger. I perform reading commands from a Task. Mono that I use (version 4.1.3) apparently has a bug that prevents some Tasks from starting, so I explicitly declared a Thread instead.



Related Topics



Leave a reply



Submit