同花順授權自動更新腳本
具體腳本如下:
#同花順更新委托主站證書,註意key有特殊字符+-等要轉義,無轉義情況下authcodes-authcode1
$AuthCodes=‘E22-LHjT-4Itu-A7sg-Hnyi-H0U+‘
$AuthCodes1=‘E22-LHjT-4Itu-A7sg-Hnyi-H0U%2B‘
$AuthPath=‘d:\thssj\wtserver\‘
$SaveFile=$AuthPath+$AuthCodes.Substring(0,3)+‘.dat‘
#加載winapi
$ini = Add-Type -memberDefinition @"
[DllImport("Kernel32")]
public static extern int GetPrivateProfileString (
string key ,
string def ,
StringBuilder retVal ,
int size ,
string filePath );
"@ -passthru -name MyPrivateProfileString -UsingNamespace System.Text
#定義配置
$section=$AuthCodes
$filePath=$AuthPath+"pauth.ini"
$key="證書截止時間"
$retVal=New-Object System.Text.StringBuilder(200)
#查看配置文件key值
$null=$ini::GetPrivateProfileString($section,$key,"",$retVal,200,$filePath)
$dateStr = $retVal.tostring()
#格式化字符串為日期
$dateVal = get-date $dateStr
#找到提前七天日期
$dateLast = $dateVal.AddDays(-7)
#獲取當前日期
$dateNow = get-date
#key值與當前日期比較,lt是小於,ge是大於
if($dateLast -le $dateNow) {
#開始執行下載授權文件
$client = new-object System.Net.WebClient
$client.DownloadFile($NetFile,$SaveFile)
#重啟委托主站
taskkill /im hxwt.exe /f
Start-Sleep -s 3
cd $AuthPath
start hxwt.exe
}
################################################################################################
#同花順更新委托網關證書,註意key有特殊字符+-等要轉義,無轉義情況下authcodes-authcode1
$AuthCodes=‘E19-LHjT-4Itu-A7sg-Hnyi-H0U+‘
$AuthCodes1=‘E19-LHjT-4Itu-A7sg-Hnyi-H0U%2B‘
$AuthPath=‘d:\thssj\WTGateWay\‘
$NetFile=‘http://services.myhexin.com/produser/downloadcert?libver=20030506&authcode=‘+$AuthCodes1+‘&Submit=%CF%C2%D4%D8%D6%A4%CA%E9‘
$SaveFile=$AuthPath+$AuthCodes.Substring(0,3)+‘.dat‘
#加載winapi
$ini = Add-Type -memberDefinition @"
[DllImport("Kernel32")]
public static extern int GetPrivateProfileString (
string section ,
string key ,
string def ,
StringBuilder retVal ,
int size ,
string filePath );
"@ -passthru -name MyPrivateProfileString -UsingNamespace System.Text
#定義配置
$section=$AuthCodes
$filePath=$AuthPath+"pauth.ini"
$key="證書截止時間"
$retVal=New-Object System.Text.StringBuilder(200)
#查看配置文件key值
$null=$ini::GetPrivateProfileString($section,$key,"",$retVal,200,$filePath)
$dateStr = $retVal.tostring()
#格式化字符串為日期
$dateVal = get-date $dateStr
#找到提前七天日期
$dateLast = $dateVal.AddDays(-7)
#獲取當前日期
$dateNow = get-date
#key值與當前日期比較,lt是小於,ge是大於
if($dateLast -le $dateNow) {
#開始執行下載授權文件
$client = new-object System.Net.WebClient
$client.DownloadFile($NetFile,$SaveFile)
#重啟委托網關
taskkill /im WTMonitor.exe /f
Start-Sleep -s 3
cd $AuthPath
start WTMonitor.exe
}
同花順授權自動更新腳本