El Bruno

El día a día de un Microsoft developer

Menú

Saltar al contenido
  • Inicio
  • Acerca de / About
  • Cómo convencer a tu jefe de utilizar Team Foundation Server
  • TFS On The Cloud: ¡apuesta por el futuro!

Archivo de la categoría: User Account Control

[#CLICKONCE] HowTo: Launch an app deployed with ClickOnce with administrator privileges

Posted on 12 julio, 2012 by elbruno

image

Buenas,

the answer to the question:

Is it possible to launch an application deployed with ClickOnce with administrator permissions?

It has a very simple answer:

NOT

The solution is two paragraphs later, so you can save the following text. The correct way to define an application requires certain permissions is through a manifesto. In it, you can indicate everything that requires an application at run time. The step by step, is on MSDN and is described in:

  • Step 6: Create and Embed an Application Manifest (UAC)
    http://msdn.Microsoft.com/en-us/library/bb756929.aspx http://msdn.Microsoft.com/en-us/library/bb756929.aspx

The problem is that if we have an application that then we deploy with ClickOnce, we apply this change in the manifest, and then try to compile we find a beautiful

image

Error 1 ClickOnce does not support the request execution level ‘requireAdministrator’.

And now? as one of the solutions comes from the hand of this post , where what is being done is basically to check if the application is launched with ADMIN and otherwise permits, launch the application again with the appropriate permissions.

I have created a small class that in addition to applying this process displays a message warning that the application will be launched again.

   1: public class RunAsAdministrator

   2: {

   3:     public bool IsRunAsAdministrator()

   4:     {

   5:         var windowsIdentity = WindowsIdentity.GetCurrent();

   6:         var windowsPrincipal = new WindowsPrincipal(windowsIdentity);

   7:         return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);

   8:     }

   9:  

  10:     public static void ValidateAdministratorModeAndRestart(bool displayMessage)

  11:     {

  12:  

  13:         var runAsAdministrator = new RunAsAdministrator();

  14:         if (runAsAdministrator.IsRunAsAdministrator()) return;

  15:  

  16:  

  17:         if (displayMessage)

  18:         {

  19:             var fi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);

  20:             string productName = fi.FileDescription;

  21:             MessageBox.Show(string.Format("{0} will launch itself with admin privileges", productName));

  22:         }

  23:  

  24:         var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase)

  25:                               {

  26:                                   UseShellExecute = true,

  27:                                   Verb = "runas"

  28:                               };

  29:         try

  30:         {

  31:             Process.Start(processInfo);

  32:         }

  33:         catch (Exception)

  34:         {

  35:             MessageBox.Show("Sorry, this application must be run as Administrator.");

  36:         }

  37:         Application.Current.Shutdown();

  38:     }

  39: }

In my case it was enough and with some exceptions that occur to me from memory, I think it may be enough Open-mouthed smile

Source: http://antscode.blogspot.com.es/2011/02/running-ClickOnce-application-as.html

Saludos @ Home

El Bruno

image image image

Share this:

  • Compartir
  • StumbleUpon

Me gusta:

Me gusta Cargando...
Publicado en ClickOnce, EnglishPost, HowTo, User Account Control | Dejar un comentario

[#CLICKONCE] HowTo: Lanzar una app desplegada con ClickOnce con privilegios de administrador

Posted on 12 julio, 2012 by elbruno

image

Buenas,

la respuesta a la pregunta:

¿Es posible lanzar una aplicación desplegada con ClickOnce con permisos de administrador?

tiene una respuesta muy simple:

NO

La solución viene dos párrafos después, así que te podes ahorrar el siguiente texto. La forma correcta de definir que una aplicación requiera ciertos permisos es a través de un manifiesto. En el mismo, se puede indicar TODO lo que requiere una aplicación al momento de ejecutarse. El paso a paso, está en MSDN y se describe en:

  • Step 6: Create and Embed an Application Manifest (UAC)
    http://msdn.microsoft.com/en-us/library/bb756929.aspxhttp://msdn.microsoft.com/en-us/library/bb756929.aspx

El problema es que si tenemos una aplicación que luego desplegaremos con ClickOnce, aplicamos este cambio en el manifiesto y luego intentamos compilar nos encontramos con un hermoso

image

Error    1    ClickOnce does not support the request execution level ‘requireAdministrator’.  

Y ahora? pues una de las soluciones viene de la mano de este post, donde lo que se hace es básicamente verificar si la aplicación se lanza con permisos de ADMIN y en caso contrario, lanzar la aplicación nuevamente con los permisos adecuados.

He creado una pequeña clase que además de aplicar este proceso, muestra un mensaje avisando que se lanzará nuevamente la aplicación.

   1: public class RunAsAdministrator

   2: {

   3:     public bool IsRunAsAdministrator()

   4:     {

   5:         var windowsIdentity = WindowsIdentity.GetCurrent();

   6:         var windowsPrincipal = new WindowsPrincipal(windowsIdentity);

   7:         return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);

   8:     }

   9:  

  10:     public static void ValidateAdministratorModeAndRestart(bool displayMessage)

  11:     {

  12:  

  13:         var runAsAdministrator = new RunAsAdministrator();

  14:         if (runAsAdministrator.IsRunAsAdministrator()) return;

  15:  

  16:  

  17:         if (displayMessage)

  18:         {

  19:             var fi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);

  20:             string productName = fi.FileDescription;

  21:             MessageBox.Show(string.Format("{0} will launch itself with admin privileges", productName));

  22:         }

  23:  

  24:         var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase)

  25:                               {

  26:                                   UseShellExecute = true,

  27:                                   Verb = "runas"

  28:                               };

  29:         try

  30:         {

  31:             Process.Start(processInfo);

  32:         }

  33:         catch (Exception)

  34:         {

  35:             MessageBox.Show("Sorry, this application must be run as Administrator.");

  36:         }

  37:         Application.Current.Shutdown();

  38:     }

  39: }

