#include "OO_JSON_non_IE.au3" #include "JSON.au3" ; URL of the TeamViewer API Global $oErrorHandler = ObjEvent("AutoIt.Error", "_TV_ErrFunc") Global $__sTVAPI_Version, $__sTVAPI_BaseUrl ; Put the current API version in here. $__sTVAPI_Version = "v1" $__sTVAPI_BaseUrl = "https://webapi.teamviewer.com" ; Constants for file IO stuff Const $__iForReading = 1, $__iForWriting = 2, $__iForAppending = 8 Const $__iTristateUseDefault = -2, $__iTristateTrue = -1, $__iTristateFalse = 0 ;############## ; API functions ;############## ;OAuth2: get an access token by clientId and authorizationCode Func _TV_RequestOAuth_AccessToken($s_ClientId, $s_ClientSecret, $s_AuthorizationCode) _My_ConsoleWrite(@CRLF) _My_ConsoleWrite("Get token...") _My_ConsoleWrite("Request [POST] /api/" & $__sTVAPI_Version & "/oauth2/token") Local $oHTTP = ObjCreate("Msxml2.XMLHTTP") $oHTTP.Open("POST", $__sTVAPI_BaseUrl & "/api/" & $__sTVAPI_Version & "/oauth2/token", False) $oHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") Local $sPayLoad = "grant_type=authorization_code&code=" & $s_AuthorizationCode & "&client_id=" & $s_ClientId & "&client_secret=" & $s_ClientSecret ; On Error Resume Next ; Err.Clear _My_ConsoleWrite("$sPayLoad: " & $sPayLoad) $oHTTP.send($sPayLoad) If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("_TV_RequestOAuth_AccessToken request failed") ;~ _TV_RequestOAuth_AccessToken = False Return False EndIf ; Check $vResponse Local $s_status, $s_StatusText Local $vResponse = $oHTTP.ResponseText _TV_FixHttpStatusBug($oHTTP, $s_status, $s_StatusText) _My_ConsoleWrite($s_status & " " & $s_StatusText) If $s_status <> 200 Then _My_ConsoleWrite("Unexpected $vResponse code. Received content was:") _My_ConsoleWrite($vResponse) ;~ _TV_RequestOAuth_AccessToken = False Return False EndIf ; On Error Resume Next ; Err.Clear ;~ Local json = New VbsJson ;~ Local $v_TokenResultJSON = json.Decode($vResponse) Local $v_TokenResultJSON = _JSONDecode($vResponse) If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("JSON Decode failed") ;~ _TV_RequestOAuth_AccessToken = False Return False EndIf _My_ConsoleWrite("Token received.") ;~ _TV_RequestOAuth_AccessToken = $v_TokenResultJSON("access_token") Return $v_TokenResultJSON("access_token") EndFunc ;==>_TV_RequestOAuth_AccessToken ; Check if API is available and verify token is valid Func _TV_PingAPI($s_TV_AccessToken) _My_ConsoleWrite(@CRLF) _My_ConsoleWrite("Ping API...") _My_ConsoleWrite("Request [GET] /api/" & $__sTVAPI_Version & "/ping") Local $oHTTP = ObjCreate("Msxml2.XMLHTTP") $oHTTP.Open("GET", $__sTVAPI_BaseUrl & "/api/" & $__sTVAPI_Version & "/ping", False) $oHTTP.setRequestHeader("Authorization", "Bearer " & $s_TV_AccessToken) ; On Error Resume Next ; Err.Clear $oHTTP.send() If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("_TV_PingAPI request failed") ;~ _TV_PingAPI = False Return False EndIf ; Check $vResponse Local $s_status, $s_StatusText Local $vResponse = $oHTTP.ResponseText _TV_FixHttpStatusBug($oHTTP, $s_status, $s_StatusText) _My_ConsoleWrite($s_status & " " & $s_StatusText) If $s_status <> 200 Then _My_ConsoleWrite("Unexpected $vResponse code. Received content was:") _My_ConsoleWrite($vResponse) ;~ _TV_PingAPI = False Return False EndIf ;~ Set json = New VbsJson MsgBox(0, '$vResponse', $vResponse) _OO_JSON_Init() Local $jsObj = _JS_obj_create($vResponse) MsgBox(0, '$jsObj.token_valid', $jsObj.token_valid) ;~ Local $a_PingResultJSON = _JSONDecode($vResponse, 'token_valid') If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("JSON Decode failed") ;~ _TV_PingAPI = False Return False EndIf If $jsObj.token_valid = True Then _My_ConsoleWrite("Ping: Token is valid") Else _My_ConsoleWrite("Ping: Token is invalid") EndIf ;~ Return $a_PingResultJSON("token_valid") Return $jsObj.token_valid EndFunc ;==>_TV_PingAPI ; get all users of a company with all available fields Func _TV_GetAllUsersAPI($s_TV_AccessToken) _My_ConsoleWrite(@CRLF) _My_ConsoleWrite("Get all users...") _My_ConsoleWrite("Request [GET] /api/" & $__sTVAPI_Version & "/users?full_list=true") Local $oHTTP = ObjCreate("Msxml2.XMLHTTP") $oHTTP.Open("GET", $__sTVAPI_BaseUrl & "/api/" & $__sTVAPI_Version & "/users?full_list=true", False) $oHTTP.setRequestHeader("Authorization", "Bearer " & $s_TV_AccessToken) ; On Error Resume Next ; Err.Clear $oHTTP.send() If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("_TV_GetAllUsersAPI request failed") ;~ _TV_GetAllUsersAPI = False Return False EndIf ; Check $vResponse Local $s_status, $s_StatusText Local $vResponse = $oHTTP.ResponseText _TV_FixHttpStatusBug($oHTTP, $s_status, $s_StatusText) _My_ConsoleWrite($s_status & " " & $s_StatusText) If $s_status <> 200 Then _My_ConsoleWrite("Unexpected $vResponse code. Received content was:") _My_ConsoleWrite($vResponse) ;~ _TV_GetAllUsersAPI = False Return False EndIf ; On Error Resume Next ; Err.Clear ;~ Set json = New VbsJson ;~ Set $v_AllUserResultJSON = json.Decode($vResponse) Local $v_AllUserResultJSON = _JSONDecode($vResponse) If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("JSON Decode failed") ;~ _TV_GetAllUsersAPI = False Return False EndIf If $v_AllUserResultJSON Then _My_ConsoleWrite("Request ok!") If $v_AllUserResultJSON.exists("users") Then Local $sUserArr ; our received users as array of dictionaries $sUserArr = $v_AllUserResultJSON.Item("users") ;~ _TV_GetAllUsersAPI = $sUserArr Return $sUserArr Else _My_ConsoleWrite("no users received") EndIf Else _My_ConsoleWrite("Users Get: error") EndIf EndFunc ;==>_TV_GetAllUsersAPI ; get a single company user, identified by email Func _TV_GetUserByMail($s_TV_AccessToken, $s_StrMail) _My_ConsoleWrite(@CRLF) _My_ConsoleWrite("Get single user by mail (" & $s_StrMail & ")") _My_ConsoleWrite("Request [GET] /api/" & $__sTVAPI_Version & "/users?email=" & $s_StrMail & "&full_list=true") Local $oHTTP = ObjCreate("Msxml2.XMLHTTP") $oHTTP.Open("GET", $__sTVAPI_BaseUrl & "/api/" & $__sTVAPI_Version & "/users?email=" & $s_StrMail & "&full_list=true", False) $oHTTP.setRequestHeader("Authorization", "Bearer " & $s_TV_AccessToken) ; On Error Resume Next ; Err.Clear $oHTTP.send() ; Check $vResponse Local $s_status, $s_StatusText Local $vResponse = $oHTTP.ResponseText _TV_FixHttpStatusBug($oHTTP, $s_status, $s_StatusText) _My_ConsoleWrite($s_status & " " & $s_StatusText) If $s_status <> 200 Then _My_ConsoleWrite("Unexpected $vResponse code. Received content was:") _My_ConsoleWrite($vResponse) ;~ _TV_GetUserByMail = False Return False EndIf ; On Error Resume Next ; Err.Clear ;~ Local json = New VbsJson ;~ Local $oSingleUserResultJSON = json.Decode($vResponse) Local $oSingleUserResultJSON = _JSONDecode($vResponse) If @error Then ; If Err.Number <> 0 Then ; Err.Clear ;~ _TV_GetUserByMail = false Return False EndIf If $oSingleUserResultJSON Then _My_ConsoleWrite("Request ok!") If $oSingleUserResultJSON.exists("users") Then Local $sUserArr ; our received users as array of dictionaries $sUserArr = $oSingleUserResultJSON.Item("users") ;~ _TV_GetUserByMail = $sUserArr Return $sUserArr Else _My_ConsoleWrite("No user received") EndIf Else _My_ConsoleWrite("User Get: error") EndIf EndFunc ;==>_TV_GetUserByMail ; Updates a single company user: ; Field values in $v_DictUser will be used to update the given user id ($s_Update_UserId) ; if email should be updated, the dict must declare a column "newEmail" with the new email value Func _TV_UpdateUser($s_TV_AccessToken, $s_Update_UserId, $v_DictUser) _My_ConsoleWrite(@CRLF) _My_ConsoleWrite("Updating user [" & $v_DictUser.Item("email") & "]...") _My_ConsoleWrite("Request [PUT] /api/" & $__sTVAPI_Version & "/users/" & $s_Update_UserId) Local $oHTTP = ObjCreate("Msxml2.XMLHTTP") Local $s_URL = $__sTVAPI_BaseUrl & "/api/" & $__sTVAPI_Version & "/users/" & $s_Update_UserId $oHTTP.Open("PUT", $s_URL, False) $oHTTP.setRequestHeader("Authorization", "Bearer " & $s_TV_AccessToken) $oHTTP.setRequestHeader("Content-Type", "application/json; charset=utf-8") ; define update fields Local $v_JSON_PayLoad Local $o_Update_PayLoad = ObjCreate("Scripting.Dictionary") ; name parameter If $v_DictUser.Exists("name") And StringLen($v_DictUser.Item("name")) > 0 Then $o_Update_PayLoad.Add("name", $v_DictUser.Item("name")) EndIf ; password parameter If $v_DictUser.Exists("password") And StringLen($v_DictUser.Item("password")) > 5 Then $o_Update_PayLoad.Add("password", $v_DictUser.Item("password")) EndIf ; permission parameter If $v_DictUser.Exists("permissions") And StringLen($v_DictUser.Item("permissions")) > 0 Then $o_Update_PayLoad.Add("permissions", $v_DictUser.Item("permissions")) EndIf ; email parameter (column newMail must exist in csv) If $v_DictUser.Exists("newEmail") And StringLen($v_DictUser.Item("newEmail")) > 5 Then $o_Update_PayLoad.Add("email", $v_DictUser.Item("newEmail")) EndIf ; active parameter (assume every user to be updated is also active per default) If $v_DictUser.Exists("active") And StringLen($v_DictUser.Item("active")) > 0 Then $o_Update_PayLoad.Add("active", $v_DictUser.Item("active")) Else $o_Update_PayLoad.Add("active", True) EndIf ; Err.Clear ;~ Set json = New VbsJson ;~ $v_JSON_PayLoad = json.Encode($o_Update_PayLoad) $v_JSON_PayLoad = _JSONEncode($o_Update_PayLoad) If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("JSON Encode") ;~ _TV_UpdateUser = false Return False EndIf ; On Error Resume Next ; Err.Clear _My_ConsoleWrite("$sPayLoad: " & $v_JSON_PayLoad) $oHTTP.send($v_JSON_PayLoad) ; Check $vResponse Local $s_status, $s_StatusText Local $vResponse = $oHTTP.ResponseText _TV_FixHttpStatusBug($oHTTP, $s_status, $s_StatusText) _My_ConsoleWrite($s_status & " " & $s_StatusText) If $s_status = 204 Then _My_ConsoleWrite("User updated.") ;~ _TV_UpdateUser = True Return True Else _My_ConsoleWrite("Error updating user.") _My_ConsoleWrite("Unexpected $vResponse code. Received content was:") _My_ConsoleWrite($vResponse) ;~ _TV_UpdateUser = False Return False EndIf ; Err.Clear EndFunc ;==>_TV_UpdateUser ; Creates a single company user: ; Field values in $v_DictUser will be used to create the given user. ; Defaults for some missing fields (permissions, password, language) must be provided. Func _TV_CreateUser($s_TV_AccessToken, $v_DictUser, $s_strDefaultUserPermissions, $s_strDefaultUserLanguage, $s_strDefaultUserPassword) _My_ConsoleWrite(@CRLF) _My_ConsoleWrite("Creating user [" & $v_DictUser.Item("email") & "]...") _My_ConsoleWrite("Request [POST] /api/" & $__sTVAPI_Version & "/users") Local $oHTTP = ObjCreate("Msxml2.XMLHTTP") Local $s_URL = $__sTVAPI_BaseUrl & "/api/" & $__sTVAPI_Version & "/users" $oHTTP.Open("POST", $s_URL, False) $oHTTP.setRequestHeader("Authorization", "Bearer " & $s_TV_AccessToken) $oHTTP.setRequestHeader("Content-Type", "application/json") ; define fields Local $v_JSON_PayLoad Local $o_Create_PayLoad = ObjCreate("Scripting.Dictionary") ; name parameter, required If $v_DictUser.Exists("name") And StringLen($v_DictUser.Item("name")) > 0 Then $o_Create_PayLoad.Add("name", $v_DictUser.Item("name")) Else _My_ConsoleWrite("Field [name] is missing. Can; t create user.") ;~ _TV_CreateUser = false Return False EndIf ; email parameter If $v_DictUser.Exists("email") And StringLen($v_DictUser.Item("email")) > 5 Then $o_Create_PayLoad.Add("email", $v_DictUser.Item("email")) Else _My_ConsoleWrite("Field [email] is missing. Can; t create user.") ;~ _TV_CreateUser = false Return False EndIf ; password parameter, If $v_DictUser.Exists("password") And StringLen($v_DictUser.Item("password")) > 5 Then $o_Create_PayLoad.Add("password", $v_DictUser.Item("password")) Else ; use defaultUserPassword parameter $o_Create_PayLoad.Add("password", $s_strDefaultUserPassword) EndIf ; permission parameter If $v_DictUser.Exists("permissions") And StringLen($v_DictUser.Item("permissions")) > 0 Then $o_Create_PayLoad.Add("permissions", $v_DictUser.Item("permissions")) Else ; use defaultUserPermissions parameter $o_Create_PayLoad.Add("permissions", $s_strDefaultUserPermissions) EndIf ; language parameter If $v_DictUser.Exists("language") And StringLen($v_DictUser.Item("language")) > 0 Then $o_Create_PayLoad.Add("language", $v_DictUser.Item("language")) Else ; use defaultUserLanguage parameter $o_Create_PayLoad.Add("language", $s_strDefaultUserLanguage) EndIf ; On Error Resume Next ; Err.Clear ;~ Set json = New VbsJson ;~ $v_JSON_PayLoad = json.Encode($o_Create_PayLoad) $v_JSON_PayLoad = _JSONEncode($o_Create_PayLoad) If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("JSON Encode failed") ;~ _TV_CreateUser = false Return False EndIf ; On Error Resume Next ; Err.Clear _My_ConsoleWrite("$sPayLoad: " & $v_JSON_PayLoad) $oHTTP.send($v_JSON_PayLoad) ; Check $vResponse Local $s_status, $s_StatusText Local $vResponse = $oHTTP.ResponseText _TV_FixHttpStatusBug($oHTTP, $s_status, $s_StatusText) _My_ConsoleWrite($s_status & " " & $s_StatusText) If $s_status = 200 Then _My_ConsoleWrite("User created.") ;~ _TV_CreateUser = True Return True Else _My_ConsoleWrite("Error creating user.") _My_ConsoleWrite("Unexpected $vResponse code. Received content was:") _My_ConsoleWrite($vResponse) ;~ _TV_CreateUser = False Return False EndIf ; Err.Clear EndFunc ;==>_TV_CreateUser ; Deactivates a single company user: Func _TV_DeactivateUser($s_TV_AccessToken, $s_UserId) _My_ConsoleWrite(@CRLF) _My_ConsoleWrite("Deactivating user [" & $s_UserId & "]...") _My_ConsoleWrite("Request [PUT] /api/" & $__sTVAPI_Version & "/users/" & $s_UserId) Local $oHTTP = ObjCreate("Msxml2.XMLHTTP") Local $s_URL = $__sTVAPI_BaseUrl & "/api/" & $__sTVAPI_Version & "/users/" & $s_UserId $oHTTP.Open("PUT", $s_URL, False) $oHTTP.setRequestHeader("Authorization", "Bearer " & $s_TV_AccessToken) $oHTTP.setRequestHeader("Content-Type", "application/json") ; define update fields Local $v_JSON_PayLoad Local $o_Update_PayLoad = ObjCreate("Scripting.Dictionary") ; active flag $o_Update_PayLoad.Add("active", False) ; On Error Resume Next ; Err.Clear ;~ Set json = New VbsJson ;~ $v_JSON_PayLoad = json.Encode($o_Update_PayLoad) $v_JSON_PayLoad = _JSONEncode($o_Update_PayLoad) If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("JSON Encode failed") ;~ _TV_DeactivateUser = false Return False EndIf ; On Error Resume Next ; Err.Clear _My_ConsoleWrite("$sPayLoad: " & $v_JSON_PayLoad) $oHTTP.send($v_JSON_PayLoad) ; Check$vResponse Local $s_status, $s_StatusText Local $vResponse = $oHTTP.ResponseText _TV_FixHttpStatusBug($oHTTP, $s_status, $s_StatusText) _My_ConsoleWrite($s_status & " " & $s_StatusText) If $s_status = 204 Then _My_ConsoleWrite("User deactivated.") ;~ _TV_DeactivateUser = True Return True Else _My_ConsoleWrite("Error deactivating user.") _My_ConsoleWrite("Unexpected $vResponse code. Received content was:") _My_ConsoleWrite($vResponse) ;~ _TV_CreateUser = False Return False EndIf ; Err.Clear EndFunc ;==>_TV_DeactivateUser ; get all connections of a company with all available fields Func _TV_GetAllConnectionsAPI($s_TV_AccessToken) _My_ConsoleWrite(@CRLF) _My_ConsoleWrite("Get all connections...") _My_ConsoleWrite("Request [GET] /api/" & $__sTVAPI_Version & "/reports/connections") Local $oHTTP = ObjCreate("Msxml2.XMLHTTP") $oHTTP.Open("GET", $__sTVAPI_BaseUrl & "/api/" & $__sTVAPI_Version & "/reports/connections", False) $oHTTP.setRequestHeader("Authorization", "Bearer " & $s_TV_AccessToken) ; On Error Resume Next ; Err.Clear $oHTTP.send() If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("_TV_GetAllConnectionsAPI request failed") ;~ _TV_GetAllConnectionsAPI = False Return False EndIf ; Check $vResponse Local $s_status, $s_StatusText Local $vResponse = $oHTTP.ResponseText _TV_FixHttpStatusBug($oHTTP, $s_status, $s_StatusText) _My_ConsoleWrite($s_status & " " & $s_StatusText) If $s_status <> 200 Then _My_ConsoleWrite("Unexpected $vResponse code. Received content was:") _My_ConsoleWrite($vResponse) ;~ _TV_GetAllConnectionsAPI = False Return False EndIf ; On Error Resume Next ; Err.Clear ;~ Set json = New VbsJson ;~ Set $v_AllConnectionsResultJSON = json.Decode($vResponse) MsgBox(0, '$vResponse', $vResponse) FileWrite(@ScriptDir & '\Test.json',$vResponse) Local $v_AllConnectionsResultJSON = _JSONDecode($vResponse) If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("JSON Decode failed") ;~ _TV_GetAllConnectionsAPI = False Return False EndIf If $v_AllConnectionsResultJSON Then _My_ConsoleWrite("Request ok!") If $v_AllConnectionsResultJSON.exists("next_offset") Then Local $v_MoreConnections ; our received, more than 1000, connections as array of dictionaries $v_MoreConnections = _TV_GetMoreConnectionsAPI($s_TV_AccessToken, $v_AllConnectionsResultJSON) ;~ _TV_GetAllConnectionsAPI = $v_MoreConnections Return $v_MoreConnections ElseIf $v_AllConnectionsResultJSON.exists("records") Then Local $a_ConnectArr[0] ; our received, less than 1000, connections as array of dictionaries $a_ConnectArr[0] = $v_AllConnectionsResultJSON.Item("records") ;~ _TV_GetAllConnectionsAPI = $a_ConnectArr Return $a_ConnectArr Else _My_ConsoleWrite("no more connections received") EndIf Else _My_ConsoleWrite("Connections Get: error") EndIf EndFunc ;==>_TV_GetAllConnectionsAPI ; get all connections if there are more dann 1000 Func _TV_GetMoreConnectionsAPI($s_TV_AccessToken, $o_connectObj) Local $sMoreConnectionsResultJSON, $s_AccessToken, $i, $v_MoreConnections, $s_MoreConnUrl, $x ; offset url to get more connections Local $sMoreConnectionsResultJSON = $o_connectObj $s_AccessToken = $s_TV_AccessToken Local $s_StoredConnections = ObjCreate("Scripting.Dictionary") ; dictionary to store connections $i = 0 While $sMoreConnectionsResultJSON.exists("next_offset") _My_ConsoleWrite("More connections found ...") If $sMoreConnectionsResultJSON.exists("records") Then $v_MoreConnections = $sMoreConnectionsResultJSON("records") $s_StoredConnections.Add("Connections " & $i, $v_MoreConnections) $s_MoreConnUrl = "?offset_id=" & $sMoreConnectionsResultJSON.Item("next_offset") EndIf _My_ConsoleWrite(@CRLF) _My_ConsoleWrite("Get more connections...") Local $oHTTP = ObjCreate("Msxml2.XMLHTTP") $oHTTP.Open("GET", $__sTVAPI_BaseUrl & "/api/" & $__sTVAPI_Version & "/reports/connections" & $s_MoreConnUrl, False) $oHTTP.setRequestHeader("Authorization", "Bearer " & $s_AccessToken) ; On Error Resume Next ; Err.Clear $oHTTP.send() If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("_TV_GetMoreConnectionsAPI request failed") ;~ _TV_GetMoreConnectionsAPI = False Return False EndIf ; Check $vResponse Local $s_status, $s_StatusText Local $vResponse = $oHTTP.ResponseText _TV_FixHttpStatusBug($oHTTP, $s_status, $s_StatusText) _My_ConsoleWrite($s_status & " " & $s_StatusText) If $s_status <> 200 Then _My_ConsoleWrite("Unexpected $vResponse code. Received content was:") _My_ConsoleWrite($vResponse) ;~ _TV_GetMoreConnectionsAPI = False Return False EndIf ; On Error Resume Next ; Err.Clear ;~ Set $oJSON = New VbsJson ;~ Local $sMoreConnectionsResultJSON = $oJSON.Decode($vResponse) Local $sMoreConnectionsResultJSON = _JSONDecode($vResponse) If @error Then ; If Err.Number <> 0 Then EchoErrorDetails("JSON Decode failed") ;~ _TV_GetMoreConnectionsAPI = False Return False EndIf $i = $i + 1 WEnd ; writes the last connections in the dictionary If $sMoreConnectionsResultJSON.exists("records") Then $v_MoreConnections = $sMoreConnectionsResultJSON("records") $s_StoredConnections.Add("Connections " & $i, $v_MoreConnections) EndIf Local $i_CountConnections = Number($s_StoredConnections.Count) Local $a_ConnectArr[$i_CountConnections - 1] ; writes the connections from the dictionary to an array For $i = 0 To $i_CountConnections - 1 $a_ConnectArr($i) = $s_StoredConnections.Item("Connections " & $i) Next ;~ _TV_GetMoreConnectionsAPI = $a_ConnectArr Return $a_ConnectArr EndFunc ;==>_TV_GetMoreConnectionsAPI ; ################# ; Helper functions ; ################# Func Pause($s_Pause) _My_ConsoleWrite($s_Pause) MsgBox(0, '$s_Pause', $s_Pause) ;~ Local z = WScript.StdIn.Read(1) EndFunc ;==>Pause Func EchoErrorDetails($sReason) _My_ConsoleWrite($sReason & ": The error was:") ;~ _My_ConsoleWrite("Error: " & Err.Number) ;~ _My_ConsoleWrite("Error (Hex): " & Hex(Err.Number)) ;~ _My_ConsoleWrite("Source: " & Err.Source) ;~ _My_ConsoleWrite("Description: " & Err.Description ;~ Err.Clear EndFunc ;==>EchoErrorDetails ; Fix Status Code Bug of MSXML $oHTTP Implementation (204 Status is 1223) Func _TV_FixHttpStatusBug($oHTTPObj, ByRef $s_status, ByRef $s_StatusText) If $oHTTPObj.status = 1223 Then $s_status = 204 $s_StatusText = "No Content" Else $s_status = $oHTTPObj.status $s_StatusText = $oHTTPObj.StatusText EndIf EndFunc ;==>_TV_FixHttpStatusBug Func _My_ConsoleWrite($sText) ConsoleWrite($sText & @CRLF) EndFunc ;==>_My_ConsoleWrite ; User's COM error function. Will be called if COM error occurs Func _TV_ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_TV_ErrFunc