ハブ上および一般的にネットワーク上には、「UACを無効にする方法」、「UACをバイパスする方法」などのトピックに関する記事が多数あります。しかし、なぜ無効にするのが便利なのでしょうか。 なぜ私たちは侵入者ではないのですか?
友達になる必要があります!
以下に、アプリケーションでこれを行う方法を説明します。
マニフェスト
最初に、私の意見では、最も単純でgliいオプションを検討してください-マニフェストの編集。 なぜ彼は悪いのですか? これは、常に管理者権限が必要なアプリケーションにのみ適しています。 それはどのように見えますか? アプリケーションを起動すると、ユーザーは使い慣れたウィンドウを受け取ります。このウィンドウで、管理者権限でアクションを実行するためのプログラムの許可を確認する必要があります。 したがって、プログラムを開始するたびに。 原則として、このオプションは、まれに1つのインスタンスで実行されるプログラムに使用できます。
そのようなアプリケーションを自動実行に入れることは不可能であるとすぐに言わなければなりません(どうしても必ずではなく、少なくともレジストリを通じて)。 Windowsは、UACウィンドウを表示せずに、開始時にそれらを単に非難します。 おそらくこの場合、Windowsサービステクノロジを使用するのが理にかなっています。
したがって、実装( ここから取得)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level="asInvoker" uiAccess="false"/> </requestedPrivileges> </security> </trustInfo> </assembly>
:
- asInvoker — (-). -.
- highestAvailable — . .. , .
- requireAdministrator — . .
. , , , , , .
, , ( UAC). , . (, , C#):
public static bool IsAdmin() { System.Security.Principal.WindowsIdentity id = System.Security.Principal.WindowsIdentity.GetCurrent(); System.Security.Principal.WindowsPrincipal p = new System.Security.Principal.WindowsPrincipal(id); return p.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator); }
, . ? , - , . . :
public static void RunAsAdmin(string aFileName, string anArguments) { System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo(); processInfo.FileName = aFileName; processInfo.Arguments = anArguments; processInfo.UseShellExecute = true; processInfo.Verb = "runas"; // System.Diagnostics.Process.Start(processInfo); }
? :
1. . , . WinAPI .NET, , . DHCP Client, ,
sc.exe start dhcp
, .
2. . , WinAPI , . , . , , ..
2. . , . . , Windows , - .
3. . , , . . - , . , StackOverflow , , .
4. . , : . ( IsAdmin()) , , , . (IsAdmin() true) .
, . UAC, «» .
, - . .
UAC .
, link-label' , UAC. , , , , .
WinForms- .
[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr SendMessage(HandleRef hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); public static void SetButtonShield(Button btn, bool showShield) { // BCM_SETSHIELD = 0x0000160C btn.FlatStyle = FlatStyle.System; SendMessage(new HandleRef(btn, btn.Handle), 0x160C, IntPtr.Zero, showShield ? new IntPtr(1) : IntPtr.Zero); }
, WinForms WPF, . , ImageSource - , .
System.Drawing.Icon img = System.Drawing.SystemIcons.Shield; System.Drawing.Bitmap bitmap = img.ToBitmap(); IntPtr hBitmap = bitmap.GetHbitmap(); ImageSource wpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
, .
, ( MessageBox). , . , , .
, .
, , UAC. github.
, .