zoukankan      html  css  js  c++  java
  • C#判断是否是以管理员权限允许当前应用

    private static bool CheckForAdminRights()
    		{
    			string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), string.Format("tfadxp{0}.txt", "80"));
    			try
    			{
    				if (File.Exists(path))
    				{
    					File.Delete(path);
    				}
    				using (StreamWriter streamWriter = File.CreateText(path))
    				{
    					streamWriter.WriteLine("test successful - {0}", DateTime.Now);
    					streamWriter.Close();
    				}
    				if (!File.Exists(path))
    				{
    					return AdminRightsError();
    				}
    				File.Delete(path);
    			}
    			catch (Exception)
    			{
    				return AdminRightsError();
    			}
    			return true;
    		}
    
    		private static bool AdminRightsError()
    		{
    			MessageBox.Show("I can not continue, You should run me with administrative priveleges.
    
    Right click on me and select "Run as administrator" menu.", "You are NOT ADMINISTRATOR!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
    			return false;
    		}
    
  • 相关阅读:
    Go 指针
    Go 字符串
    Go Maps
    Go 可变参数函数
    Go 数组和切片
    pyqt5实现窗口跳转并关闭上一个窗口
    spy++查找窗口句柄
    Python中Tk模块简单窗口设计
    pyqt5无边框拖动
    pyqt5 GUI教程
  • 原文地址:https://www.cnblogs.com/AlexanderZhao/p/12878842.html
Copyright © 2011-2022 走看看