Sign in to follow this  
Followers 0
Icarii

Systray for Netscreen Remote

3 posts in this topic

#1 ·  Posted (edited)

Ok, I know this is been brought up a few times, but I am having a few problems getting everything to work correctly. I am running Nescreen Remote Client and need to create a script that will: 1. verify internetconnection is up(sprint card), 2. disconnect any VPN connected, 3. deactivate security policy (if active), 4. activate security policy, 5. start vpn connection, 6. authenticate, 7. start logon script and gpupdate refresh.

I have created one using systray_udf.au3

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template AutoIt script.
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include "SysTray_UDF.au3"
ProgressOn("Connecting VPN to PD!", "Please Wait!", "0 percent", 320, 520, 16)
;BlockInput(1)

$i = 0
$j = 0

$p = 10
ProgressSet($p, $p & " percent")

;;Start checking to see if there is a internet conection
$MouseClick = "left"
$TrayFile = "OSCM3.exe"
TraySelect()

$p = 20
ProgressSet($p, $p & " percent")

WinActivate("Sprint PCS Connection Manager for Novatel Wireless", "")
WinWaitActive("Sprint PCS Connection Manager for Novatel Wireless", "", 60)
If Not WinActive("Sprint PCS Connection Manager for Novatel Wireless", " Mobile Broadband: Connected") Then
    BlockInput(0)
    MsgBox(0, "Sprint Error", "Internet Is Not Connected. Please Click 'GO', Check Your Connection And Try Again.")
    Exit
EndIf

$p = 40
ProgressSet($p, $p & " percent")

WinSetState("Sprint PCS Connection Manager for Novatel Wireless", "", @SW_HIDE)

;Exit
;;start vpn connection
$MouseClick = "left"
$TrayFile = "SafeCfg.exe"
TraySelect()
;MouseClick("right")
;Sleep(1050)

$p = 50
ProgressSet($p, $p & " percent")

;;Check status of netscreen remote and act accorfingly
$TrayCount = _SysTrayIconCount()
MsgBox(0,"count",$TrayCount)
For $i = 0 To $TrayCount
    $j = $i;correct function
    If _SysTrayIconTooltip ($i) = "NetScreen-Remote - Policy is deactivated!" Then;If NSR is deactivated start it
        MouseClick("right")
        Sleep(100)
        Send("{UP}")
        Sleep(50)
        Send("{UP}")
        Sleep(50)
        Send("{UP}")
        Sleep(50)
        Send("{UP}")
        Sleep(50)
        Send("{UP}")
        Sleep(50)
        Send("{UP}")
        Sleep(50)
        Send("{UP}")
        Sleep(50)
        Send("{UP}")
        Sleep(50)
        Send("{UP}")
        Sleep(50)
        Send("{ENTER}")
        Sleep(1500)
        MsgBox(0,"deactivated","")
        $p = 60
        ProgressSet($p, $p & " percent")
    Else;If NSR is Activated then deactivate it and reactivate
        If _SysTrayIconTooltip ($i) = "NetScreen-Remote" Then
            Sleep(1000)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{ENTER}")
            Sleep(1500)
            MouseClick("right")
            Sleep(1000)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{UP}")
            Sleep(50)
            Send("{ENTER}")
            Sleep(1500)
            MsgBox(0,"activate","")
            $p = 60
            ProgressSet($p, $p & " percent")
        EndIf
    EndIf
    $i = $j;correct function
Next

;Start vpn connection authentication
MouseClick("right")
Send("{UP}")
Sleep(50)
Send("{UP}")
Sleep(50)
Send("{UP}")
Sleep(50)
Send("{UP}")
Sleep(50)
Send("{right}")
Sleep(50)
Send("{ENTER}")

;BlockInput(0)

$p = 70
ProgressSet($p, $p & " percent")

WinWait("User Authentication for My Connections\vpn", "", 60)
If Not WinExists("User Authentication for My Connections\vpn", "") Then
    BlockInput(0)
    MsgBox(0, "VPN ERROR", "The Connection Failed. Please try again." & @CR & "If the problem continues, contact Technical Support.")
    Exit
