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;
    		}
    
  • 相关阅读:
    ddd
    对Map按key和value分别排序
    两端通信
    WinDBG调试.NET程序示例
    FAQ:仓储实现为什么在基础设施层?
    Please Send Me a Card
    Web API 入门指南
    Node.js
    聊天工具mychat
    C语言面试问答5
  • 原文地址:https://www.cnblogs.com/AlexanderZhao/p/12878842.html
Copyright © 2011-2022 走看看