以其他身份运行且自动登录的代码,哪位酷派大神f2更新出错帮忙看哪里出错了

3157人阅读
using System.D
using System.C
using System.W
using System.Web.S
using System.Web.UI;
using System.Web.UI.WebC
using System.Web.UI.WebControls.WebP
using System.Web.UI.HtmlC
using System.Runtime.InteropS
namespace Utility
/// &summary&
/// 使用此类来模拟某个系统用户(系统帐号、AD等)
/// 主要用在需要特别权限的地方,因为IIS的系统帐号权限通常比较低,需要更高级权限时使用此类来替换用户,执行完毕后再换回原来的帐号
/// &/summary&
public class Impersonal
[DllImport("advapi32.dll", SetLastError = true)]
public extern static bool LogonUser(String lpszUsername, String lpszDomain,
String lpszPassword, int dwLogonType,
int dwLogonProvider, ref IntPtr phToken);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public extern static bool CloseHandle(IntPtr handle);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public extern static bool DuplicateToken(IntPtr ExistingTokenHandle,
int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle);
const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_INTERACTIVE = 2;
const int SecurityImpersonation = 2;
private IntPtr tokenH
private IntPtr dupeTokenH
private System.Security.Principal.WindowsImpersonationContext impersonatedU
private string UserN
private string PWD;
public Impersonal(string username, string password)
tokenHandle = new IntPtr(0);
dupeTokenHandle = new IntPtr(0);
UserName =
/// &summary&
/// 开始模拟
/// &/summary&
public void StartImpersonate()
string domainName = string.E
string userName = string.E
if (!System.Text.RegularExpressions.Regex.IsMatch(UserName, @"^/w+[//]?/w+$"))
throw new ApplicationException("非法的用户名");
string[] tmp = UserName.Split(new char[] { '//' });
if (tmp.Length & 1)
domainName = tmp[0];
userName = tmp[1];
userName = tmp[0];
tokenHandle = IntPtr.Z
dupeTokenHandle = IntPtr.Z
bool returnValue = LogonUser(userName, domainName, PWD,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);
if (!returnValue)
throw new ApplicationException("取Handle出错了!");
//Console.WriteLine("当前用户是: "
+ WindowsIdentity.GetCurrent().Name);
bool retVal = DuplicateToken(tokenHandle, SecurityImpersonation, ref dupeTokenHandle);
if (!retVal)
CloseHandle(tokenHandle);
throw new ApplicationException("复制Handle出错了!");
System.Security.Principal.WindowsIdentity newId = new System.Security.Principal.WindowsIdentity(dupeTokenHandle);
impersonatedUser = newId.Impersonate();
/// &summary&
/// 取消模拟
/// &/summary&
public void StopImpersonate()
if (impersonatedUser != null)
impersonatedUser.Undo();
if (tokenHandle != IntPtr.Zero)
CloseHandle(tokenHandle);
if (dupeTokenHandle != IntPtr.Zero)
CloseHandle(dupeTokenHandle);
前提你要有系统管理员的密码,如果客户端加入了域,就用域的管理员帐号登录。。使用方法Impersonal impl=new Impersonal(系统管理员帐号,密码);//例如..Impersonal("Administrator","12345")或者Impersonal("域名/Administrator","12345")impl.StartImpersonate();运行你的代码impl.StopImpersonate();&
我给你的类就是实现你想要的功能。用它来模拟管理员的身份,然后执行你想要的操作。首先,你需要明白一点,你想要的&自动更改为以管理员身份运行&要有一个前提条件,就是你必须拥有管理员帐号的密码,在本机就是&Administrator&,在AD中就是 &域/Administrator&你或者事先已经知道客户电脑的密码,或者弹出一个输入框让用户输入密码。然后:Impersonal impl=new Impersonal(&Administrator&,用户输入的密码);impl.StartImpersonate(); 执行自动升级impl.StopImpersonate();
比较简单的方式:创建软件的快捷方式.右击快捷方式并选择&属性&。点击&Advanced&按钮,并勾选&Run as administrator&。点&OK&保存更改。然后:启动快捷方式就可。System.Diagnostics.Process.Start(@"C:/Users/Jason/Desktop/xxx.lnk");&
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2191006次
积分:24452
积分:24452
排名:第118名
原创:57篇
转载:1369篇
评论:322条
(1)(10)(1)(4)(3)(14)(27)(17)(5)(34)(24)(17)(25)(43)(8)(24)(1)(10)(1)(2)(2)(12)(1)(5)(12)(13)(9)(1)(5)(107)(21)(35)(2)(4)(11)(21)(3)(8)(2)(4)(3)(12)(6)(4)(9)(20)(10)(39)(24)(2)(59)(32)(34)(13)(44)(150)(56)(50)(41)(24)(95)(34)(3)(8)(43)(35)(27)
<a href="/article查看: 4342|回复: 1
淘宝网自动登录代码给大家分享下,谁能解决淘宝登陆cookies问题
火车车厢 节
本帖最后由 0575sos 于
15:07 编辑
最近在玩淘宝,弄了些小玩意,琢磨出了几种自动登录的方法,下面是两种我运行过两周没问题的版本。
login = function(){
& & wb.go(&/member/login.jhtml&)
& & wb.wait(&&);
& & wb.waitEle(&TPL_username_1&).value = &username&
& & var cwnd = winex.findEx(winform.hwnd,2,&ATL\:Edit&)
& & winex.say2(&pwd&,cwnd)
& & wb.queryEles( innerHTML=&登录&;tagName=&BUTTON&;className=&J_Submit& ).click()
& & wb.waitEle(&J_Logout&)
优点:执行稳定
缺点:系统高负荷时winex.say2()可能会出错。消息队列无法及时处理
login2 = function(){
& & wb.post(&/member/login.jhtml&, &TPL_username=& ++ username ++ &&TPL_password=& ++ password ++ &&longLogin=0&action=Authenticator&event_submit_do_login=anything&TPL_redirect_url=&+formEncode(&/&) + &&from=tbTop&fc=2&style=default&css_style=&tid=&support=000001&CtrlVersion=&+formEncode(&1,0,0,7&) + &&loginType=4&minititle=&minipara=&umto=&+formEncode(&Tea187d1310acbb1b63ca18e6f2e6eab4,&) + &&pstrong=&llnick=&sign=&need_sign=&isIgnore=&full_redirect=&popid=&callback=&guf=&_duplite_str=&need_user_id=&poy=&gvfdcname=10&gvfdcre=F2FAFF6D2F&from_encoding=&)
& & wb.waitEle(&J_Logout&)
}& &//用户名和密码用明文来写也可以post通过,无需加密
优点:登录最快
缺点:怕淘宝修改js
post版去掉了一些字段,经实验不影响登录。
token可以不用写,登录时候没验证?
还有tbcpCrumbs,不写入post字段也能通过。
悲剧的是,post方法刚弄出来没两天,淘宝就限制我的帐号了,现在登录要输入图片验证码。
昨天找到了新的方法绕过验证码,代码还在调试中。
有些比较怪的节点,网页内容会发生变化,用webspy生成的代码取不到。
火车车厢 节
本帖最后由 zyzy135 于
16:45 编辑
楼主也是 aauto
咋发到这里了??
温馨提示:建议您联系官方定制服务,通过官方支付方式完成支付。您与其他非官方账号发生的交易,我方概不承担责任。网络有风险,交易需谨慎
Copyright &
&Template by
All Rights Reserved.
Powered by

我要回帖

更多关于 大神f1更新出错 的文章

 

随机推荐