EndIf
If Not WinActive("User Authentication for My Connections\City of El Reno", "") Then WinActivate("User Authentication for My Connections\vpn", "")
WinWaitActive("User Authentication for My Connections\vpn", "", 10)
$p = 80
ProgressSet($p, $p & " percent")
Send("user{TAB}password{ENTER}")
WinWait("Manual Connection Status", "Successfully connected to My Connections\vpn", 20)
If Not WinExists("Manual Connection Status", "Successfully connected to My Connections\vpn") Then
    BlockInput(0)
    MsgBox(0, "VPN ERROR", "The Connection Failed. Please try again." & @CR & "If the problem continues, contact Technical Support.")
    Exit
EndIf
If Not WinActive("Manual Connection Status", "Successfully connected to My Connections\vpn") Then WinActivate("Manual Connection Status", "Successfully connected to My Connections\vpn")
$p = 90
ProgressSet($p, $p & " percent")
WinWaitActive("Manual Connection Status", "Successfully connected to My Connections\vpn", 60)
Send("{ENTER}")

$p = 95
ProgressSet($p, $p & " percent")
Sleep(2000)

Run("erpd-logon.bat", "", @SW_MINIMIZE)
$i = 0
$j = 0
BlockInput(0)
$p = 100
ProgressSet($p, $p & " percent")
ProgressOff()

Func TraySelect()
    $oldMatchMode = Opt("WinTitleMatchMode", 4)
    $oldChildMode = Opt("WinSearchChildren", 1)

    $class = "classname=Shell_TrayWnd"
    $hControl = ControlGetHandle($class, "", "Button2")
; Press hide inactive icon's button part is from Valik's refresh system tray script!
    $oldMatchMode = Opt("WinTitleMatchMode", 4)
    $oldChildMode = Opt("WinSearchChildren", 1)

    $class = "classname=Shell_TrayWnd"
    $hControl = ControlGetHandle($class, "", "Button2")
    
; get tray position and move there. Helps if Auto Hide tray option is used.
    $posTray = WinGetPos(_FindTrayToolbarWindow ())
    MouseMove($posTray[0], $posTray[1])

    $index = _SysTrayIconIndex ($TrayFile); Change this to some other application if needed
    If $index <> -1 Then
        $pos = _SysTrayIconPos ($index)

        If $pos = -1 Then
    ; ***** Moved by CatchFish *****
    ; If XP and the Hide Inactive Icons mode is active
            If $hControl <> "" And ControlCommand($class, "", $hControl, "IsVisible", "") Then
                ControlClick($class, "", $hControl)
                Sleep(250); Small delay to allow the icons to be drawn
            EndIf
    ; ******************************
            $pos = _SysTrayIconPos ($index)
            If $pos = -1 Then Exit; ** A real error this time;)
        EndIf

        MouseMove($pos[0], $pos[1])
        Sleep(1000)
        MouseClick($MouseClick)
    EndIf
    
    ConsoleWrite(@CRLF & @CRLF & "Pos[0]: " & $pos[0] & "$pos[1]: " & $pos[1])
; Restore Opt settings
    Opt("WinTitleMatchMode", $oldMatchMode)
    Opt("WinSearchChildren", $oldChildMode)
    Sleep(1000)
EndFunc ;==>TraySelect

Func _ActDeact()
    Send("{UP}")
    Sleep(50)
    Send("{UP}")
    Sleep(50)
    Send("{UP}")
    Sleep(50)
    Send("{UP}")
    Sleep(50)
    Send("{UP}")
    Sleep(50)
    Send("{UP}")
    Sleep(50)
    Send("{UP}")
    Sleep(50)
    Send("{UP}")
    Sleep(50)
    Send("{UP}")
    Sleep(50)
    Send("{ENTER}")
    Sleep(1500)
EndFunc ;==>ActDeact

Problem is, it works most of the time. When it quits, it get to the popup menu for NSR, then it is supposed to key up the the desired action but it never does.

I tried to use some code from this post

http://www.autoitscript.com/forum/index.ph...mp;hl=netscreen

but I could not get it to return a correct number for the icons. Plus I am still trying to get a grasp on the Auto3lib and how to use it. Looks cool though.

I know there has to be an easier way to do this I just have not figured it out yet. Any help would be great.

Icarii

Edited by Icarii

Share this post


Link to post
Share on other sites



