Запуск привилегированной программой других программ, но с ограниченными правами - C#

Узнай цену своей работы

Формулировка задачи:

Программа запущена от имени администратора, в ней присутствует запуск других программ, и по дефолту они запускаются тоже от админа, как этого избежать? То есть запустить программу с привилегиями обычного пользователя?
Мне кажется рыть нужно в сторону Verb, ну как с verb = runas в случае с запуском от админа

Решение задачи: «Запуск привилегированной программой других программ, но с ограниченными правами»

textual
Листинг программы
  1. [DllImport("native-helpers.dll", CallingConvention = CallingConvention.Cdecl)]
  2. static extern void ShellExecuteFromExplorer(
  3.     [MarshalAs(UnmanagedType.LPWStr)] string file,
  4.     [MarshalAs(UnmanagedType.LPWStr)] string arguments,
  5.     [MarshalAs(UnmanagedType.LPWStr)] string directory,
  6.     [MarshalAs(UnmanagedType.LPWStr)] string verb,
  7.     WindowShowStyle windowStyle
  8. );
  9.  
  10. enum WindowShowStyle
  11. {
  12.     /// <summary>Hides the window and activates another window.</summary>
  13.     /// <remarks>See SW_HIDE</remarks>
  14.     Hide = 0,
  15.     /// <summary>Activates and displays a window. If the window is minimized
  16.     /// or maximized, the system restores it to its original size and
  17.     /// position. An application should specify this flag when displaying
  18.     /// the window for the first time.</summary>
  19.     /// <remarks>See SW_SHOWNORMAL</remarks>
  20.     ShowNormal = 1,
  21.     /// <summary>Activates the window and displays it as a minimized window.</summary>
  22.     /// <remarks>See SW_SHOWMINIMIZED</remarks>
  23.     ShowMinimized = 2,
  24.     /// <summary>Activates the window and displays it as a maximized window.</summary>
  25.     /// <remarks>See SW_SHOWMAXIMIZED</remarks>
  26.     ShowMaximized = 3,
  27.     /// <summary>Maximizes the specified window.</summary>
  28.     /// <remarks>See SW_MAXIMIZE</remarks>
  29.     Maximize = 3,
  30.     /// <summary>Displays a window in its most recent size and position.
  31.     /// This value is similar to "ShowNormal", except the window is not
  32.     /// actived.</summary>
  33.     /// <remarks>See SW_SHOWNOACTIVATE</remarks>
  34.     ShowNormalNoActivate = 4,
  35.     /// <summary>Activates the window and displays it in its current size
  36.     /// and position.</summary>
  37.     /// <remarks>See SW_SHOW</remarks>
  38.     Show = 5,
  39.     /// <summary>Minimizes the specified window and activates the next
  40.     /// top-level window in the Z order.</summary>
  41.     /// <remarks>See SW_MINIMIZE</remarks>
  42.     Minimize = 6,
  43.     /// <summary>Displays the window as a minimized window. This value is
  44.     /// similar to "ShowMinimized", except the window is not activated.</summary>
  45.     /// <remarks>See SW_SHOWMINNOACTIVE</remarks>
  46.     ShowMinNoActivate = 7,
  47.     /// <summary>Displays the window in its current size and position. This
  48.     /// value is similar to "Show", except the window is not activated.</summary>
  49.     /// <remarks>See SW_SHOWNA</remarks>
  50.     ShowNoActivate = 8,
  51.     /// <summary>Activates and displays the window. If the window is
  52.     /// minimized or maximized, the system restores it to its original size
  53.     /// and position. An application should specify this flag when restoring
  54.     /// a minimized window.</summary>
  55.     /// <remarks>See SW_RESTORE</remarks>
  56.     Restore = 9,
  57.     /// <summary>Sets the show state based on the SW_ value specified in the
  58.     /// STARTUPINFO structure passed to the CreateProcess function by the
  59.     /// program that started the application.</summary>
  60.     /// <remarks>See SW_SHOWDEFAULT</remarks>
  61.     ShowDefault = 10,
  62.     /// <summary>Windows 2000/XP: Minimizes a window, even if the thread
  63.     /// that owns the window is hung. This flag should only be used when
  64.     /// minimizing windows from a different thread.</summary>
  65.     /// <remarks>See SW_FORCEMINIMIZE</remarks>
  66.     ForceMinimized = 11
  67. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

15   голосов , оценка 3.733 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы