win7 以管理员身份调用regsvr32命令 win7下调用regsvr32注册组件失败,但是以管理员身份使用regsvr32命令注册就成功 那C#如何以管理员身份电泳regsvr32命令呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 右键工程-->属性-->安全性-->启用ClickOnce安全设置这时Properties目录下会有一个app.manifest文件,双击编辑<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="IsUserAdmin" type="win32"/><description>Description of your application</description><!-- Identify the application security requirements. --><trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges>//加下这个节点 <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> </requestedPrivileges> </security></trustInfo></assembly>听说这样可以让程序自动以管理员方式运行,但我没试过。你可以试一下 给你一个注册com组件的类吧using System;using System.Runtime.InteropServices;public static class ComUtils{ public static bool RegisterComComponent(string path) { // Register COM component, false if not a COM component IntPtr module = LoadLibraryEx(path, IntPtr.Zero, 0); if (module == IntPtr.Zero) throw new ArgumentException("Could not load DLL, error code=" + Marshal.GetLastWin32Error().ToString()); try { IntPtr addr = GetProcAddress(module, "DllRegisterServer"); if (addr == IntPtr.Zero) return false; DllRegisterServer dlg = (DllRegisterServer)Marshal.GetDelegateForFunctionPointer(addr, typeof(DllRegisterServer)); int hr = dlg.Invoke(); if (hr != 0) Marshal.ThrowExceptionForHR(hr); return true; } finally { FreeLibrary(module); } } // P/Invoke declarations private delegate int DllRegisterServer(); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern IntPtr LoadLibraryEx(string path, IntPtr dummy, int flags); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern bool FreeLibrary(IntPtr hdl); [DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true)] private static extern IntPtr GetProcAddress(IntPtr hdl, string name);}看看这个好不好使。 这个方法好像只能是VS2008以上的吧VS2005也可以吗? 可以的,vs 2005和2008都可以的http://clacklin.blog.163.com/blog/static/103209820106108538269/ 为什么我用VSO8可以,VS05就不行啊,app.manifest文件如下:<?xml version="1.0" encoding="utf-8"?><asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges> <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> </requestedPrivileges> <applicationRequestMinimum> <defaultAssemblyRequest permissionSetReference="Custom" /> <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" /> </applicationRequestMinimum> </security> </trustInfo></asmv1:assembly> 树形结构的问题 【求救】C#视频是通过什么传输的 视频流?还是? 一个DataGridView 绑定两个数据源 新手求助!这是验证码的前部分代码,能够帮我把每一句注释下吗??谢谢! C#通过飞信WebService发送免费短信 c#中如何把一个项目中的文件放在另一个项目中使用 xml DataGrid优化问题 c#初学者的一个问题,刚开始学了,兄弟们多多帮忙! .net framework类库引用出了问题,提示List<int>在.net standard中被定义 无法动态加载标 依然关于WPF问题
这时Properties目录下会有一个app.manifest文件,双击编辑
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86"
name="IsUserAdmin"
type="win32"/>
<description>Description of your application</description>
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>//加下这个节点
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
听说这样可以让程序自动以管理员方式运行,但我没试过。你可以试一下
using System.Runtime.InteropServices;public static class ComUtils
{
public static bool RegisterComComponent(string path)
{
// Register COM component, false if not a COM component
IntPtr module = LoadLibraryEx(path, IntPtr.Zero, 0);
if (module == IntPtr.Zero) throw new ArgumentException("Could not load DLL, error code=" + Marshal.GetLastWin32Error().ToString());
try
{
IntPtr addr = GetProcAddress(module, "DllRegisterServer");
if (addr == IntPtr.Zero) return false;
DllRegisterServer dlg = (DllRegisterServer)Marshal.GetDelegateForFunctionPointer(addr, typeof(DllRegisterServer));
int hr = dlg.Invoke();
if (hr != 0) Marshal.ThrowExceptionForHR(hr);
return true;
}
finally
{
FreeLibrary(module);
}
}
// P/Invoke declarations
private delegate int DllRegisterServer();
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr LoadLibraryEx(string path, IntPtr dummy, int flags);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool FreeLibrary(IntPtr hdl);
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
private static extern IntPtr GetProcAddress(IntPtr hdl, string name);
}
看看这个好不好使。
http://clacklin.blog.163.com/blog/static/103209820106108538269/
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges> <applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
</applicationRequestMinimum>
</security>
</trustInfo>
</asmv1:assembly>