写个内网的自动签到程序,但是运行时,在我原来的机子上正常,其他三个机子都不正常了( 恰好我现在换了个不正常运行的机子),不管装没有装VB6,很是郁闷,把代码发下,大家指点下
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim j As Integer
Dim ex As Object
Dim wb As Object
Dim sh As Object
Dim objDoc
Dim endi As Integer
Dim k As Integer
Private i As Integer
Private si As String
Private Sub Form_Load()
WebBrowser1.Width = Screen.Width
WebBrowser1.Height = Screen.Height - 500
i = 1
Set ex = CreateObject("Excel.Application")Set wb = ex.Workbooks.Open(App.Path & "\1.xls")
Set sh = wb.Sheets(1)
endi = sh.UsedRange.Rows.Count
WebBrowser1.Navigate "http://148.36.20.220:86/"
End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If WebBrowser1.LocationURL = "http://148.36.20.220:86/" Then
If i > endi Then
wb.Close True
ex.Quit
Set sh = Nothing
Set wb = Nothing
Set ex = Nothing
Unload Me
End
Else:
WebBrowser1.Document.Forms(0).TextBox1.Value = sh.Cells(i, 1) '填用户名
WebBrowser1.Document.Forms(0).TextBox2.Value = sh.Cells(i, 2) '密码
j = (Int(Rnd * 10) + 3) * 1000
Sleep j
WebBrowser1.Document.Forms(0).Button1.Click '点确认
i = i + 1
End If
End If
If WebBrowser1.LocationURL = "http://148.36.20.220:86/qd.aspx" Then
Dim s As Variant
s = pDisp.Document.documentElement.outerHTML
If InStr(s, "ImageButton1") > 0 Then '按钮1存在就点
j = (Int(Rnd * 10) + 5) * 1000
Sleep j
On Error Resume Next
Set objDoc = WebBrowser1.Document
For k = 0 To objDoc.All.Length - 1
If objDoc.All(k).Name = "ImageButton1" Then
objDoc.All(k).Click
End If
Next
WebBrowser1.Navigate "http://148.36.20.220:86/"
' WebBrowser1.Document.Forms(0).ImageButton1.Click
' 在这里说下,上一句写在按钮命令里是可能运行的,但是在这儿就是运行不了
ElseIf InStr(s, "ImageButton2") > 0 Then '按钮2是否存在
j = (Int(Rnd * 10) + 5) * 1000
Sleep j
On Error Resume Next
Set objDoc = WebBrowser1.Document
For k = 0 To objDoc.All.Length - 1
If objDoc.All(k).Name = "ImageButton2" Then
objDoc.All(k).Click
End If
Next
WebBrowser1.Navigate "http://148.36.20.220:86/"
'WebBrowser1.Document.Forms(0).ImageButton2.Click
Else: '没有按钮1或2就直接返回
j = (Int(Rnd * 10) + 3) * 1000
Sleep j
WebBrowser1.Navigate "http://148.36.20.220:86/"
End If
End IfEnd Sub它总是第一个运行正常,后面的只填用户名和密码后,网页二打不开就直接回网页一,继续填下一户的用户名和密码了,后面有时能有一二个用户名正常运行,但多数还是不正常点击按钮!还有就是IE或别的浏览器打开网页一或二时很快,用WEBBROWSER怎么总是很慢,特别是第一次,我看了下网页的源码,没有什么不正常的啊.
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim j As Integer
Dim ex As Object
Dim wb As Object
Dim sh As Object
Dim objDoc
Dim endi As Integer
Dim k As Integer
Private i As Integer
Private si As String
Private Sub Form_Load()
WebBrowser1.Width = Screen.Width
WebBrowser1.Height = Screen.Height - 500
i = 1
Set ex = CreateObject("Excel.Application")Set wb = ex.Workbooks.Open(App.Path & "\1.xls")
Set sh = wb.Sheets(1)
endi = sh.UsedRange.Rows.Count
WebBrowser1.Navigate "http://148.36.20.220:86/"
End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If WebBrowser1.LocationURL = "http://148.36.20.220:86/" Then
If i > endi Then
wb.Close True
ex.Quit
Set sh = Nothing
Set wb = Nothing
Set ex = Nothing
Unload Me
End
Else:
WebBrowser1.Document.Forms(0).TextBox1.Value = sh.Cells(i, 1) '填用户名
WebBrowser1.Document.Forms(0).TextBox2.Value = sh.Cells(i, 2) '密码
j = (Int(Rnd * 10) + 3) * 1000
Sleep j
WebBrowser1.Document.Forms(0).Button1.Click '点确认
i = i + 1
End If
End If
If WebBrowser1.LocationURL = "http://148.36.20.220:86/qd.aspx" Then
Dim s As Variant
s = pDisp.Document.documentElement.outerHTML
If InStr(s, "ImageButton1") > 0 Then '按钮1存在就点
j = (Int(Rnd * 10) + 5) * 1000
Sleep j
On Error Resume Next
Set objDoc = WebBrowser1.Document
For k = 0 To objDoc.All.Length - 1
If objDoc.All(k).Name = "ImageButton1" Then
objDoc.All(k).Click
End If
Next
WebBrowser1.Navigate "http://148.36.20.220:86/"
' WebBrowser1.Document.Forms(0).ImageButton1.Click
' 在这里说下,上一句写在按钮命令里是可能运行的,但是在这儿就是运行不了
ElseIf InStr(s, "ImageButton2") > 0 Then '按钮2是否存在
j = (Int(Rnd * 10) + 5) * 1000
Sleep j
On Error Resume Next
Set objDoc = WebBrowser1.Document
For k = 0 To objDoc.All.Length - 1
If objDoc.All(k).Name = "ImageButton2" Then
objDoc.All(k).Click
End If
Next
WebBrowser1.Navigate "http://148.36.20.220:86/"
'WebBrowser1.Document.Forms(0).ImageButton2.Click
Else: '没有按钮1或2就直接返回
j = (Int(Rnd * 10) + 3) * 1000
Sleep j
WebBrowser1.Navigate "http://148.36.20.220:86/"
End If
End IfEnd Sub它总是第一个运行正常,后面的只填用户名和密码后,网页二打不开就直接回网页一,继续填下一户的用户名和密码了,后面有时能有一二个用户名正常运行,但多数还是不正常点击按钮!还有就是IE或别的浏览器打开网页一或二时很快,用WEBBROWSER怎么总是很慢,特别是第一次,我看了下网页的源码,没有什么不正常的啊.
<head><title>
绩效考核系统
</title>
<style type="text/css">
.style1
{
font-family:Tahoma,Verdana,"宋体"; font-size: 12px;
}
.button1 { border: #999999; border-style: double; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; font-family:Tahoma,Verdana,"宋体"; font-size: 12px; line-height: 15px;COLOR: #000000;}
</style>
</head>
<body>
<form name="form1" method="post" action="login.aspx" id="form1">
<div>
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTU2MzQ1NzIyMGRkrPaC46Wfk8/FoaAyxiiIQBIj5tU=" />
</div><script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>
<script src="/WebResource.axd?d=bLlVDp3ZWxEa917bDqzKpg2&t=633759254897031250" type="text/javascript"></script>
<script src="/WebResource.axd?d=Sqdk0DMjrjozlEha79VLiQ2&t=633759254897031250" type="text/javascript"></script>
<div>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" style="z-index: 100; left: 0px; position: absolute; top: 0px">
<tr>
<td height="700" align="center" valign="middle" bgcolor="#0a68af" >
<input type="submit" name="Button1" value="请登录" id="Button1" tabindex="2" style="left: 7px;
position: relative; top: 193px" />
<table width="650" height="410" border="0" align="center" cellpadding="0" cellspacing="0" background="Images/login2.jpg" >
<tbody>
<tr>
<td align="center" style="width: 650px; height: 310px;">
<input name="TextBox2" type="password" id="TextBox2" tabindex="12" class="button1" style="width:130px;left: 337px;
position: relative; top: -65px; z-index: 100;" />
<input name="TextBox1" type="text" id="TextBox1" tabindex="11" class="button1" style="width:142px;position: relative; left: -19px; top: -64px; z-index: 100;" />
<span id="Label1" class="style1" style="display:inline-block;color:Red;width:191px;position: relative; left: -326px; top: -25px; z-index: 100;"></span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</div>
<div> <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAK4uZf2BwKM54rGBgLs0fbZDALs0bLrBoZyY2mBsZAcAyCoHpIrpaOT2D/l" />
</div><script type="text/javascript">
<!--
WebForm_AutoFocus('TextBox1');// -->
</script>
</form>
</body>
</html>再发下登录完后的网页源码,是没有按钮状态的
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
绩效考核主页
</title>
<style type="text/css">
<!--
body {
font-size:13px;
font-family:Arial;
text-align: center;
background-image: url(Images/bg3.gif);
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
#container1{
width:962px;
height: 200px;
text-align: center;
margin-top:0px;
background-color: #FFFFFF;
}
-->
</style>
<link href="Css/Style.css" rel="stylesheet" type="text/css" /></head>
<body> <form name="form1" method="post" action="qd.aspx" id="form1">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJMzA1OTY1ODk4D2QWAgIDD2QWDAIFDw8WAh4EVGV4dAUI6ZmIICDnkLNkZAIHDw8WAh8ABRUyMDEw5bm0NeaciDXml6UgMTA6MDJkZAIJDw8WBh8ABQ/mgqjlt7Lnrb7ov4fvvIEeCUZvcmVDb2xvcgqNAR4EXyFTQgIEZGQCCw8PFgIeB1Zpc2libGVoZGQCDQ8PFgYfAAUb6K+35Zyo5LiK54+t5pe26Ze0562+5Yiw77yBHwEKJR8CAgRkZAIPDw8WAh8DaGRkZCOs3OCHRuIaz+UEPoeHB10BA7c/" />
</div><script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
height::140px;
}
.txttop
{
font-size:13px;
text-align:center;
font-weight: bold;
}
a {
color: #FFFFFF;
text-decoration: none;
font-size: 16px;
}
a:hover {
color: #FF0000;
text-decoration: underline;
font-size: 16px;
}-->
</style><TABLE width=962 border=0 align="center" cellPadding=0 cellSpacing=0>
<TR>
<TD height=140 valign="top" background="Images/toplog.jpg"> </TD>
</TR>
<TR>
<TD height=30 align="center" valign="middle" bgcolor="#3366FF"><table width="100%" border="0" bgcolor="#3366FF" class="txttop">
<tr>
<td width="13%"><a href="http://148.36.20.220">首页</a></td>
<td width="13%"><a href="login.aspx">签到</a></td>
<td width="13%"><a href="cx.aspx">查询</a></td>
<td width="13%"><a href="tj.aspx">统计</a></td>
<td width="13%">
<a id="Top1_LinkButton1" href="javascript:__doPostBack('Top1$LinkButton1','')" style="left: 0px; top: 0px">维护</a><a href="wh.aspx"></a></td>
<td width="13%"><a href="mmxg.aspx">修改密码</a></td>
<td width="13%" style="color: #ff0000">
技术管理科制作</td>
</tr>
</table></TD>
</TR>
</TABLE>
<div id="container1">
<table width="800" style="border:1px solid #A9C9E2;background-color: #E8F5FE; height: 400px;">
<tr>
<td style="height: 21px; width: 71px;"><span id="labMsg"></span> </td>
<td style="height: 21px; width: 696px;"><p align="left" style="font-size: 18px">您好,
<span id="username">张三</span>
:<br />
现在是
<span id="date">2010年5月5日 10:02</span>
,欢迎进入网上签到系统!<br />
代签是严重违反劳动纪律的行为,违者必究!</td>
</tr>
<tr>
<td colspan="2" style="height: 200px" >
<table align="center" border="1px" bordercolor="#000000" cellpadding="0" cellspacing="0" width="603">
<tr>
<th style="width: 513px; height: 49px">
功能名称</th>
<th style="width: 714px; height: 49px">
签到状态</th>
<th style="width: 368px; height: 49px">
签到</th>
</tr>
<tr>
<th rowspan="2" style="font-weight: bolder; width: 513px; color: red; height: 65px">
1、上午签到</th>
<td rowspan="2" style="width: 714px; height: 65px"><span id="swqd" style="color:Red;">您已签过!</span></td>
<td rowspan="2" style="width: 368px; height: 65px">
</td>
</tr>
<tr> </tr>
<tr>
<th rowspan="2" style="font-weight: bolder; width: 513px; color: red; height: 65px">
2、下午签到</th>
<td rowspan="2" style="width: 714px; height: 65px;"><span id="xwqd" style="color:Blue;">请在上班时间签到!</span></td>
<td rowspan="2" style="width: 368px; height: 65px;">
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLKzfKkCALo/ZvOAVusv3wuafmICHHVekO0SS5ugocD" />
</div></form>
</body>
</html>