Cisco Anyconnect VPN上的VB脚本

时间:2013-08-14 19:56:30

标签: vbscript vpn cisco

我是新手使用VB脚本。我使用以下代码连接我的VPN。但问题是在VPN客户端输入“选择”按钮后,第二页显示取决于网络速度。有时它会在4秒内加载,有时在10秒后加载。是否有任何代码可以让VPN完全加载或不加载(如IE的BUSY命令)。

    set WshShell=Wscript.CreateObject("Wscript.Shell")
    WshShell.Run("""C:\\Program Files\Cisco\Anyconnect\vpnui.exe""")
    WScript.Sleep 500

    WshShell.SendKeys "{ENTER}"
    WScript.Sleep 500 
    WshShell.SendKeys "username"
    WshShell.SendKeys "rsa_no"
    WshShell.SendKeys "password"
    WScript.Sleep 500 
    WshShell.SendKeys "{ENTER}"

1 个答案:

答案 0 :(得分:0)

请尝试下面的代码。请注意,您可能需要调整睡眠时间(以毫秒为单位)。要查看命令提示符中发生的情况,请将第9行中的1更改为Dim host, username, password, pathToClient host = "yourHostURL" username = "yourUsername" password = "yourPassword" pathToClient = "C:\Program Files {(}x86{)}\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe" Set ws = WScript.CreateObject("WScript.Shell") ws.run("TASKKILL.exe /F /IM vpnui.exe"), 0, false ws.run("cmd.exe"), 2, false ws.AppActivate("Command Prompt") WScript.Sleep 300 ws.SendKeys """" & pathToClient & """ connect " & host & "~" WScript.Sleep 1000 ws.SendKeys(username & "~") WScript.Sleep 50 ws.SendKeys(password & "~") ws.run("TASKKILL.exe /F /IM cmd.exe"), 0, false

        for (int i = 0; i < AssociatedSteps.Length; i++)
        {
            //if (i == 0 || AssociatedSteps[i].OriginPkg != AssociatedSteps[i-1].OriginPkg)
            //{
            //Define new Row to add
            RowDef = new RowDefinition();
            RowDef.Height = new GridLength(60);

            //Add row definition to Grid
            WorkPackageViewResults.RowDefinitions.Add(RowDef);

            //Define the control that will be added to new row
            Text1 = new TextBlock();
            Text1.Text = AssociatedSteps[i].SF01;
            Text1.Width = Settings.workPackageColumn5Width;
            Text1.TextAlignment = TextAlignment.Center;

            Text2 = new TextBlock();
            Text2.Text = AssociatedSteps[i].SF10;
            Text2.Width = Settings.workPackageColumn5Width;
            Text2.TextAlignment = TextAlignment.Center;

            Text3 = new TextBlock();
            Text3.Text = AssociatedSteps[i].OriginPkg;
            Text3.Width = Settings.workPackageColumn5Width;
            Text3.TextAlignment = TextAlignment.Center;

            Button1 = new Button();
            Button1.Content = AssociatedSteps[i].Description;
            Button1.Width = Settings.workPackageColumn5Width;
            Button1.Click += new RoutedEventHandler(ProgressUpdateButton_Click);
            Button1.Tag = AssociatedSteps[i].StepID;

            //create stackpanel and define which row to add the stackpanel to
            StackP = new StackPanel();
            //StackP.Background = new SolidColorBrush(Colors.Wheat);
            StackP.SetValue(Grid.RowProperty, i);
            StackP.Orientation = Orientation.Horizontal;
            StackP.Margin = new Thickness(0, 0, 0, 0);

            PercentComplete = new TextBlock();
            PercentComplete.Text = (Convert.ToDouble(AssociatedSteps[i].ToDateQty) / Convert.ToDouble(AssociatedSteps[i].MTOQty)).ToString();
            PercentComplete.Width = Settings.workPackageColumn5Width;
            PercentComplete.TextAlignment = TextAlignment.Center;

            //add your control to the stackpanel
            StackP.Children.Add(Text1);
            StackP.Children.Add(Text2);
            StackP.Children.Add(Text3);
            StackP.Children.Add(Button1);
            StackP.Children.Add(PercentComplete);
            //add the stackpanel to the grid
            WorkPackageViewResults.Children.Add(StackP);
        }
相关问题