VBS设置系统的环境变量

来源:互联网 发布:mac使用搜狗 编辑:程序博客网 时间:2024/05/18 00:15
程序实现的是系统环境变量设置,更改Enviroment为user可设置用户变量。
Dim currentpathcurrentpath=createobject("Scripting.FileSystemObject").GetFolder(".").PathMsgBox currentpathDim ocrpathocrpath=currentpath&"\Tesseract-OCR"SetTheEnv(ocrpath)Function SetTheEnv(ocrpath)Dim pSysEnvSet pSysEnv = CreateObject("WScript.Shell").Environment("System")  pSysEnv("TESSDATA_PREFIX")=ocrpath&"\"Dim ExistValueExistValue=pSysEnv("path")Dim target,s,exist,appendvalueexist=Falseappendvalue=ocrpath&";"&ocrpath&"\training"ExistValue=ExistValue&";"&appendvalueExistValue=reduce(ExistValue,False,";")target=split(ExistValue,";")ExistValue=""For Each s In targetIf s<>"" ThenExistValue=ExistValue&s&";"End IfNextpSysEnv("path")=ExistValue'ExistValue=pSysEnv("wdir")'MsgBox("WDIR="&ExistValue)MsgBox "环境设置成功!"End FunctionFunction reduce(srcstr,casesentive,sp)Dim objDict,x,ysrcarr=split(Trim(srcstr),sp)Set objDict=createobject("Scripting.Dictionary")For Each x In srcArrIf Not casesentive Then y=LCase(x)Elsey=xEnd IfIf Not objDict.Exists(y) Then If y<>lcase(driverLetter)&"\" ThenobjDict.Add y,xEnd IfEnd IfNextreduce=Join(objDict.Items,sp)Set objDict=NothingEnd Function


原创粉丝点击