-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetCurrentEnvironment.vbs
51 lines (41 loc) · 1.93 KB
/
setCurrentEnvironment.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Dim objShell, rCode, strDeploy, m
Set objShell = CreateObject("wscript.shell")
if WScript.Arguments.Count = 0 then
on error resume next
strDeploy = objShell.RegRead("HKCU\Environment\currentDeploy")
if strDeploy = "" then
m = "No building environment was selected."
else
m = "Selected building environment is - '" & strDeploy & "'. "
end if
m = m + " In order to select building environment put the path to new environment file like 'Development.xml' as a command line parameter to this vbs-file or drag and drop it on this vbs-file."
wscript.echo m
WScript.Quit
end if
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
Set f = FSO.GetFolder(".")
if f.path = objShell.ExpandEnvironmentStrings("%windir%") + "\System32" or f.path = objShell.ExpandEnvironmentStrings("%homedrive%") + objShell.ExpandEnvironmentStrings("%homepath%") then
strDeploy = WScript.Arguments(0)
else
strDeploy = f.path & "\" & WScript.Arguments(0)
end if
Set deployFile = FSO.GetFile(strDeploy)
Set scriptFolder = FSO.GetFile(WScript.ScriptFullName).ParentFolder
if not deployFile.ParentFolder = scriptFolder then
FSO.Copyfile strDeploy, scriptFolder & "\"
strDeploy = scriptFolder & "\" & deployFile.Name
end if
Set getOSVersion = objShell.exec("%comspec% /c ver")
version = getOSVersion.stdout.readall
Select Case True
Case InStr(version, " 5.") > 1 :
rCode = objShell.RegWrite("HKCU\Environment\currentDeploy", strDeploy, "REG_SZ")
strDeploy = objShell.RegRead("HKCU\Environment\currentDeploy")
wscript.echo "Building environment marked in the windows environment variable 'currentDeploy' is " & strDeploy & _
". You have to restart PC or to fulfill Logoff\Logon. "
rem Case InStr(version, "n 6.") > 1 : GetOS = "Vista"
Case Else :
objShell.run "cmd /c setx currentDeploy " + strDeploy
rem quit cause RegRead("HKCU\Environment\currentDeploy") gives old value
End Select