Results 1 to 14 of 14

Thread: Automation Help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Bronze Member
    Join Date
    Dec 2005
    Posts
    175
    Or use Rasdial

    1. Try to establish connection using RasDial
    2 a. if connection successful - write an event log record and start p2p program
    2 b. if connection failed - write an event log record and redial.

    Code:
    ConnectionName = "XYZ"
    strUserName = "username"
    strPassword = "pass"
    nRedial = 10
    progEXEpath = "path of p2p.exe"
    
    sDialUpCmd = "Rasdial " & ConnectionName & " " & chr(34) & strUserName & chr(34)  & " " & chr(34) & strPassword & chr(34) 
    
    Set objShell = Wscript.CreateObject("Wscript.Shell")
    
    Do 
    sResult = CMDResults(sDialUpCmd)
    If InStr(1, sResult, error, vbTextCompare) = 0 Then
       objShell.LogEvent 0, sResult  
       StartPrgm progEXEpath 
       WScript.Quit
    Else
        'Wscript.Echo i
        objShell.LogEvent 0, sResult 
        i = i + 1
    End If
    Wscript.Sleep 5000
    Loop Until i = nRedial
    
    Function CMDResults(cmdline)
      Set oExCmd = objShell.Exec(cmdline)
      Set oExCmdStdOut = oExCmd.StdOut
      Do: WScript.Sleep 10
        Do Until oExCmdStdOut.AtEndOfStream
          CmdResults = CmdResults & oExCmdStdOut.ReadAll
        Loop
      Loop Until oExCmd.Status <> 0 and oExCmdStdOut.AtEndOfStream
    End Function
    
    Sub StartPrgm(strPath)
    Const NORMAL_WINDOW = 5
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
    Set objStartup = objWMIService.Get("Win32_ProcessStartup")
    Set objConfig = objStartup.SpawnInstance_
    objConfig.ShowWindow = NORMAL_WINDOW
    Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
    errReturn = objProcess.Create _
    (strPath, null, objConfig, intProcessID)
    End Sub
    Copy the code (add connection name (ConnectionName), username (strUserName), password (strPassword), no. of redials (nRedial) and p2p program path (progEXEPath) to notepad save it as dial.vbs file. Double-click dial.vbs to run it.

    http://windowsxp.mvps.org/rasdial.htm

    =======

    Terminate your dial-up connection

    http://windowsxp.mvps.org/closeras.htm

    Or use this script
    Code:
    ConnectionName = "XYZ"
    
    sDialUpCmd = "Rasdial " & ConnectionName & " /DISCONNECT"
    
    Set objShell = Wscript.CreateObject("Wscript.Shell")
    
    sResult = CMDResults(sDialUpCmd)
      objShell.LogEvent 0, sResult  
    
    Function CMDResults(cmdline)
      Set oExCmd = objShell.Exec(cmdline)
      Set oExCmdStdOut = oExCmd.StdOut
      Do: WScript.Sleep 10
        Do Until oExCmdStdOut.AtEndOfStream
          CmdResults = CmdResults & oExCmdStdOut.ReadAll
        Loop
      Loop Until oExCmd.Status <> 0 and oExCmdStdOut.AtEndOfStream
    End Function
    Copy the code (add connection name(ConnectionName)) to notepad and save it as terminate.vbs. Double click terminate.vbs to run it.

    =======

    To shutdown computer automatically

    (a) if connection failed:

    add
    Code:
    WScript.Sleep 5000
    objShell.Run “Shutdown –s –t 60"
    after Loop Until i = nRedial (1st script)

    (b) after terminating connection : add the above code after objShell.LogEvent 0, sResult (2nd Script)

    Or download shutdown.exe and add
    Code:
    WScript.Sleep 5000
    objShell.Run “path of shutdown.exe –u"
    Last edited by Kane; July 23rd, 2006 at 23:05 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •