學校DrCom登錄腳本

'configure
Const DELETE_CONFIG = 0 'put 1 to delete script configure in registry
Const KEEP_QUIET = 0 'put 1 to no longer pop up MessageBox
Const DRCOM_URL = "http://172.16.3.11/"
Const DRCOM_LOGOFF_URL = "http://172.16.3.11/F.htm"
Const METHOD_POST = "POST"
Const METHOD_GET = "GET"
Const REG_KEY = "HKLM\Software\DrCom"
Const REG_CFGKEY = "HKLM\Software\DrCom\Config\"
Const CHECK_KEY_0 = "Account"
Const CHECK_KEY_1 = "Password"
Const REG_UNAME = "uname"
Const REG_UPASS = "upass"
Const DATA_0 = "DDDDD="
Const DATA_1 = "&upass="
Const DATA_2 = "&0MKKey=%B5%C7%C2%BC+Login"

'string
Const SMicrosoftXmlHttp = "Microsoft.XmlHttp"
Const SWscriptShell = "Wscript.Shell"
Const SContentType = "Content-Type"
Const Sapplicationxwww = "application/x-www-form-unlencoded"
Const STip = "Tip"
Const SQuestion = "Question"
Const SlogoffSuc = "Successfully log off DrCom!"
Const SloginSuc = "Successfully log in DrCom!"
Const SQLogoff = "Log off DrCom?"
Const SQLogin = "Log in DrCom?"
Const SITAccount = "Input Account"
Const SIAccount_0 = "Account (Stu.No.):"
Const SIAccount_1 = "put 0 to exit script"
Const SITPassword = "Input Password"
Const SIPassword = "Password :"

Function http_get(url)
    Dim http
    
    Set http = CreateObject(SMicrosoftXmlHttp)
    Call http.Open(METHOD_GET, url, False)
    Call http.Send
    http_get = http.ReadyState
    Set http = Nothing
End Function

Function http_post(url, data)
    Dim http
    
    Set http = CreateObject(SMicrosoftXmlHttp)
    Call http.Open(METHOD_POST, url, False)
    Call http.SetRequestHeader(SContentType, Sapplicationxwww)
    Call http.Send(data)
    http_post = http.ReadyState
    Set http = Nothing
End Function

Function check_loggedin()
    Dim http
    
    Set http = CreateObject(SMicrosoftXmlHttp)
    Call http.Open(METHOD_GET, DRCOM_URL, False)
    Call http.Send
    check_loggedin = 0
    If http.ReadyState <> 4 Then Exit Function
    If InStr(http.ResponseText, CHECK_KEY_1) = 0 And InStr(http.ResponseText, CHECK_KEY_0) = 0 Then
        check_loggedin = 1
    End If
    Set http = Nothing
End Function

Sub drcom_login(uname, upass)
    Dim data
    
    data = DATA_0 & uname & DATA_1 & upass & DATA_2
    Call http_post(DRCOM_URL, data)
End Sub

Sub drcom_logoff()
    If http_get(DRCOM_LOGOFF_URL) = 4 Then
        If check_loggedin() = 0 Then If KEEP_QUIET = 0 Then Call MsgBox(SlogoffSuc, vbInformation, STip)
    End If
End Sub

Sub main()
    On Error Resume Next
    Dim wsh
    Dim uname, upass, ustate
    
    If check_loggedin() = 1 Then
        If KEEP_QUIET = 0 Then If MsgBox(SQLogoff, vbQuestion Or vbYesNo, SQuestion) = vbNo Then Exit Sub
        Call drcom_logoff
    Else
        Set wsh = CreateObject(SWscriptShell)
        If KEEP_QUIET = 0 Then If MsgBox(SQLogin, vbQuestion Or vbYesNo, SQuestion) = vbNo Then Exit Sub
        uname = wsh.RegRead(REG_CFGKEY & REG_UNAME)
        upass = wsh.RegRead(REG_CFGKEY & REG_UPASS)
        Do
            If uname = "" Or upass = "" Then
                uname = InputBox(SIAccount_0 & vbCrLf & SIAccount_1, SIT_Account)
                upass = InputBox(SIPassword, SITPassword)
            End If
            If uname = "0" Then Exit Sub
            Call drcom_login(uname, upass)
            ustate = check_loggedin()
            If ustate = 0 Then
                uname = ""
                upass = ""
            End If
        Loop Until ustate = 1
        If KEEP_QUIET = 0 Then Call MsgBox(SloginSuc, vbInformation, STip)
        Call wsh.RegWrite(REG_CFGKEY & REG_UNAME, uname)
        Call wsh.RegWrite(REG_CFGKEY & REG_UPASS, upass)
        Set wsh = Nothing
    End If
    If DELETE_CONFIG = 1 Then
        Set wsh = CreateObject(SWscriptShell)
        wsh.RegDelete REG_KEY
        Set wsh = Nothing
    End If
End Sub

'script entry

Call main   ''''main proc of script

'end of script


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值