En mi caso ha bastado y salvo algunas excepciones que se me ocurren de memoria, creo que puede bastar Open-mouthed smile

Source: http://antscode.blogspot.com.es/2011/02/running-clickonce-application-as.html

Saludos @ Home

El Bruno

image image image

Share this:

  • Compartir
  • StumbleUpon

Me gusta:

Me gusta Cargando...
Publicado en ClickOnce, HowTo, User Account Control | Dejar un comentario

El Bruno

100316_Cubierta-VisualStudio2010

Follow me @ElBruno

  • [#KINECT] Que hay de nuevo en Kinect 2.0 (se llamará así?) wp.me/p1lnOY-1bi 1 hour ago
  • [#EVENT] Materials of the event of working AGILE with #VS2012 and #TFS2012 wp.me/p1lnOY-1aY 1 hour ago
  • [#EVENT] WebCast on #AGILE with Visual Studio and Team Foundation Server 2012 #VS2012 #ALM blogtopsites.com/p/21984002 15 hours ago
  • [#EVENT] Materiales del evento de trabajo AGILE con #VS2012 y #TFS2012 blogtopsites.com/p/21984001 15 hours ago
  • [#EVENT] Materiales del evento de trabajo AGILE con #VS2012 y #TFS2012 wp.me/p1lnOY-1aW 16 hours ago
Follow @elbruno

Buscar

El Bruno

Introduce tu dirección de correo electrónico para seguir este Blog y recibir las notificaciones de las nuevas publicaciones en tu buzón de correo electrónico.

Únete a otros 1.230 seguidores

Cloud

ALM CodePlex Code Sample EnglishPost Enterprise Library Event HowTo Informática e Internet Kinect KinectSdk MSN, Microsoft Opinion Personal Programacion ReSharper Sin categoría Source Control Team Build 2010 Team Foundation Server Team Foundation Server 11 Team Foundation Server 2012 Team Foundation Service Tutorial Visual Studio Visual Studio 2005 Visual Studio 2010 Visual Studio 2012 Visual Studio Gallery Windows 8 WorkItemTracking

@ElBruno

  • [#KINECT] Que hay de nuevo en Kinect 2.0 (se llamará así?) wp.me/p1lnOY-1bi 1 hour ago
  • [#EVENT] Materials of the event of working AGILE with #VS2012 and #TFS2012 wp.me/p1lnOY-1aY 1 hour ago
  • [#EVENT] WebCast on #AGILE with Visual Studio and Team Foundation Server 2012 #VS2012 #ALM blogtopsites.com/p/21984002 15 hours ago
  • [#EVENT] Materiales del evento de trabajo AGILE con #VS2012 y #TFS2012 blogtopsites.com/p/21984001 15 hours ago
  • [#EVENT] Materiales del evento de trabajo AGILE con #VS2012 y #TFS2012 wp.me/p1lnOY-1aW 16 hours ago

Categorías

Popular posts

  • [MICROPOST] Mi Libro de Visual Studio 2010 disponible en PDF
  • [#EVENT] Materiales del evento de trabajo AGILE con #VS2012 y #TFS2012
  • [#EVENT] WebCast sobre #AGILE con Visual Studio 2012 y Team Foundation Server 2012 #VS2012 #ALM
  • [#EVENT] MSDN Latam: Webcast MSDN: Todos a bordo del Team Foundation Server Express
  • [#EVENT] WebCast on #AGILE with Visual Studio and Team Foundation Server 2012 #VS2012 #ALM

Entradas Recientes

  • [#KINECT] What’s new in the Kinect #XboxOne
  • [#KINECT] Que hay de nuevo en Kinect 2.0 (se llamará así?)
  • [#EVENT] Materials of the event of working AGILE with #VS2012 and #TFS2012
  • [#EVENT] Materiales del evento de trabajo AGILE con #VS2012 y #TFS2012
  • [#EVENT] WebCast on #AGILE with Visual Studio and Team Foundation Server 2012 #VS2012 #ALM
  • [#EVENT] WebCast sobre #AGILE con Visual Studio 2012 y Team Foundation Server 2012 #VS2012 #ALM
  • [#ALM] Do you ever wondered why we do use methodologies? (and again PAIN is the solution)
  • [#ALM] Alguna vez te has preguntado porqué utilizamos metodologías? (y de nuevo el Dolor es la solución)
  • [#VS2012] Image Comment, an interesting AddIn for #VisualStudio2012
  • [#VS2012] Image Comment, un AddIn interesante para #VisualStudio2012

Translate

Traducir esta página
Con tecnología de Microsoft® Translator

/* */

Blog de WordPress.com. | Tema Superhero por Automattic.
Seguir

Recibe cada nueva publicación en tu buzón de correo electrónico.

Únete a otros 1.230 seguidores

Ofrecido por WordPress.com
%d bloggers like this: