C# 2005 Programmer’s Reference - chapter 26

Tham khảo tài liệu 'c# 2005 programmer’s reference - chapter 26', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 580 CHAPTER 26 Interacting with the OS and Hardware very important--icon won t show up without this The Win32 class is a simple wrapper for P Invoked functionality see the section Call Native Windows Functions Using P Invoke later in this chapter class Win32 DllImport public static extern IntPtr SendMessage HandleRef hWnd UInt32 Msg IntPtr wParam IntPtr lParam defined in public const UInt32 BCM_SETSHIELD 0X0000160C It is impossible to elevate a process s privileges once the process has started so the technique is to start your same process as an admin and pass it some command-line arguments or otherwise communicate with it to tell it what to do. That second process will do the required behavior then exit. Leaving the second elevated process running and having the first exit is not recommended your programs should always run with the least privilege possible. Here is the button event handler which has to do something requiring elevation private void buttonCreateSource_Click object sender EventArgs e you can t elevate the current process--you have to start a new one ProcessStartInfo startInfo new ProcessStartInfo -createEventSource trigger the UAC prompt runas try Process proc startlnfo catch Exception ex There was an error launching the elevated process Write to the Event Log 581 Then when the program starts you can look for the arguments STAThread static void Main string args foreach string arg in args if -createEventSource arg 0 we should be running as admin now so attempt the privileged operation CreateEventSource don t need to show UI--we re already running it so just exit return false new Form1 Write to the Event Log Scenario Problem .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.