Re: Make icon select environment at startup [DEFINITIVE]
Here is the definitive, all singing, all dancing version of the OneWorld startup script which allows you to specify the environment that the user will see when they start OneWorld. Note the commented portion which explains how to do this for a terminal server.
What this does, by the way, is to open the JDE.INI, search for the LASTENV entry, and overwrite it with the environment you want to log into. If the key doesn't exist (as in a new installation), it will create it. I used some code from Nolan Bagadiong which reads and writes to INI files from VBS programs.
//////////////////
' START FUNCTIONS AND SUBS HERE '===================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalSCRIPT(TM)
'
' NAME: VBScript ReadINI/WriteINI
'
' AUTHOR: Bagadiong, Nolan
' DATE : 7/27/2001
'
' COMMENT: Uses Regular Expressions to find keys and values; no longer case ' or space sensitive ' ' If you pass READINI(file, section, key), function returns scalar of the value ' assigned to key '
' If you pass READINI(file,"section", ""), function returns array of all keys ' under "section" ' ' If you pass READINI(file,"",""), function returns array of sections in the ' file '
'===================
'Usage
' READINI (file, section, item) returns value; otherwise returns ""
Function ReadINI(file, section, key)
set FileSysObj = CreateObject("Scripting.FileSystemObject")
ReadIni=""
If FileSysObj.FileExists(file) then
Set ini = FileSysObj.OpenTextFile( file, 1, False)
' Return array of sections if section and keys are empty
if section="" then
set reSection =new RegExp
reSection.Global =True
reSection.IgnoreCase=True
reSection.Pattern ="\[([a-zA-Z0-9 ]*)\]"
Do While ini.AtEndofStream =False
line = ini.ReadLine
if reSection.Test(line) then
tempSection=tempSection & reSection.Replace(line, "$1") & ","
end if
loop
ini.close
tempSection=left(tempSection, len(tempSection)-1)
ReadINI=split(tempSection,",")
set reSection=nothing
exit function
end if
' Return array of keys if keys are empty
if key="" then
set reSection =new RegExp
reSection.Global =True
reSection.IgnoreCase=True
reSection.Pattern ="\s*\[\s*" & section & "\s*\]"
Do While ini.AtEndofStream =False
line = ini.ReadLine
if reSection.Test(line) then
line=ini.ReadLine
do while instr(line,"[")=0
tempKeys=tempKeys & trim(left(line,instr(line,"=")-1)) & ","
line=ini.ReadLine
loop
tempKeys=left(tempKeys,(len(tempkeys)-1)) ' Remove last comma
ReadINI =split(tempKeys,",")
exit function
end if
loop
end if
'===================
' READINI Part for file, section, key
set reSection =new RegExp
reSection.Global =False
reSection.IgnoreCase=True
'reSection.Pattern ="\s*[\s*" & section & "\s*]"
reSection.Pattern ="\s*\[\s*" & section & "\s*\]"
set reKey =new RegExp
reKey.Global =False
reKey.IgnoreCase=True
reKey.Pattern="\s*" & key & "\s*=\s*"
Do While ini.AtEndofStream = False
line = ini.ReadLine
if reSection.Test(line) = True then
line=ini.ReadLine
do while instr(line,"[")=0
if reKey.Test(line) then
ReadINI=trim(mid(line,instr(line,"=")+1))
exit do
end if
line=ini.ReadLine
Loop
exit do
end if
loop
ini.Close
set reSection=nothing
set reKey =nothing
end if ' If FileSysObj
end function
'==================
' WRITEINI ( file, section, item, value )
' file = path and name of ini file
' section = [Section] must be in brackets in the ini file
' item = the variable to read;
' value = the value to assign to the item.
'
Sub WriteIni( file, section, item, value )
set FileSysObj = CreateObject("Scripting.FileSystemObject")
in_section = False
section_exists = False
item_exists = ( ReadIni( file, section, item ) <> "" )
wrote = False
path = Mid( file, 1, InStrRev( file, "\" ) )
Set read_ini = FileSysObj.OpenTextFile( file, 1, True, TristateFalse )
Set write_ini = FileSysObj.CreateTextFile( path & "temp_ini.ini", False )
set reWSection =new RegExp
reWSection.Global =False
reWSection.IgnoreCase=True
reWSection.Pattern ="\s*[\s*" & section & "\s*]"
set reItem =new RegExp
reItem.Global =False
reItem.IgnoreCase=True
reItem.Pattern ="\s*" & item & "\s*="
While read_ini.AtEndOfStream = False
line = read_ini.ReadLine
If wrote = False Then
If reWSection.Test(line) Then
section_exists = True
in_section = True
ElseIf InStr( line, "[" )> 0 Then
in_section = False
End If
End If
If in_section Then
If item_exists = False Then
write_ini.WriteLine line
write_ini.WriteLine item & "=" & value
wrote = True
in_section = False
msgbox "Writing " & line
ElseIf reItem.Test(line) Then
write_ini.WriteLine item & "=" & value
wrote = True
in_section = False
Else
write_ini.WriteLine line
End If
Else
write_ini.WriteLine line
End If
Wend
If section_exists = False Then ' section doesn't exist
section=trim(section)
item =trim(item)
write_ini.WriteLine
write_ini.WriteLine "[" & section & "]"
write_ini.WriteLine item & "=" & value
End If
read_ini.Close
write_ini.Close
FileSysObj.DeleteFile file
FileSysObj.MoveFile path & "temp_ini.ini", file
set reWSection=nothing
set reItem=nothing
End Sub
const taWindowHidden = 0
const taWindowShow = 1
const taWaitForFinish = True
const taDontWaitForFinish = False
Dim oSh
' NOTE: this section only works for regular clients. See below
' for the version for Terminal Server.
WriteIni "c:\winnt\jde.ini", "SIGNON", "LASTENV", "PD7333"
Set oSh = CreateObject("WScript.Shell")
oSh.run "oexplore", tsWindowShow, taDontWaitForFinish
set oSh = Nothing
' NOTE: remove the lines above and uncomment the following
' lines to use this with Terminal Server, where the JDE.INI
' is stored for each individual user.
'Set oSh = CreateObject("WScript.Shell")
'UserProfile = oSh.Environment("Process").item("USERPROFILE")
'WriteIni UserProfile & "\windows\jde.ini", "SIGNON", "LASTENV", "PD7333"
'oSh.run "oexplore", tsWindowShow, taDontWaitForFinish
'set oSh = Nothing