Well, I think I can help you out with the Auto3Lib part. :) I not sure about the rest, but let's take it one step at a time. First, if you're want to use Auto3Lib, handling popup menus is pretty simple. For example, the following snippet will right click (where the mouse is when it's run) and list the text for all the items in the context menu that appears:

#include <A3LMenu.au3>

MouseClick("right")
$hMenu = _Lib_PopupGetHwnd()
for $iI = 0 to _Menu_GetItemCount($hMenu) - 1
  ConsoleWrite(_Menu_GetItemText($hMenu, $iI) & @CR)
nextoÝ÷ Ù8^ì­¢ë"(×±¶g§ºÈ¬ëmx-èZÙ^¶azg§¹8b²+0«K³è¦êFzÑð×hzÂ-­ën®{-èZÙ^¶azg§º)íç(×±¶g§¸ZèØ^­ì¨¹Æ§ºÇ­+!jwez)Ú*¶Ü³çîËb¢{£¯z»ax
Ë1éînç(ë0Ø_ºw-ìn襶Ê^r'âr&¥'è­ÉbrH§Ê'µìméîצ°Z+{¦¦W­çèZ0x,*izÜ"YZºw!e¢·«®(!µÉbrKh²0¶¢{^ÆÙæ§vØ^Ç¥yËUìrìjëh×6#include <A3LMenu.au3>

; Open up Explorer
Run("explorer.exe /root, ,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
_Lib_WinWaitActive("My Computer")

; Right click in the middle of the ListView control
ControlClick("My Computer", "", "SysListView321", "right")

; Select the "View" menu
_Menu_ClickPopupAccel("V")

; Select the "Icons" view
_Menu_ClickPopupAccel("n")oÝ÷ Ø×±·*.«Þ¶ÞjX³zØZ¶Ø^K+-zdëk(¬ë-i:(¶«rí®S«lÓh¨"rz,¢®º+°¬µ©h¢[j·(ÚèK"ay:(¶«nçë¢`.¶Ë¼¨¹Æ§v¥Ê+¶Ê¶§Ì"¶­N¢YhÂ)à²x©¥ëpYeËhºÛayÆ©¶*'~Ú[az趦²»§)à|¨º»2²×¦¶¶²jëh×6#include <A3LToolbar.au3>

Opt("WinTitleMatchMode", 4)

$hWnd = ControlGetHandle("classname=Shell_TrayWnd", "", "Notification Area")
for $iI = 1 to _Toolbar_ButtonCount($hWnd)
  $iCommand = _Toolbar_IndexToCommand($hWnd, $iI)
  $sText    = _Toolbar_GetButtonText ($hWnd, $iCommand)
  if $sText <> "" then ConsoleWrite($sText & @CR)
next

And just like the A3LMenu module, there are functions in A3LToolbar to click on these items, including right clicking to bring up their context menus.

Hope some of this helps. If you have any Auto3Lib questions, feel free to post them in the Auto3Lib thread in the examples forum if they're simple or PM me if it's really involved. :)


Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

Thanks for the help. The code below is what I came up with and seams to be working great.

#include <A3LToolbar.au3>
#include <A3LMenu.au3>

Opt("MustDeclareVars"  , 1)
Opt("WinTitleMatchMode", 4)

Global $hWnd, $iCount, $iI, $iCount, $iCommand, $sText, $p

; ====================================================================================================
===========================
; Main
; ====================================================================================================
===========================

ProgressOn("Connecting VPN to PD!", "Please Wait!", "0 percent", 320, 520, 16)

$hWnd   = ControlGetHandle("classname=Shell_TrayWnd", "", "Notification Area")
$iCount = _Toolbar_ButtonCount($hWnd)

$p = 10
ProgressSet($p, $p & " percent")

;check and see that Sprint Ineternet is connected, if not return error and exit
For $iI = 1 to $iCount
  $iCommand = _Toolbar_IndexToCommand($hWnd, $iI)
  $sText    = _Toolbar_GetButtonText ($hWnd, $iCommand)
  IF _Toolbar_GetButtonText($hWnd, $iCommand) = "Sprint Mobile Broadband" Then
        _Toolbar_ClickButton($hWnd, $iCommand, "left")
        WinActivate("Sprint PCS Connection Manager for Novatel Wireless", "")
        WinWaitActive("Sprint PCS Connection Manager for Novatel Wireless", "", 60)
        If Not WinActive("Sprint PCS Connection Manager for Novatel Wireless", " Mobile Broadband: Connected") Then
            BlockInput(0)
            MsgBox(0, "Sprint Error", "Internet Is Not Connected. Please Click 'GO', Check Your Connection And Try Again.")
            Exit
        EndIf
        WinSetState("Sprint PCS Connection Manager for Novatel Wireless", "", @SW_HIDE)
  EndIf
Next

$p = 20
ProgressSet($p, $p & " percent")

$hWnd   = ControlGetHandle("classname=Shell_TrayWnd", "", "Notification Area")
$iCount = _Toolbar_ButtonCount($hWnd)

;check to see what state NSR is in, dea=activate act=deactivate and activate
For $iI = 1 to $iCount
  $iCommand = _Toolbar_IndexToCommand($hWnd, $iI)
  $sText    = _Toolbar_GetButtonText ($hWnd, $iCommand)
  IF _Toolbar_GetButtonText($hWnd, $iCommand) = "NetScreen-Remote - Policy is deactivated!" Then
      _Toolbar_ClickButton($hWnd, $iCommand, "right")
      _Menu_ClickPopupAccel("t")
  EndIf
  
  $p = 30
  ProgressSet($p, $p & " percent")
  
  IF _Toolbar_GetButtonText($hWnd, $iCommand) = "NetScreen-Remote" Then
    _Toolbar_ClickButton($hWnd, $iCommand, "right")
    _Menu_ClickPopupAccel("p")
    Sleep(500)
    _Toolbar_ClickButton($hWnd, $iCommand, "right")
    Sleep(500)
    _Menu_ClickPopupAccel("t")
  EndIf
Next

$p = 40
ProgressSet($p, $p & " percent")

$hWnd   = ControlGetHandle("classname=Shell_TrayWnd", "", "Notification Area")
$iCount = _Toolbar_ButtonCount($hWnd)

Sleep(2000)

;start vpc connection
For $iI = 1 to $iCount
  $iCommand = _Toolbar_IndexToCommand($hWnd, $iI)
  $sText    = _Toolbar_GetButtonText ($hWnd, $iCommand)
  IF _Toolbar_GetButtonText($hWnd, $iCommand) = "NetScreen-Remote - Policy is deactivated!" Then
      _Toolbar_ClickButton($hWnd, $iCommand, "right")
      MsgBox(0,"Netscreen Error","There was a problem with Activating the NSR Software." & @CR & "Please Try Again. If The Problem COntinues Please Contact Technical Support.")
      Exit
  EndIf
  
  IF _Toolbar_GetButtonText($hWnd, $iCommand) = "NetScreen-Remote" Then
    _Toolbar_ClickButton($hWnd, $iCommand, "right")
    _Menu_ClickPopupAccel("c")
    Sleep(500)
;_Menu_ClickPopupAccel("m")
    Send("m")
;MsgBox(0,"2","")
  EndIf
Next

$p = 50
ProgressSet($p, $p & " percent")

;start authentication
WinWait("User Authentication for My Connections\vpn", "", 60)
If Not WinExists("User Authentication for My Connections\vpn", "") Then
    BlockInput(0)
    MsgBox(0, "VPN ERROR", "The Connection Failed. Please try again." & @CR & "If the problem continues, contact Technical Support.")
    Exit
EndIf
If Not WinActive("User Authentication for My Connections\vpn", "") Then WinActivate("User Authentication for My Connections\vpn", "")
WinWaitActive("User Authentication for My Connections\vpn", "", 10)

$p = 60
ProgressSet($p, $p & " percent")

Send("username{TAB}password{ENTER}")
WinWait("Manual Connection Status", "Successfully connected to My Connections\vpn", 20)
If Not WinExists("Manual Connection Status", "Successfully connected to My Connections\vpn") Then
    BlockInput(0)
    MsgBox(0, "VPN ERROR", "The Connection Failed. Please try again." & @CR & "If the problem continues, contact Technical Support.")
    Exit
EndIf
If Not WinActive("Manual Connection Status", "Successfully connected to My Connections\vpn") Then WinActivate("Manual Connection Status", "Successfully connected to My Connections\vpn")

$p = 80
ProgressSet($p, $p & " percent")

WinWaitActive("Manual Connection Status", "Successfully connected to My Connections\vpn", 60)
Send("{ENTER}")

$p = 90
ProgressSet($p, $p & " percent")



;run logon script and gpupdate in batch file
Run("logon.bat", "", @SW_MINIMIZE)

Well, now I am trying to write a script that updates a products table in an Access database. Thanks again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0