一个自动登录网页的软件开发过程
2016-01-24 00:00
711 查看
首先这个小软件需要实现如下的功能,用已知的用户名和密码登录某系统,单击系统的tab页地址,查询出数据列表,然后随便抽一行点击某列的链接地址,这个过程中无人工干预,用软件的方式自动完成(注:系统登录无验证码,但页面提交数据有一定的规则,小软件运行在windows系统,要求浏览器留有cookie,下次打开网页时可以直接登录)。
简单的需求分析,首先某同事告知了初步想法,用户名和密码的录入和保存,使用按键精灵类似的软件填入录入用户名和密码,实现登录,打开tab页和地址链接。
需求与实现的转化:用户名和密码的录入保存需要一个用户页面输入,最优选择自然.net平台,使用c#语言开发;登录和点击下载了按键精灵准备实现。
前端部分实现:下载了visual studio express开发工具,页面很快做好,但感觉差点什么,跟web系统对比,差了placeholder这样的功能,于是动手添加,textbox只需修改页面配置文件即可,passwordbox稍微复杂,经过一番折腾总算较为满意的实现;接着文本框的字体光标靠上,看着不舒服,再次解决了字体和光标垂直居中水平居左显示。录入用户名和密码后,数据的存储,考虑到小软件,不需使用数据库,用文件的方式即可,windows自然常用的是ini文件,可读性也好,所以几行代码即可完成,开发页面的时间大概半天,期间调坐标对齐,按钮事件相应,字段空判断,写入文件,再次启动是读取文件一起完成。
后端登录的实现:大概流程了按键精灵的教程,录入了一段脚本,试着操作了下挺简单。实现登录最早使用按键精灵自身的html方式登录,打包后,内嵌的IE8启动运行,可以基本实现要求,但此web系统是使用html5开发,IE8支持的不完美,部分页面排版有错误。一番搜索后发现有类似vbs的方式的按键精灵脚本实现登录,半天后实现此功能。
前后端集合,前端已经保存成inf文件,后端自然是读取inf然后实现登录,这里速度较快,大概1个钟完成。
到现在为止功能基本完成了,但有不满意的地方,按键xx打包后运行会弹出一x浪的游戏网,本地也有弹窗,并不友好,去广告需要注册会员付费才可以去广告,另外就是打包的exe大概8m,给人小牛拉大车啊。秉着追求完成,便有了继续的开发。
后端的优化:vbs替换按键xx混合脚本。首先是读取inf文件的替换,消耗时间大概2个钟。接着是脚本的内容的替换和语法的变化,稍学习了vbs的语法和结构后,顺利的完成,期间msdn搜索时看到一段实例代码,有vb和c#分别参考代码。有了c#的参考代码,好奇心出来能不能用c#的方式直接实现,不用在vbs相互调用。搬过去实例代码后,接着是dom操作的替换,半天后顺利完成功能。
最后的运行阶段:最早调用vbs是使用写进程的方式调用,两个各自运行不会中断,使用c#后,由于在当前现场调用Internateexploer对象,网页登录过程中,窗体页面会卡住不动无法操作,便使用的线程的方式启动。功能的实现还差开机启动,这里使用写注册表启动,但几次都是失败,因为win7后,注册表的读写控制较为严格,local_machine需要管理员权限才可以写入,最后使用current_user可以顺利写入。
交付客户前,替换了默认的exeLogo,默认的窗口logo,在窗口部分添加了带登录网页的logo,适当调大的窗体字体和文本框长宽,前天花费3.5天时间。
总结用到的技能和知识点: c#语言开发/vbs开发/按键xx使用,脚本开发;文件的的相对目录、读取;多线程开发;写入注册表;DOM的操作和容错性处理;用于界面的优化。
源代码如下:
PasswordBoxMonitor.cs(密码输入框优化)
Service.cs(注册服务)
访问网络并并登录ViewerInternate.cs
主界面MainWindow.xaml.cs
主页面布局
VBS实现自动登录
简单的需求分析,首先某同事告知了初步想法,用户名和密码的录入和保存,使用按键精灵类似的软件填入录入用户名和密码,实现登录,打开tab页和地址链接。
需求与实现的转化:用户名和密码的录入保存需要一个用户页面输入,最优选择自然.net平台,使用c#语言开发;登录和点击下载了按键精灵准备实现。
前端部分实现:下载了visual studio express开发工具,页面很快做好,但感觉差点什么,跟web系统对比,差了placeholder这样的功能,于是动手添加,textbox只需修改页面配置文件即可,passwordbox稍微复杂,经过一番折腾总算较为满意的实现;接着文本框的字体光标靠上,看着不舒服,再次解决了字体和光标垂直居中水平居左显示。录入用户名和密码后,数据的存储,考虑到小软件,不需使用数据库,用文件的方式即可,windows自然常用的是ini文件,可读性也好,所以几行代码即可完成,开发页面的时间大概半天,期间调坐标对齐,按钮事件相应,字段空判断,写入文件,再次启动是读取文件一起完成。
后端登录的实现:大概流程了按键精灵的教程,录入了一段脚本,试着操作了下挺简单。实现登录最早使用按键精灵自身的html方式登录,打包后,内嵌的IE8启动运行,可以基本实现要求,但此web系统是使用html5开发,IE8支持的不完美,部分页面排版有错误。一番搜索后发现有类似vbs的方式的按键精灵脚本实现登录,半天后实现此功能。
前后端集合,前端已经保存成inf文件,后端自然是读取inf然后实现登录,这里速度较快,大概1个钟完成。
到现在为止功能基本完成了,但有不满意的地方,按键xx打包后运行会弹出一x浪的游戏网,本地也有弹窗,并不友好,去广告需要注册会员付费才可以去广告,另外就是打包的exe大概8m,给人小牛拉大车啊。秉着追求完成,便有了继续的开发。
后端的优化:vbs替换按键xx混合脚本。首先是读取inf文件的替换,消耗时间大概2个钟。接着是脚本的内容的替换和语法的变化,稍学习了vbs的语法和结构后,顺利的完成,期间msdn搜索时看到一段实例代码,有vb和c#分别参考代码。有了c#的参考代码,好奇心出来能不能用c#的方式直接实现,不用在vbs相互调用。搬过去实例代码后,接着是dom操作的替换,半天后顺利完成功能。
最后的运行阶段:最早调用vbs是使用写进程的方式调用,两个各自运行不会中断,使用c#后,由于在当前现场调用Internateexploer对象,网页登录过程中,窗体页面会卡住不动无法操作,便使用的线程的方式启动。功能的实现还差开机启动,这里使用写注册表启动,但几次都是失败,因为win7后,注册表的读写控制较为严格,local_machine需要管理员权限才可以写入,最后使用current_user可以顺利写入。
交付客户前,替换了默认的exeLogo,默认的窗口logo,在窗口部分添加了带登录网页的logo,适当调大的窗体字体和文本框长宽,前天花费3.5天时间。
总结用到的技能和知识点: c#语言开发/vbs开发/按键xx使用,脚本开发;文件的的相对目录、读取;多线程开发;写入注册表;DOM的操作和容错性处理;用于界面的优化。
源代码如下:
PasswordBoxMonitor.cs(密码输入框优化)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; namespace smartlogin { public class PasswordBoxMonitor : DependencyObject { public static bool GetIsMonitoring(DependencyObject obj) { return (bool)obj.GetValue(IsMonitoringProperty); } public static void SetIsMonitoring(DependencyObject obj, bool value) { obj.SetValue(IsMonitoringProperty, value); } public static readonly DependencyProperty IsMonitoringProperty = DependencyProperty.RegisterAttached("IsMonitoring", typeof(bool), typeof(PasswordBoxMonitor), new UIPropertyMetadata(false, OnIsMonitoringChanged)); public static int GetPasswordLength(DependencyObject obj) { return (int)obj.GetValue(PasswordLengthProperty); } public static void SetPasswordLength(DependencyObject obj, int value) { obj.SetValue(PasswordLengthProperty, value); } public static readonly DependencyProperty PasswordLengthProperty = DependencyProperty.RegisterAttached("PasswordLength", typeof(int), typeof(PasswordBoxMonitor), new UIPropertyMetadata(0)); private static void OnIsMonitoringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var pb = d as PasswordBox; if (pb == null) { return; } if ((bool)e.NewValue) { pb.PasswordChanged += PasswordChanged; } else { pb.PasswordChanged -= PasswordChanged; } } static void PasswordChanged(object sender, RoutedEventArgs e) { var pb = sender as PasswordBox; if (pb == null) { return; } SetPasswordLength(pb, pb.Password.Length); } } }
Service.cs(注册服务)
using System; using System.Collections; using System.Collections.Generic; using System.Configuration.Install; using System.Linq; using System.ServiceProcess; using System.Text; using System.Threading.Tasks; using System.Windows; namespace smartlogin { class Service { private String ServiceName; public Service(String ServiceName) { this.ServiceName = ServiceName; } public void Install(string filepath) { try { System.ServiceProcess.ServiceController service = new System.ServiceProcess.ServiceController(ServiceName); if (!ServiceIsExisted(ServiceName)) { //Install Service IDictionary stateSaver = new Hashtable(); AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller(); myAssemblyInstaller.UseNewContext = true; myAssemblyInstaller.Path = filepath; myAssemblyInstaller.Install(stateSaver); myAssemblyInstaller.Commit(stateSaver); myAssemblyInstaller.Dispose(); service.Start(); } else { if (service.Status != System.ServiceProcess.ServiceControllerStatus.Running && service.Status != System.ServiceProcess.ServiceControllerStatus.StartPending) { service.Start(); } } } catch (Exception ex) { MessageBox.Show("installServiceError/n" + ex.Message); } } private void UnInstall(string filepath) { try { if (ServiceIsExisted(ServiceName)) { //UnInstall Service AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller(); myAssemblyInstaller.UseNewContext = true; myAssemblyInstaller.Path = filepath; myAssemblyInstaller.Uninstall(null); myAssemblyInstaller.Dispose(); } } catch (Exception ex) { throw new Exception("unInstallServiceError/n" + ex.Message); } } private bool ServiceIsExisted(string serviceName) { ServiceController[] services = ServiceController.GetServices(); foreach (ServiceController s in services) { if (s.ServiceName == serviceName) { return true; } } return false; } } }
访问网络并并登录ViewerInternate.cs
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; namespace smartlogin { class ViewerInternate { private string username; private string website; private string password; private Thread thread; public ViewerInternate(string username, string website, string password) { this.username = username; this.website = website; this.password = password; thread = new Thread(new ThreadStart(Run)); } public void Start() { if (thread != null) { thread.Start(); } } private void Run() { try { SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer(); SetForegroundWindow(IE.HWND); object Empty = 0; object URL = website; IE.Visible = true; IE.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, ref Empty); while (IE.Busy || IE.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { System.Threading.Thread.Sleep(1000); } if (IE.Document.getElementsByName("ctl03$tbUser").length > 0) { IE.Document.getElementsByName("ctl03$tbUser")(0).value = username; System.Threading.Thread.Sleep(100); } if (IE.Document.getElementsByName("ctl03$tbPassword").length > 0) { IE.Document.getElementsByName("ctl03$tbPassword")(0).value = password; System.Threading.Thread.Sleep(100); } if (IE.Document.getElementsByName("ctl01$btnSubmitLogin").length > 0) { IE.Document.getElementsByName("ctl01$btnSubmitLogin")(0).click(); System.Threading.Thread.Sleep(100); } while (IE.Busy || IE.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { System.Threading.Thread.Sleep(1000); } object oFlags = 0; IE.Navigate2("https://xxxx.xx.com", oFlags, "_self", ref Empty, ref Empty); while (IE.Busy || IE.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { System.Threading.Thread.Sleep(2000); } if (IE.Document == null) { return; } mshtml.HTMLTable table = IE.Document.getElementById("tpl_ih_adminList_MainGrid"); if (table != null) { mshtml.IHTMLElementCollection tr = table.getElementsByTagName("tr"); if (tr != null && tr.length > 1) { dynamic a = tr.item(1).getElementsByTagName("a"); if ((object)a != null && a.length > 4) IE.Navigate2(a(5).href, ref Empty, ref Empty, ref Empty, ref Empty); } } else { MessageBox.Show("获取地址出错", "提示"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } [DllImport("User32.dll", CharSet = CharSet.Auto)] public static extern int SetForegroundWindow(int hwnd); } }
主界面MainWindow.xaml.cs
using System; using System.Windows; using System.ServiceProcess; using System.Configuration.Install; using System.Collections; using System.Runtime.InteropServices; using System.Text; using System.Diagnostics; using System.IO; using Microsoft.Win32; using System.Security.Permissions; using System.Windows.Controls; namespace smartlogin { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { private string ServiceName = "esker"; private string IniFileNamePath = ".\\libs\\default.ini"; public MainWindow() { InitializeComponent(); Initialize(); } private void Initialize() { if (File.Exists(IniFileNamePath)) { string username=ReadIniData(ServiceName, "username",IniFileNamePath); string website = ReadIniData(ServiceName, "website", IniFileNamePath); string password = ReadIniData(ServiceName, "password", IniFileNamePath); bool checkedState= checkBox.IsChecked.Value; passwordBox.Password = password; idTextBox.Text = username; webTextBox.Text= website; String checkedStr = ReadIniData(ServiceName, "checked", IniFileNamePath); if(checkedStr.Length!=0) { checkedState = Boolean.Parse(checkedStr); checkBox.IsChecked = checkedState; } Handle(checkedState); // new ViewerInternate(username, website, password).Start(); } } private void saveBtn_Click(object sender, RoutedEventArgs e) { string password = passwordBox.Password.Trim(); string username = idTextBox.Text.Trim(); string website = webTextBox.Text.Trim(); Boolean checkedState=checkBox.IsChecked.Value; if (website.Length == 0) { MessageBox.Show("请输入'网址'", "提示"); return; } if (!checkedState) { if (password.Length == 0 || username.Length == 0 ) { MessageBox.Show("请输入'标识符/密码'", "提示"); return; } } if (!Directory.Exists(".\\libs")) { Directory.CreateDirectory(".\\libs"); } WritePrivateProfileString(ServiceName, "username", username, IniFileNamePath); WritePrivateProfileString(ServiceName, "password", password, IniFileNamePath); WritePrivateProfileString(ServiceName, "website", website, IniFileNamePath); WritePrivateProfileString(ServiceName, "checked", checkedState.ToString(), IniFileNamePath); BootLoader(ServiceName); if (MessageBox.Show("已保存数据成功,是否运行浏览器?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK) { // new ViewerInternate(username, website, password).Start(); Startup(); } } private void loginBtn_Click(object sender, RoutedEventArgs e) { string password = passwordBox.Password.Trim(); string username = idTextBox.Text.Trim(); string website = webTextBox.Text.Trim(); Boolean checkedState = checkBox.IsChecked.Value; if (website.Length == 0) { MessageBox.Show("请输入'网址'", "提示"); return; } if (!checkedState) { if (password.Length == 0 || username.Length == 0) { MessageBox.Show("请输入'标识符/密码'", "提示"); return; } } // new ViewerInternate(username, website, password).Start(); Startup(); } private void checkBox_Checked(object sender, RoutedEventArgs e) { Handle(checkBox.IsChecked.Value); } private void checkBox_Unchecked(object sender, RoutedEventArgs e) { Handle(checkBox.IsChecked.Value); } void Handle(bool flag) { if (flag) { idTextBox.IsEnabled = false; passwordBox.IsEnabled = false; idTextBox.Text = ""; passwordBox.Password = ""; webTextBox.Text = "https://abc.ccc.com"; } else { idTextBox.IsEnabled = true; passwordBox.IsEnabled = true; webTextBox.Text = "https://abc.ccc.com.aspx"; } } private void BootLoader(string serviceName) { string path = @System.Environment.CurrentDirectory + "\\libs\\startup.vbs "+ System.Environment.CurrentDirectory+ "\\libs\\default.ini"; try { RegistryKey reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true); reg.SetValue(serviceName, path); reg.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Startup() { try { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "wscript.exe"; startInfo.Arguments = ".\\libs\\startup.vbs .\\libs\\default.ini"; // startInfo.FileName = @System.Environment.CurrentDirectory + "\\libs\\startup.vbs"; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = false; Process.Start(startInfo); } catch (Exception ex) { MessageBox.Show(ex.Message); } } #region 读Ini文件 public static string ReadIniData(string Section, string Key,string iniFilePath) { if (File.Exists(iniFilePath)) { StringBuilder temp = new StringBuilder(1024); GetPrivateProfileString(Section, Key, "", temp, 1024, iniFilePath); return temp.ToString(); } else { return String.Empty; } } #endregion #region API函数声明 [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)] private static extern bool WritePrivateProfileString( string lpAppName, string lpKeyName, string lpString, string lpFileName); [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)] private static extern int GetPrivateProfileString( string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName); #endregion } }
主页面布局
<Window x:Class="smartlogin.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:smartlogin" xmlns:Smart="clr-namespace:smartlogin" mc:Ignorable="d" Title="Esker自动登录设置" Height="340" Width="540" ResizeMode="CanMinimize" Icon="pictures/linkgoo.png"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="130*"/> <RowDefinition Height="191*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="7*"/> <ColumnDefinition Width="0*"/> <ColumnDefinition Width="347*"/> <ColumnDefinition Width="179*"/> <ColumnDefinition Width="0*"/> </Grid.ColumnDefinitions> <TextBox x:Name="idTextBox" HorizontalAlignment="Left" Margin="189.8,0,0,133.4" TextWrapping="Wrap" Width="280" Grid.Column="2" Grid.Row="1" FontSize="13.333" Height="32" VerticalAlignment="Bottom" VerticalContentAlignment="Center" Grid.ColumnSpan="2"> <TextBox.Resources> <VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.3" Stretch="None" AlignmentX="Left"> <VisualBrush.Visual> <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="Black" Text="请输入标识符"/> </VisualBrush.Visual> </VisualBrush> </TextBox.Resources> <TextBox.Style> <Style TargetType="TextBox"> <Style.Triggers> <Trigger Property="Text" Value="{x:Null}"> <Setter Property="Background" Value="{StaticResource HelpBrush}"/> </Trigger> <Trigger Property="Text" Value=""> <Setter Property="Background" Value="{StaticResource HelpBrush}"/> </Trigger> </Style.Triggers> </Style> </TextBox.Style> </TextBox> <PasswordBox x:Name="passwordBox" HorizontalAlignment="Left" Margin="189.8,0,0,91.4" VerticalAlignment="Bottom" Width="280" Height="32" Grid.Column="2" Grid.Row="1" FontSize="13.333" VerticalContentAlignment="Center" Grid.ColumnSpan="2"> <PasswordBox.Style> <Style TargetType="PasswordBox"> <Setter Property="Height" Value="32"></Setter> <Setter Property="HorizontalAlignment" Value="Left"></Setter> <Setter Property="VerticalAlignment" Value="Center"></Setter> <Setter Property="Smart:PasswordBoxMonitor.IsMonitoring" Value="True"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type PasswordBox}"> <Border Name="Bd" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" SnapsToDevicePixels="true"> <Grid> <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> <StackPanel Orientation="Horizontal" Visibility="Collapsed" Name="myStackPanel"> <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="LightGray" Text="请输入密码"/> </StackPanel> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Visibility" TargetName="myStackPanel" Value="Collapsed"/> </Trigger> <Trigger Property="Smart:PasswordBoxMonitor.PasswordLength" Value="0"> <Setter Property="Visibility" TargetName="myStackPanel" Value="Visible"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </PasswordBox.Style> </PasswordBox> <TextBox x:Name="webTextBox" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Top" Height="45" Margin="189.8,83,0,0" TextWrapping="Wrap" Width="280" VerticalContentAlignment="Center" Text="https://as1.ondemand.esker.com/ondemand/webaccessSSO/?uniqueId=636737578820560627209209&name=esquelprod" FontSize="13.333" Grid.ColumnSpan="2" Grid.RowSpan="2"> <TextBox.Resources> <VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.3" Stretch="None" AlignmentX="Left"> <VisualBrush.Visual> <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="Black" Text="请输入登录网址"/> </VisualBrush.Visual> </VisualBrush> </TextBox.Resources> <TextBox.Style> <Style TargetType="TextBox"> <Style.Triggers> <Trigger Property="Text" Value="{x:Null}"> <Setter Property="Background" Value="{StaticResource HelpBrush}"/> </Trigger> <Trigger Property="Text" Value=""> <Setter Property="Background" Value="{StaticResource HelpBrush}"/> </Trigger> </Style.Triggers> </Style> </TextBox.Style> </TextBox> <Button x:Name="saveBtn" Content="保存资料" Grid.Column="2" HorizontalAlignment="Left" Margin="189.8,0,0,18.4" VerticalAlignment="Bottom" Width="90" Click="saveBtn_Click" Height="32" Grid.Row="1" FontSize="14.667"/> <Button x:Name="loginBtn" Content="测试登录" Grid.Column="3" HorizontalAlignment="Left" Margin="30.6,0,0,18.4" VerticalAlignment="Bottom" Width="90" Click="loginBtn_Click" Height="32" Grid.Row="1" FontSize="14.667"/> <Image x:Name="logoImg" Grid.Column="2" HorizontalAlignment="Right" Height="91" Margin="0,80,180.629,0" VerticalAlignment="Top" Width="154" Source="pictures/esker.png" Grid.RowSpan="2"/> <CheckBox x:Name="checkBox" Content="SSO Login" Grid.Column="2" HorizontalAlignment="Left" Margin="189.8,101.4,0,0" VerticalAlignment="Top" Grid.Row="1" IsChecked="True" Checked="checkBox_Checked"/> </Grid> </Window>
VBS实现自动登录
call AutoClick function AutoClick() set argus=wscript.arguments dim website,username,password,checked if argus.count=0 then checked=ReadIni("default.ini","esker","checked") website=ReadIni("default.ini","esker","website") username=ReadIni("default.ini","esker","username") password=ReadIni("default.ini","esker","password") else checked=ReadIni( argus(0),"esker","checked") website=ReadIni( argus(0),"esker","website") username=ReadIni( argus(0),"esker","username") password=ReadIni( argus(0),"esker","password") end if set IE=CreateObject("InternetExplorer.Application") IE.visible = False IE.Width = 1024 IE.Height = 768 IE.left = 50 IE.top = 50 IE.navigate website Wait(IE) WScript.sleep 1000 If checked Then If IE.document.getElementsByName("ctl03$tbUser").length > 0 Then IE.document.getElementsByName("ctl03$tbUser")(0).value = username WScript.sleep 100 IsExit(IE) End If If IE.document.getElementsByName("ctl03$tbPassword").length > 0 Then IE.document.getElementsByName("ctl03$tbPassword")(0).value = password WScript.sleep 100 End If If IE.document.getElementsByName("ctl01$btnSubmitLogin").length > 0 Then Call IE.document.getElementsByName("ctl01$btnSubmitLogin")(0).click End If Wait(IE) End If IsExit(IE) While InStr(IE.LocationURL,"/ase")=0 WScript.sleep 1000 IsExit(IE) Wend IE.navigate "https://abc.ccc.com.aspx?tab=1345485262" Wait(IE) IsExit(IE) WScript.sleep 2000 on error resume next set table= IE.document.getElementById("tpl_ih_adminList_MainGrid") If not IsNull(table) Then set tr=table.getElementsByTagName("tr") If tr.length > 2 Then IE.navigate tr(1).getElementsByTagName("a")(1).href End If End If End function Function Wait(IE) While IE.busy Or IE.readystate <> 4 WScript.sleep 1000 IsExit(IE) Wend End function Function IsExit(IE) if VarType(IE)=9 then msgbox "您关闭了IE,程序执行终止" Wscript.quit End If End function Function ReadIni(pathset, keyname, bond) Dim fso,f,cs,text cs=0 text="" Set fso=CreateObject("scripting.filesystemobject") Set f=fso.OpenTextFile(pathset) Do While Not f.AtEndOfStream If cs=0 Then text=f.ReadLine() If InStr(1,text,"["&keyname&"]",1)=1 Then cs=cs+1 End If ElseIf cs=1 Then text=f.ReadLine() If InStr(1,text,bond,1)=1 Then readini=Split(text,"=")(1) Exit do ElseIf InStr(1,text,"[",1)=1 then cs=cs+1 End If ElseIf cs=2 Then readini="" Exit Do End If Loop f.Close Set fso=Nothing End Function
相关文章推荐
- python UnicodeEncodeError: 'ascii' codec 错误的处理
- python 修饰器学习
- win7重启 MySQL服务丢失解决方法
- 5.Java基础复习----Map
- ntpdate[16603]: the NTP socket is in use
- C++类型转换解析
- SharedPreferences 简单记录(13)
- android:内部存储空间 IO 操作openFileInput()、output(13)
- android:读取SD卡中的图片显示出来(缩略图),SD卡工具类(13)
- android:将图片写SD卡中(13)
- 一个添加删除黑名单的小记录(11)
- android:查找手机所有文件,进行浏览(文件浏览器)(13)
- android:如何将数据库取出放进ListView,并进行增删查改的简单记录(14)
- android:将数据库(SQLite)取出的数据ListView,并进行分页的简单记录(14)
- android: SQLiteOpenHelper,会将数据库放在当前应用程序的某个文件下(14)
- android: 用ContentResolver读取自己应用的短信和手机通话记录(15)
- joomla第十一节images幻灯片显示以及模块的汉化
- 宏正自动科技发行首创双控制端抽拉式LCD KVM设备
- iOS 一键加入QQ群(项目常用)
- ThreadLocal理解与分析