public static void Load()
{
if (NeedAdmin())
{
new Form().ShowDialog();
Environment.Exit();
}
}
public static bool NeedAdmin()
{
bool result;
if (Environment.OSVersion.Version.Major >= )
{
WindowsIdentity current = WindowsIdentity.GetCurrent();
WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current);
result = !windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
}
else
{
result = false;
}
return result;
}
private void BtnRunasAdmin_Click(object sender, EventArgs e)
{
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.WorkingDirectory = Application.StartupPath;
processStartInfo.FileName = Path.GetFileName(Application.ExecutablePath);
processStartInfo.Verb = "runas";
string[] commandLineArgs = Environment.GetCommandLineArgs();
if (commandLineArgs.Length > )
{
string text = "";
for (int i = ; i < commandLineArgs.Length; i++)
{
text += commandLineArgs[i];
}
processStartInfo.Arguments = text;
}
try
{
Process.Start(processStartInfo);
base.Close();
}
catch
{
base.Close();
}
}

[转]判断是否 Win7 且需要管理员权限的更多相关文章

  1. 实现在vista和win7中使用管理员权限接收WM_DROPFILES(OnDropFiles())消息的方法(好像XP不支持这个函数)

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #pragma once   #ifndef WM_COPYGLOBALD ...

  2. bat 判断 bat 是否是以管理员权限运行,和自动以管理员权限运行

    bat 判断 bat 是否是以管理员权限运行,和自动以管理员权限运行 判断 @echo off net.exe session 1>NUL 2>NUL && ( goto ...

  3. bat代码中判断 bat是否是以管理员权限运行,以及自动以管理员权限运行CMD BAT

    · bat 代码中判断bat是否是以管理员权限运行,以及自动以管理员权限运行CMD BAT 一.判断bat是否是以管理员权限运行 @echo off net.exe session >NUL & ...

  4. 判断当前进程是否以管理员权限运行(AllocateAndInitializeSid后,用CheckTokenMembership与AdministratorsGroup进行比较,和Delphi的那个例子还有点不一样)

    在Win7下(Vista以上的...)有时某些操作就是会让人郁闷 开启了UAC的话,得以管理员权限运行才不会出现Access is denied... 但是,程序又不是非得什么时候都用那破管理员权限的 ...

  5. VS2005 工程在win7下使用管理员权限运行

    想关资料 http://stackoverflow.com/questions/13030492/set-administrator-privilege-for-my-c-application-in ...

  6. WIN7操作平台获取管理员权限批处理

    在WIN7操作平台打开某些文件,如果需要管理员权限才能打开.通过下面的操作就可以获取管理员权限 创建批处理register文件.文件内容为,文件后缀名为.reg.然后双击该文件.打开需要访问的文件,如 ...

  7. vs2005 ,2008,2010中引入app.manifest(即c#程序在win7下以管理员权限运行方法)

    打开VS2005.VS2008.VS2010工程,查看工程文件夹中的Properties文件夹下是否有app.manifest这个文件:如没有,按如下方式创建:鼠标右击工程在菜单中选择“属性”,点击工 ...

  8. win7,win8取得管理员权限 .reg文件

    Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\runas] @="获取管理员所有权" " ...

  9. csharp:引入app.manifest,程序在win7下以管理员权限运行配置方法

    https://msdn.microsoft.com/en-us/library/windows/desktop/hh848036(v=vs.85).aspx https://msdn.microso ...

随机推荐

  1. python 复制/移动文件

    用python实现将某代码文件复制/移动到指定路径下. 场景例如:mv ./xxx/git/project1/test.sh ./xxx/tmp/tmp/1/test.sh (相对路径./xxx/tm ...

  2. SharePoint SSS(Security Store Service)服务-PowerShell

    1. 获取SSS应用程序的标识 Get-SPServiceApplication 2. 获取指定的SSS应用程序实例 $sss = Get-SPServiceApplication -Identity ...

  3. 【设计模式】 模式PK:工厂模式VS建造者模式

    1.概述 工厂方法模式注重的是整体对象的创建方法,而建造者模式注重的是部件构建的过程,旨在通过一步一步地精确构造创建出一个复杂的对象.我们举个简单例子来说明两者的差异,如要制造一个超人,如果使用工厂方 ...

  4. parser_url

    $url="http://127.0.0.1/test2.php?sitename=mysite.cn&a=1&b=2";$a=parse_url($url);p( ...

  5. Ascii vs. Binary Files

    Ascii vs. Binary Files Introduction Most people classify files in two categories: binary files and A ...

  6. C#中.XSD是什么文件?

    xml的Schema文件 如果把xml看做数据库的数据,那么Schema文件就相当于数据库,表的结构(比如有哪些字段,约束等等)

  7. 切换python版本

    安装python3.6.5后, alias python='/usr/bin/python3.6'

  8. Redis学习第八课:Redis高级实用特性(二)

    Redis高级实用特性 4.持久化机制 Redis是一个支持持久化的内存数据库,也就是说Redis需要经常将内存中的数据同步到硬盘来保证持久化.Redis支持两种持久化方式:(1).snapshott ...

  9. 转:Canvas标签的width和height以及style.width和style.height的区别

    转自:http://www.cnblogs.com/artwl/archive/2012/02/28/2372042.html 作者:Artwl 背景 今天在博问中看到一个问题:用canvas 的 l ...

  10. Linux博客系统服务器搭建

    linux(CentOS)服务器搭建 前言 拿到购买的服务器信息后,会给出一个服务器的账号的密码,看你自己设置,账号一般为root. 拿到后,可在阿里云官网登录进入服务器.然后就可以进行一下的流程从而 ...