Option Explicit
Dim strComputer : strComputer = "."
' 기본 Object 가져오기
Dim Shell : Set Shell = WScript.CreateObject("WScript.Shell")
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim WshEnv : Set WshEnv = Shell.Environment("Process")
Dim ProgramDir : ProgramDir = WshEnv("ProgramFiles")
Dim Reg : Set Reg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Dim WMIService : Set WMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'CMD 윈도우 98에서도 적용 가능하게 COMSPEC으로 가져온다.
Dim COMSPEC : COMSPEC = Shell.ExpandEnvironmentStrings("%comspec%")
'현재 세팅 파일 경로 구하기
Dim strSetupFile : strSetupFile = "Env_Setting.vbs"
'Main 함수 실행 후 종료
MainFunction
Wscript.quit
'Main 함수
Sub MainFunction
' 세팅 파일 절대 경로 구하기
Dim strParentFolderPath
GetParentFolderPath strSetupFile, strParentFolderPath
' 환경 변수 레지스트리 설정
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strKeyPath, strValueName, strValue
'일단 등록하고 아래에서 바로 사용할 수 있도록 Refresh 하자
strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
strValueName = "TTF_Base"
strValue = strParentFolderPath
Reg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
strValueName = "TTF_Base_Header"
strValue = "%TTF_Base%\include\Header"
Reg.SetExpandedStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
strValueName = "TTF_Base_Lib"
strValue = "%TTF_Base%\Include\Library"
Reg.SetExpandedStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
strValueName = "TTF_Base_UnitTest"
strValue = "%TTF_Base%\UnitTest++\src"
Reg.SetExpandedStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
'환경 변수 새로고침(바로 사용 가능하도록 Refresh)
Dim colItems : Set colItems = WMIService.ExecQuery ("Select * from Win32_Environment WHERE SystemVariable = True")
Dim objItem
For Each objItem in colItems
objItem.Put_
Next
End Sub
Sub GetParentFolderPath(strFileName, strFileFullPath)
Dim objFile
Set objFile = FSO.GetFile( strFileName )
strFileFullPath = FSO.GetParentFolderName(objFile)
End Sub





Env_Setting.vbs








블로그 이전 ..





2009/01






