Dim currentpath
currentpath=createobject("Scripting.FileSystemObject").GetFolder(".").Path
MsgBox currentpath
Dim ocrpath
ocrpath=currentpath&"\Tesseract-OCR"
SetTheEnv(ocrpath)
Function SetTheEnv(ocrpath)
Dim pSysEnv
Set pSysEnv = CreateObject("WScript.Shell").Environment("System")
pSysEnv("TESSDATA_PREFIX")=ocrpath&"\"
Dim ExistValue
ExistValue=pSysEnv("path")
Dim target,s,exist,appendvalue
exist=False
appendvalue=ocrpath&";"&ocrpath&"\training"
ExistValue=ExistValue&";"&appendvalue
ExistValue=reduce(ExistValue,False,";")
target=split(ExistValue,";")
ExistValue=""
For Each s In target
If s<>"" Then
ExistValue=ExistValue&s&";"
End If
Next
pSysEnv("path")=ExistValue
'ExistValue=pSysEnv("wdir")
'MsgBox("WDIR="&ExistValue)
MsgBox "環境設置成功!"
End Function
Function reduce(srcstr,casesentive,sp)
Dim objDict,x,y
srcarr=split(Trim(srcstr),sp)
Set objDict=createobject("Scripting.Dictionary")
For Each x In srcArr
If Not casesentive Then
y=LCase(x)
Else
y=x
End If
If Not objDict.Exists(y) Then
If y<>lcase(driverLetter)&"\" Then
objDict.Add y,x
End If
End If
Next
reduce=Join(objDict.Items,sp)
Set objDict=Nothing
End Function
VBS設置系統的環境變量
程序實現的是系統環境變量設置,更改Enviroment爲user可設置用戶變量。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.