#118957 - 2004-05-04 11:31 AM
Proper way to end a script
|
Collin
Fresh Scripter
Registered: 2002-01-18
Posts: 21
Loc: Amsterdam - NL
|
Hi all, I have a question about finishing a script properly. I am using my login script at home with Win XP and I have no problem whatsoever with it, but I recently started a job who are still using Win98 clients. On all Win98 PC's when i run the script 2 or 3 times without booting I get all sorts of errors. (BSOD, out of system resources, Fatal errors, that sorta stuff). I had a feeling it had something to do with the script not freeing up resources after running, somehow.
Then I remembered some code I saw a long time ago who cleared the variables at the end of the script, like: $Variable1="" $Variable2=""
That instantly solved my problem, by clearing about 100 vars at the end of the script.
I can't find any topic addressing how to properly end a script. Is it the poor memory management of Win98 who is causing the reservation of memory? Are there any best practices on how to 'end' a script?
_________________________
Ruud is my hero
|
|
Top
|
|
|
|
#118958 - 2004-05-04 11:59 AM
Re: Proper way to end a script
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
I never did a 9x logon script, but remember something about a cookie ... here :
Quote:
Cookie1
Action: Creates a cookie, or semaphore-file, that the Windows 9x Logon API uses to determine whether the script has finished running. This command is only useful when KiXtart is being used to emulate Lmscript.exe. For more information, see “Lmscript Emulation,” earlier in this document. Syntax: COOKIE1
and here the part about lmscript emulation :
Quote:
Running KiXtart with Lmscript Emulation Normally, when a user logs on to a LAN Manager or Windows NT domain from Windows 9x, the Windows API responsible for processing the logon request starts a program called Lmscript to run the logon script. The sole responsibility of Lmscript is to inform the logon API when the logon script has finished by creating a semaphore file (also called a cookie).
Unfortunately, the original Lmscript.exe takes up a lot of memory. To solve this issue, KiXtart can be used as a replacement for Lmscript.exe. This not only saves memory, but also means that the Kix32.exe does not have to be read from the network during the logon sequence, as it is automatically run from the local hard disk. The benefit of this is minimal in a normal LAN environment, but can be substantial in a WAN or RAS environment. To enable Lmscript emulation on computers running Windows 9x 1. In the Windows\System folder, rename the original Lmscript.exe. 2. Rename Kix32.exe to Lmscript.exe and then copy it to the Windows\System folder. 3. In User Manager, in the Logon Script Name box, specify a KiXtart script as the logon script for the user (for example, Kixtart). 4. At the end of the specified KiX script, add a line containing the COOKIE1 command to create the semaphore file.
· Note Users who do not use Lmscript emulation (such as users running Windows 9x on the LAN or users running Windows NT Workstation) cannot run the logon script unless there is also a batch file with the same name as the KiX script specified for the user.
The following example illustrates the use of such a batch file for a user named Fred.
User name Fred Logon script Script1 Contents of the Scripts directory on the logon server Script1.batScript1.kixKix32.exe Contents of Script1.bat @ECHO OFF%0\..\Kix32 Script1EXIT 0 Contents of Script1.kix CLSBIG? "Hi, @USERID"SLEEP 10COOKIE1EXIT 0
If Fred uses a computer running Windows NT to log onto the network, or if he uses a computer running Windows 9x with the original Lmscript.exe, Script1.bat starts and then in turn starts Kix32.exe with Script1.kix as the logon script. If he uses a computer running Windows 9x and logs on with Kix32.exe renamed as Lmscript.exe, Script1.kix runs automatically.
not sure if this helps
_________________________
|
|
Top
|
|
|
|
#118961 - 2004-05-04 05:00 PM
Re: Proper way to end a script
|
Collin
Fresh Scripter
Registered: 2002-01-18
Posts: 21
Loc: Amsterdam - NL
|
Quote:
I never had a problem with Win9x logins, of course each script is fairly unique.
When KiXtart exits it should release memory and clean up automatically, with the exception of COM automation objects which may hang around - you should explicitly clear/close these if you have any.
My guess is that it is a timing issue, and your extra code to clear down the variables is delaying the script long enough so that the problem does not appear.
I've seen similar problems with scripts that run asynchronously, or mess about with the Z: drive mapping.
I run all logon scripts synchronously, so the redirection of shell folders (my docs, favorites, etc) is in effect before the profile is loaded. I have a safety check that the Z: drive cannot be mapped, so that's not it as well..
I do run some WMI code (WMIQuery UDF) though, does WMI get info trough COM scripting (or am I way off :P ) perhaps? And do you mean I need to empty all vars used in the WMIQuery function or how can I nicely close up COM scripting?
_________________________
Ruud is my hero
|
|
Top
|
|
|
|
#118963 - 2004-05-06 05:52 AM
Re: Proper way to end a script
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I have never had any problem with Win9x computer and my scripts. I end mine with the last carraige return after typing the last line...
Maybe you could trash the Win9x? Sorry, this isn't very helpful.
|
|
Top
|
|
|
|
#118965 - 2004-05-11 10:12 AM
Re: Proper way to end a script
|
Collin
Fresh Scripter
Registered: 2002-01-18
Posts: 21
Loc: Amsterdam - NL
|
Late reaction, didnt have time to check, but here's the code (don't know if it is any help :P ), You cannot run it just like that, it uses some ini files containing all the settings.
Code:
;============================================================
;== Login script written by Collin van Raam (cfvr atsign dds.nl) ==
;============================================================
;== Build 300
;== Modify date 9:43 29-4-2004
;== Modified by Collin van Raam
;============================================================
GOSUB Preparation
GOSUB Functions
GOSUB HomeDrive
GOSUB Printers
GOSUB CustomScripts
GOSUB ShellFolders
GOSUB Word
GOSUB Outlook
GOSUB InternetExplorer
GOSUB Inventory
GOSUB TimeSync
GOSUB ClientFiles
GOSUB Updates
GOSUB LoginLog
GOSUB FinishLogin
GOSUB ClearVars
SLEEP 1
EXIT 0
============================================================
== Preparation
============================================================
:Preparation
$Dummy=SetConsole("Hide")
IF INGROUP("Domain Admins")
BREAK ON
ENDIF
$ScriptDir=@SCRIPTDIR
$Language = ReadProfileString("$ScriptDir\Custom\LoginScript.ini","LoginScript","ScriptLanguage")
If Exist('$ScriptDir\Data\Languages\$Language.kix')
Call '$ScriptDir\Data\Languages\$Language.kix'
Else
$TextLabel1 = "Welcome back"
$TextLabel2 = "User name"
$TextLabel3 = "Computer name"
$TextLabel4 = "Operating system"
$TextLabel5 = "Domain name"
$TextLabel6 = "Logon server"
$TextLabel7 = "The update below is ready to be installed. Would you like to install this update now?"
$TextLabel8 = "The update below is now being installed.."
$TextLabel9 = "Mapping home drive..."
$TextLabel10 = "Mapping network printers..."
$TextLabel11 = "Executing group scripts..."
$TextLabel12 = "Executing personal script..."
$TextLabel13 = "Setting user shell folders..."
$TextLabel14 = "Setting Microsoft Word file locations..."
$TextLabel15 = "Configuring Outlook"
$TextLabel16 = "Gathering machine inventory..."
$TextLabel17 = "Synchronizing system time..."
EndIf
IF EXIST( "%WINDIR%\Kixforms.dll" )
IF COMPAREFILETIMES ("$ScriptDir\Data\KixTart\KixForms.dll", "%WINDIR%\Kixforms.dll" ) = 1 OR COMPAREFILETIMES ("$ScriptDir\Data\KixTart\KixForms.dll", "%WINDIR%\Kixforms.dll" ) = -1
COPY "$ScriptDir\Data\KixTart\KixForms.dll" "%WINDIR%\Kixforms.dll"
EndIF
ELSE
COPY "$ScriptDir\Data\KixTart\KixForms.dll" "%WINDIR%\Kixforms.dll"
ENDIF
Select
Case Exist("%Windir%\system\regsvr32.exe")
cd "%Windir%\System"
SHELL "%COMSPEC% /C regsvr32.exe %WINDIR%\Kixforms.dll /s"
Case Exist("%Windir%\system32\regsvr32.exe")
SHELL "%COMSPEC% /C regsvr32.exe %WINDIR%\Kixforms.dll /s"
Case 1
$Dummy=MessageBox("Regsrv32.exe not found, script is exiting!","Critical")
EndSelect
IF @INWIN = 1
$Dummy = WRITEVALUE( "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "RunLogonScriptSync", "1", "REG_DWORD" )
ENDIF
$SkipServer = 0
IF READPROFILESTRING( "$ScriptDir\custom\Servers.ini" , "Servers" , @WKSTA ) <> ""
$SkipServer = 1
ENDIF
IF OPEN(3, "$ScriptDir\Custom\LoginScript.ini") = 0
$x = READLINE(3)
WHILE INSTR( $x , "END_OF_FILE" ) = 0
IF $x <> ""
IF INSTR( $x , "=" )
IF SUBSTR( $x , 1 , 1 ) <> ";" AND SUBSTR( $x , 1 , 3 ) <> "REM"
$Dummy = EXECUTE( '$' + $x )
ENDIF
ENDIF
ENDIF
$x = READLINE(3)
LOOP
ELSE
CLS
? "Error opening '$ScriptDir\Custom\LoginScript.ini' - Login script aborted!"
BEEP
SLEEP 5
EXIT
ENDIF
$Dummy = CLOSE(3)
If Exist('$ScriptDir\Data\Languages\$ScriptLanguage.kix')
Call '$ScriptDir\Data\Languages\$ScriptLanguage.kix'
Else
Call '$ScriptDir\Data\Languages\English.kix'
EndIf
IF INSTR(@fullname,",")
$y = INSTR(@fullname,",")
$FullName = SUBSTR(@fullname,$y+2,LEN(@fullname)-$y-1) + " " + SUBSTR(@fullname,1,$y-1)
ELSE
$FullName = @fullname
ENDIF
$CpuType = "@CPU"
$IEVersion = "Internet Explorer " + LEFT( READVALUE( "HKLM\Software\Microsoft\Internet Explorer" , "Version" ) , 3 )
$IPaddress = LTRIM(SUBSTR(@IPADDRESS0 , 1 , 3)) + "." + LTRIM(SUBSTR(@IPADDRESS0 , 5 , 3)) + "." + LTRIM(SUBSTR(@IPADDRESS0 , 9 , 3)) + "." + LTRIM(SUBSTR(@IPADDRESS0 , 13 , 3))
$HWAddress = SUBSTR(@ADDRESS , 1 , 2) + "-" + SUBSTR(@ADDRESS , 3 , 2) + "-" + SUBSTR(@ADDRESS , 5 , 2) + "-" + SUBSTR(@ADDRESS , 7 , 2) + "-" + SUBSTR(@ADDRESS , 9 , 2) + "-" + SUBSTR(@ADDRESS , 11 , 2)
$Lserver = SUBSTR( @LSERVER , 3 , LEN( @LSERVER ) - 2 )
$Blue = 50,111,166
$BlueGrey = 123,148,177
$Grey = 198,195,198
$Green = 0,180,0
$Red = 180,0,0
$EasyKix = CreateObject("Kixtart.Form")
$Easykix.BackColor = $Grey
$EasyKix.Width = 508
$EasyKix.Height = 430
$EasyKix.Center
$Easykix.FillStyle=1
$Easykix.Borderstyle=0
$Easykix.Caption = $LoginScriptTitle
$Easykix.FillColor=$Blue
$Rectangle1=$Easykix.Rectangle(10,30,488,390)
$Easykix.FillColor=$Grey
$Rectangle2=$Easykix.Rectangle(25,70,458,140)
$Rectangle3=$Easykix.Rectangle(25,225,458,185)
$lblWelcomeTxt = $EasyKix.Label("$TextLabel1 $FullName",30,40,448,25)
$lblWelcomeTxt.BackColor=$Blue
$lblWelcomeTxt.FontBold=1
$lblWelcomeTxt.Center = 1
$lblWelcomeTxt.FontSize=14
$lblWelcomeTxt.Alignment=2
$lblWelcomeTxt.ForeColor=$Grey
$lblTitle = $Easykix.Label("$LoginScriptTitle",3,3,494,24)
$lblTitle.Center = 1
$lblTitle.FontSize = 13
$lblTitle.Alignment = 2
$lblName = $Easykix.Label("$TextLabel2:",50,90,120,20)
$lblComputerName = $Easykix.Label("$TextLabel3:",50,110,120,20)
$lblOperatingSystem = $Easykix.Label("$TextLabel4:",50,130,120,20)
$lblLogonDomain = $Easykix.Label("$TextLabel5:",50,150,120,20)
$lblLogonServer = $Easykix.Label("$TextLabel6:",50,170,120,20)
$lblName2 = $Easykix.Label("@USERID (@FULLNAME)",170,90,310,20)
$lblComputerName2 = $Easykix.Label("@WKSTA",170,110,310,20)
$lblOperatingSystem2 = $Easykix.Label("@PRODUCTTYPE @CSD",170,130,310,20)
$lblLogonDomain2 = $Easykix.Label("@DOMAIN",170,150,310,20)
$lblLogonServer2 = $Easykix.Label("@LSERVER",170,170,310,20)
$StatusTop = 240
$StatusCount = 0
$prgProgressBar = $EasyKix.ProgressBar("",35,380,436,20)
$prgProgressBar.max = 6
$prgProgressBar.BackColor = $Grey
$prgProgressBar.ForeColor = $Blue
$prgProgressBar.BorderStyle = 5
$prgProgressBar.Style = 1
$EasyKix.Show
If $DeleteNetworkPrinters = "YES"
$Printer = ENUMKEY( "HKCU\Printers\Connections" , 0 )
WHILE $Printer <> ""
$Dummy = DELKEY( "HKCU\Printers\Connections\$Printer" )
$Printer = ENUMKEY( "HKCU\Printers\Connections" , 0 )
LOOP
EndIf
$Dummy = OPEN(1, "%WINDIR%\LoginScript.ini" , 5)
$Dummy = CLOSE(1)
$LoginScrIni = "%WINDIR%\LoginScript.ini"
$Dummy = WRITEPROFILESTRING("$LoginScrIni" , '@USERID' , 'LastLogon' , '@TIME on @MDAYNO @MONTH @YEAR')
$Dummy = WRITEPROFILESTRING("$LoginScrIni" , '@USERID' , 'LogonServer' , '@LSERVER')
RETURN
============================================================
== Functions
============================================================
:Functions
FUNCTION MAPDRIVE( $Letter , $Share , optional $Persistent )
IF %UserProfile% = ""
$Persistent = ""
EndIf
IF RIGHT( $Letter , 1 ) <> ":" AND $Letter <> ":"
$Letter = $Letter + ":"
ENDIF
SELECT
CASE INSTR( $Letter , "Z" )
LOGERROR( "Illegal drive letter 'Z:' configured for the share '$Share'. Choose another letter." )
CASE LEN( $Letter ) <> 2
LOGERROR( "Invalid drive letter '$Letter' configured for the share '$Share'." )
CASE 1
USE $Letter /DELETE /PERSISTENT
IF EXIST( "$Share" )
IF $Persistent <> ""
USE $Letter $Share /PERSISTENT
IF @ERROR <> 0
LOGERROR( "Error mapping '$Letter' to share '$Share' (persistent mapping)." )
ENDIF
ELSE
USE $Letter $Share
IF @ERROR <> 0
LOGERROR( "Error mapping '$Letter' to share '$Share'." )
ENDIF
ENDIF
ELSE
LOGERROR( "Share '$Share' cannot be found on the network." )
ENDIF
ENDSELECT
ENDFUNCTION
;-------------------------------------------------------------------
FUNCTION MAPPRINTER( $PrinterShare , optional $Default )
SELECT
CASE @INWIN <> 1
CASE Instr( $PrinterShare , "\\@Wksta\" )
CASE $SkipServer = 1 AND READPROFILESTRING( "$ScriptDir\custom\Servers.ini" , "ServerRoutines" , "Printers" ) <> "YES"
CASE LEFT( $PrinterShare , 2 ) <> "\\"
LOGERROR( "Invalid printer share '$PrinterShare' configured. Share must begin with 2 backslashes." )
CASE 1
IF ADDPRINTERCONNECTION( $PrinterShare ) <> 0
LOGERROR( "Error mapping printer '$PrinterShare'." )
ENDIF
IF $Default <> ""
IF SETDEFAULTPRINTER( $PrinterShare ) <> 0
LOGERROR( "Error making '$PrinterShare' the default printer." )
ENDIF
ENDIF
ENDSELECT
ENDFUNCTION
;-------------------------------------------------------------------
FUNCTION SHOWSTATUS( $Status )
$ErrorLevel = 0
$StatusCount = $StatusCount + 1
$Dummy = Execute("$$Label"+$StatusCount+"=$$EasyKix.Label($$Status,140,$$StatusTop,240,17)")
$Dummy = Execute("$$Label"+$StatusCount+".BackColor=$$Grey")
$Dummy = Execute("$$Label"+$StatusCount+".BorderStyle=0")
$Dummy = Execute("$$LabelResult"+$StatusCount+"=$$EasyKix.Label('',90,$$StatusTop,22,16)")
$Dummy = Execute("$$LabelResult"+$StatusCount+".BackColor=$$Grey")
$Dummy = Execute("$$LabelResult"+$StatusCount+".BorderStyle=1")
ENDFUNCTION
;-------------------------------------------------------------------
FUNCTION SHOWRESULT()
IF $ErrorLevel <> 1
$Dummy = Execute("$$LabelResult"+$StatusCount+".BackColor=$$Green")
$Dummy = Execute("$$LabelResult"+$StatusCount+".Text=' OK'")
ELSE
$Dummy = Execute("$$LabelResult"+$StatusCount+".BackColor=$$Red")
$Dummy = Execute("$$LabelResult"+$StatusCount+".Text=' X'")
ENDIF
$StatusTop = $StatusTop + 15
$prgProgressBar.Value = $prgProgressBar.Value + 1
$ErrorLevel = 0
ENDFUNCTION
;-------------------------------------------------------------------
FUNCTION LOGERROR( $ErrorMessage )
$ErrorLevel = 1
$KixErrorCode = READPROFILESTRING( "$ScriptDir\data\Kixtart\kixerrors.ini" , "ErrorCodes" , @ERROR )
IF $OpenScript <> ""
$FileError = "in file $OpenScript "
ELSE
$FileError = ""
ENDIF
IF $LoginLogging = "ENABLED"
IF EXIST( "$LoginLogPath\Errors" ) = 0
MD "$LoginLogPath\Errors"
ENDIF
$arrErrorFiles = "%WINDIR%\LoginErrors.txt" , "$LoginLogPath\Errors\@USERID.txt"
FOR EACH $Errorfile IN $arrErrorFiles
IF OPEN( 4 , "$Errorfile" , 5 ) = 0
IF $ErrorsLogged <> 1
$Dummy = WRITELINE( 4 , "-------------------------------------------------------------------------------" + @CRLF )
ENDIF
$Dummy = WRITELINE( 4 , "@TIME @MDAYNO-@MONTHNO-@YEAR > @USERID@@@WKSTA > $KixErrorCode $FileError> $ErrorMessage" + @CRLF )
$Dummy = CLOSE( 4 )
ENDIF
NEXT
ENDIF
$ErrorsLogged = 1
ENDFUNCTION
;-------------------------------------------------------------------
FUNCTION CALLSCRIPT( $script )
$OpenScript = "$script"
CALL "$script"
$OpenScript = ""
ENDFUNCTION
;-------------------------------------------------------------------
FUNCTION WMIQUERY($what,$where,)
dim $strQuery, $objEnumerator, $value
$strQuery = "Select $what From $where"
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//@WKSTA")
$objEnumerator = $SystemSet.ExecQuery($strQuery)
For Each $objInstance in $objEnumerator
If @Error = 0 and $objInstance <> ""
$=execute("$$value = $$objInstance.$what")
$WMIQuery="$value"+"|"+"$WMIQuery"
EndIf
Next
$WMIQuery = left($WMIQuery,len($WMIQuery)-1)
ENDFUNCTION
;-------------------------------------------------------------------
FUNCTION GetFileAge( $File )
If Exist($File)
$FileYear = SUBSTR( GETFILETIME( $File ) , 1 , 4 )
$FileMonth = SUBSTR( GETFILETIME( $File ) , 6 , 2 )
$FileDay = SUBSTR( GETFILETIME( $File ) , 9 , 2 )
$MonthDays = 0,0,31,59,90,120,151,181,212,243,273,304,334
$=Execute("$FileYearDay = $MonthDays["+$FileMonth+"]+$FileDay")
$=Execute("$YearDay = $MonthDays["+@MonthNo+"]+"+@MDayNo)
$GetFileAge = ((VAL(@YEAR)*365)+$YearDay) - ((VAL($FileYear)*365)+$FileYearDay)
Else
$GetFileAge = -1
EndIf
ENDFUNCTION
;-------------------------------------------------------------------
FUNCTION RUNUPDATE( $UpdateCommandLine )
RUN $UpdateCommandLine
$Dummy = WRITEPROFILESTRING( $LoginScrINI , "Updates" , $UpdateName , "INSTALLED" )
IF $LoginLogging = "ENABLED"
IF EXIST( "$LoginLogPath\Updates" ) = 0
MD "$LoginLogPath\Updates"
IF @ERROR <> "0"
LOGERROR( "Error creating updates log folder '$LoginLogPath\Updates'. Create the folder manually or check folder permissions." )
ENDIF
ENDIF
IF EXIST( "$LoginLogPath\Updates" )
IF OPEN( 5 , "$LoginLogPath\Updates\$UpdateName.txt" , 5 ) = 0
$Dummy = WRITELINE( 5 , "@WKSTA >> Update installed by @USERID ($FullName) at @TIME on @MDAYNO @MONTH @YEAR" + @CRLF )
ENDIF
$Dummy = CLOSE( 5 )
ENDIF
ENDIF
ENDFUNCTION
;-------------------------------------------------------------------
FUNCTION INSTALLPATCH( $IniFileTitle )
$Prompt = "NO"
$Silent = "NO"
IF $PCounter > 999
ELSE
$PCounter = 1
ENDIF
WHILE $PCounter < 10
IF READPROFILESTRING( "$ScriptDir\custom\Updates.ini" , $IniFileTitle , $PCounter ) <> ""
$Array = SPLIT( READPROFILESTRING( "$ScriptDir\custom\Updates.ini" , $IniFileTitle , $PCounter ) , "|" , 5 )
$UpdateName = $Array[0]
IF READPROFILESTRING( $LoginScrINI , "Updates" , $UpdateName ) <> "INSTALLED"
FOR EACH $Element IN $Array
SELECT
CASE $SkipServer = 1
$Prompt = "YES"
CASE $Element = "SILENT"
$Silent = "YES"
CASE $Element = "PROMPT"
$Prompt = "YES"
ENDSELECT
NEXT
IF $Prompt = "YES"
$Result = MESSAGEBOX( "$TextLabel7 @CRLF @CRLF * $Updatename" , "Update" , 4132 )
IF $Result = 6
RUNUPDATE( $Array[1] )
$PCounter = 1000
ENDIF
ELSE
RUNUPDATE( $Array[1] )
$PCounter = 1000
IF $Silent <> "YES"
$Dummy = MESSAGEBOX( "$TextLabel8 @CRLF @CRLF * $UpdateName" , "Update" , 4096 , 20 )
ENDIF
ENDIF
ENDIF
ENDIF
$PCounter = $PCounter + 1
LOOP
ENDFUNCTION
;-------------------------------------------------------------------
FUNCTION SETSHELLFOLDER( $ShellFolder , $FolderLocation )
IF $FolderLocation <> ""
IF EXIST( "$FolderLocation" ) = 0
MD "$FolderLocation"
IF EXIST( "$FolderLocation" ) = 0
LOGERROR( "The '$ShellFolder' folder '$FolderLocation' does not exist and could not be created. Please create the folder manually." )
ENDIF
ENDIF
IF EXIST( "$FolderLocation" )
$Dummy = WRITEVALUE( "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" , "$ShellFolder" , "$FolderLocation" , "REG_SZ")
IF @ERROR <> 0
LOGERROR( "There was an error writing the '$ShellFolder' folder '$FavoritesDir' to the registry" )
ENDIF
ENDIF
ENDIF
ENDFUNCTION
RETURN
============================================================
== HomeDrive
============================================================
:HomeDrive
SELECT
CASE READPROFILESTRING( "$ScriptDir\custom\Servers.ini" , "ServerRoutines" , "HomeDrive" ) <> "YES" AND $SkipServer = 1
RETURN
CASE $HomeDrivePath = "" OR $HomeDriveLetter = ""
RETURN
CASE 1
IF RIGHT( $HomeDrivePath , 1 ) = "\"
$HomeDrivePath = SUBSTR( $HomeDrivePath , 1 , LEN( $HomeDrivePath ) -1 )
ENDIF
SHOWSTATUS( $TextLabel9 )
MAPDRIVE( $HomeDriveLetter , $HomeDrivePath , "Persistent" )
SHOWRESULT()
ENDSELECT
RETURN
============================================================
== Printers
============================================================
:Printers
SELECT
CASE @INWIN <> 1
RETURN
CASE $SkipServer = 1 AND READPROFILESTRING( "$ScriptDir\custom\Servers.ini" , "ServerRoutines" , "Printers" ) <> "YES"
RETURN
ENDSELECT
$Counter = 0
$Group = ENUMGROUP($Counter)
WHILE $Group <> ""
$Groupname = SUBSTR( $Group , INSTR( $Group , "\" ) + 1 , LEN( $Group ) - INSTR( $Group , "\" ) )
IF READPROFILESTRING( "$ScriptDir\custom\Printers.ini" , "PrinterShares" , $Groupname ) <> ""
$PrinterShare = READPROFILESTRING( "$ScriptDir\custom\Printers.ini" , "PrinterShares" , $Groupname )
IF INGROUP ( $Groupname + "_DEFAULT" )
IF $FoundPrinter <> "YES"
SHOWSTATUS( $TextLabel10 )
ENDIF
$FoundPrinter = "YES"
MAPPRINTER( $PrinterShare , DEFAULT )
ELSE
IF $FoundPrinter <> "YES"
SHOWSTATUS( $TextLabel10 )
ENDIF
$FoundPrinter = "YES"
MAPPRINTER( $PrinterShare )
ENDIF
ENDIF
$Counter = $Counter + 1
$Group = ENUMGROUP($Counter)
LOOP
IF $FoundPrinter = "YES"
SHOWRESULT()
ENDIF
RETURN
============================================================
== CustomScripts
============================================================
:CustomScripts
$Counter = 0
$Group = ENUMGROUP($Counter)
WHILE $Group <> ""
$Groupname = SUBSTR( $Group , INSTR( $Group , "\" ) + 1 , LEN( $Group ) - INSTR( $Group , "\" ) )
IF EXIST( "$ScriptDir\Custom\GroupScripts\" + $Groupname + ".kix" )
IF $FoundGroupScript <> "YES"
SHOWSTATUS( $TextLabel11 )
ENDIF
$FoundGroupScript = "YES"
CALLSCRIPT( "$ScriptDir\Custom\GroupScripts\" + $Groupname + ".kix" )
ENDIF
$Counter = $Counter + 1
$Group = ENUMGROUP($Counter)
LOOP
IF $FoundGroupScript = "YES"
SHOWRESULT()
ENDIF
;---------------------------------------------------------------------
IF EXIST( "$ScriptDir\Custom\UserScripts\@USERID.kix" )
SHOWSTATUS( $TextLabel12 )
CALLSCRIPT( "$ScriptDir\Custom\UserScripts\@USERID.kix" )
SHOWRESULT()
ENDIF
RETURN
============================================================
== ShellFolders
============================================================
:ShellFolders
SELECT
CASE READPROFILESTRING( "$ScriptDir\custom\LaptopUsers.ini" , "Laptop users" , @USERID ) <> ""
RETURN
CASE $DefaultOfficePath = "" AND $UserTemplates = "" AND $MyDocumentsDir = "" AND $FavoritesDir = ""
RETURN
CASE READPROFILESTRING( "$ScriptDir\custom\Servers.ini" , "ServerRoutines" , "ShellFolders" ) <> "YES" AND $SkipServer = 1
RETURN
CASE 1
SHOWSTATUS( $TextLabel13 )
$OfficeKey = "HKCU\Software\Microsoft\Office"
ENDSELECT
SETSHELLFOLDER( "Personal" , $MyDocumentsDir )
SETSHELLFOLDER( "Favorites" , $FavoritesDir )
SETSHELLFOLDER( "Desktop" , $DesktopDir )
SETSHELLFOLDER( "Recent" , $RecentDir )
SETSHELLFOLDER( "AppData" , $ApplicationData )
SETSHELLFOLDER( "Cache" , $TempInternetFiles )
SETSHELLFOLDER( "Cookies" , $Cookies )
SETSHELLFOLDER( "History" , $History )
IF INSTR( $MyPicturesFolder , "\" )
SETSHELLFOLDER( "My Pictures" , $MyPicturesFolder )
ELSE
IF $MyDocumentsDir <> ""
$MyPicturesFolder = "$MyDocumentsDir\$MyPicturesFolder"
SETSHELLFOLDER( "My Pictures" , $MyPicturesFolder )
ELSE
LOGERROR( "Illegal path '$MyPicturesFolder' set for the 'My Pictures' folder. Set the 'MyDocumentsDir' variable in the LoginScript.ini file." )
ENDIF
ENDIF
SHOWRESULT()
RETURN
============================================================
== Office 97/2000/XP/2003
============================================================
:Word
SELECT
CASE $UserTemplates = "" AND $WorkgroupTemplates = "" AND $WordStartUpPath = ""
RETURN
CASE 1
SHOWSTATUS( $TextLabel14 )
$OfficeKey = "HKCU\Software\Microsoft\Office"
ENDSELECT
IF $UserTemplates <> ""
IF EXIST( "$UserTemplates" ) = 0
MD "$UserTemplates"
IF @ERROR <> 0
LOGERROR( "The 'Microsoft Word User Templates' folder '$UserTemplates' does not exist and could not be created. Please create the folder manually. No changes were made to the location of the 'Templates' folder." )
ENDIF
ENDIF
IF EXIST( "$UserTemplates" )
$Dummy = Writevalue("$OfficeKey\8.0\Common\FileNew\LocalTemplates" , "" , "$UserTemplates" , "REG_SZ")
$Dummy = Writevalue("$OfficeKey\9.0\Common\General" , "UserTemplates" , "$UserTemplates" , "REG_EXPAND_SZ")
$Dummy = Writevalue("$OfficeKey\10.0\Common\General" , "UserTemplates" , "$UserTemplates" , "REG_EXPAND_SZ")
$Dummy = Writevalue("$OfficeKey\11.0\Common\General" , "UserTemplates" , "$UserTemplates" , "REG_EXPAND_SZ")
ENDIF
ENDIF
IF $WorkgroupTemplates <> ""
IF EXIST( "$WorkgroupTemplates" ) = 0
MD "$WorkgroupTemplates"
IF @ERROR <> 0
LOGERROR( "The 'Microsoft Word Workgroup Templates' folder '$WorkgroupTemplates' does not exist and could not be created. Please create the folder manually. No changes were made to the location of the 'Templates' folder." )
ENDIF
ENDIF
IF EXIST( "$WorkgroupTemplates" )
$Dummy = Writevalue("$OfficeKey\8.0\Common\FileNew\SharedTemplates" , "" , "$WorkgroupTemplates" , "REG_SZ")
$Dummy = Writevalue("$OfficeKey\9.0\Common\General" , "SharedTemplates" , "$WorkgroupTemplates" , "REG_EXPAND_SZ")
$Dummy = Writevalue("$OfficeKey\10.0\Common\General" , "SharedTemplates" , "$WorkgroupTemplates" , "REG_EXPAND_SZ")
$Dummy = Writevalue("$OfficeKey\11.0\Common\General" , "SharedTemplates" , "$WorkgroupTemplates" , "REG_EXPAND_SZ")
ENDIF
ENDIF
IF $WordStartUpPath <> ""
IF EXIST( "$WordStartUpPath" ) = 0
MD "$WordStartUpPath"
IF @ERROR <> 0
LOGERROR( "The 'Microsoft Word startup' folder '$DefaultOfficePath' does not exist and could not be created. Please create the folder manually. No changes were made to the location of the 'Word startup' folder." )
ENDIF
ENDIF
IF EXIST( "$WordStartUpPath" )
$Dummy = Writevalue("$OfficeKey\8.0\Word\Options" , "STARTUP-PATH" , "$WordStartUpPath" , "REG_SZ")
$Dummy = Writevalue("$OfficeKey\9.0\Word\Options" , "STARTUP-PATH" , "$WordStartUpPath" , "REG_EXPAND_SZ")
$Dummy = Writevalue("$OfficeKey\10.0\Word\Options" , "STARTUP-PATH" , "$WordStartUpPath" , "REG_EXPAND_SZ")
$Dummy = Writevalue("$OfficeKey\11.0\Word\Options" , "STARTUP-PATH" , "$WordStartUpPath" , "REG_EXPAND_SZ")
ENDIF
ENDIF
SHOWRESULT()
RETURN
============================================================
== Outlook
============================================================
:Outlook
Select
Case KeyExist("HKCU\Software\Microsoft\Windows Messaging Subsystem\Profiles\@USERID")
$Dummy = Writevalue("HKCU\Software\Microsoft\Windows Messaging Subsystem\Profiles" , "DefaultProfile" , "@USERID" , "REG_SZ")
Return
Case KeyExist("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\@USERID")
$Dummy = Writevalue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" , "DefaultProfile" , "@USERID" , "REG_SZ")
Return
Case $ExchangeServer = ""
Return
Case $ConfigureOutlook <> "YES"
Return
Case Exist(ReadValue("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE",""))
$OutlookVersionNr=GetFileVersion(ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE",""))
$OutlookPath=ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE","")
Case 1
Return
EndSelect
Select
Case Left($OutlookVersionNr,1)=8
$OutlookVersion=97
Case Left($OutlookVersionNr,1)=9
$OutlookVersion=2000
Case Left($OutlookVersionNr,2)=10
$OutlookVersion=XP
Case Left($OutlookVersionNr,2)=11
$OutlookVersion=2003
EndSelect
ShowStatus("$TextLabel15 $OutlookVersion...")
copy "$ScriptDir\data\Outlook\Outlook.prf" "%TEMP%\@UserID.prf"
copy "$ScriptDir\data\Outlook\Fixprf.exe" %TEMP%
copy "$ScriptDir\data\Outlook\Newprof.exe" %TEMP%
If $ResolveMailboxVar <> ""
SHELL '%COMSPEC% /C %TEMP%\fixprf %TEMP%\@UserID.prf "$ResolveMailboxVar" @USERID $ExchangeServer'
Else
SHELL '%COMSPEC% /C %TEMP%\fixprf %TEMP%\@UserID.prf @USERID @USERID $ExchangeServer'
EndIf
Select
Case $OutlookVersion=97
SHELL '%COMSPEC% /C %TEMP%\newprof -p %TEMP%\@UserID.prf -x'
If @error<>0
Logerror("Error configuring Outlook")
EndIf
Case $OutlookVersion=2000
SHELL '%COMSPEC% /C %TEMP%\newprof -p %TEMP%\@UserID.prf -x'
If @error<>0
Logerror("Error configuring Outlook")
EndIf
Case $OutlookVersion=XP
Run '$OutlookPath /importprf %TEMP%\@UserId.prf'
If @error<>0
Logerror("Error configuring Outlook")
EndIf
Case $OutlookVersion=2003
Run '$OutlookPath /importprf %TEMP%\@UserId.prf'
If @error<>0
Logerror("Error configuring Outlook")
EndIf
EndSelect
Sleep 1
del "%TEMP%\Fixprf.exe"
del "%TEMP%\Newprof.exe"
del "%TEMP%\@UserId.prf"
ShowResult()
RETURN
============================================================
== Configuring Internet Explorer
============================================================
:InternetExplorer
If $MandatoryStartupPage <> ""
$Dummy=WriteValue("HKCU\Software\Microsoft\Internet Explorer\Main","Start Page",$MandatoryStartupPage,"REG_SZ")
EndIf
If $ProxyServer <> "" And $ProxyServerPort <> ""
$Dummy=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyEnable","1","REG_DWORD")
$Dummy=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyServer","$ProxyServer:$ProxyServerPort","REG_SZ")
EndIf
If $ProxyBypassString <> ""
$Dummy=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyOverride","$ProxyBypassString","REG_SZ")
EndIf
RETURN
============================================================
== Inventory
============================================================
:Inventory
IF $Inventory <> "ENABLED" OR $LoginLogPath = ""
RETURN
ENDIF
$InvMacAddress = ReadProfileString( "$LoginLogPath\Inventory\@WKSTA.txt" , "tech info" , "hardware address" )
$InvComputerName = ReadProfileString( "$LoginLogPath\Inventory\@WKSTA.txt" , "Last inventory" , "workstation" )
$InventoryAge=GetFileAge("$LoginLogPath\Inventory\@WKSTA.Txt")
SELECT
CASE VAL($InventoryAge) => $MinInventoryAge
SHOWSTATUS( $TextLabel16 )
CASE $HWAddress <> $InvMacAddress
SHOWSTATUS( $TextLabel16 )
CASE @WKSTA <> $InvComputerName
SHOWSTATUS( $TextLabel16 )
CASE 1
RETURN
ENDSELECT
IF EXIST( "$LoginLogPath\Inventory" ) = 0
MD "$LoginLogPath\Inventory"
ENDIF
IF EXIST( "$LoginLogPath\Inventory\@WKSTA.txt" )
DEL "$LoginLogPath\Inventory\@WKSTA.txt"
IF @ERROR <> 0
LOGERROR( "Error deleting inventory file '$LoginLogPath\Inventory\@WKSTA.txt'. Inventory is appended to the file." )
ENDIF
ENDIF
$WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!//@WKSTA")
IF $WMI <> ""
$SystemManufacturer = TRIM(WMIQUERY("Manufacturer","Win32_ComputerSystem"))
$SystemModel = TRIM(WMIQUERY("Model","Win32_ComputerSystem"))
$SerialNumber = WMIQuery("SerialNumber","Win32_BIOS")
$BiosVersion = WMIQuery("SMBIOSBIOSVersion","Win32_BIOS")
$BiosDate = WMIQuery("Version","Win32_BIOS")
$OSSerialNumber = WMIQuery("SerialNumber","Win32_OperatingSystem")
$InstallDateString = WMIQuery("InstallDate","Win32_OperatingSystem")
$InstallDate = SUBSTR($InstallDateString,7,2) + "-" + SUBSTR($InstallDateString,5,2) + "-" + SUBSTR($InstallDateString,1,4) + " at " + SUBSTR($InstallDateString,9,2) + ":" + SUBSTR($InstallDateString,11,2)
$LastBootTimeStr = WMIQuery("LastBootupTime","Win32_OperatingSystem")
$LastBootTime = SUBSTR($LastBootTimeStr,7,2) + "-" + SUBSTR($LastBootTimeStr,5,2) + "-" + SUBSTR($LastBootTimeStr,1,4) + " at " + SUBSTR($LastBootTimeStr,9,2) + ":" + SUBSTR($LastBootTimeStr,11,2)
$RegisteredUser = WMIQuery("RegisteredUser","Win32_OperatingSystem")
$RegisteredOrg = WMIQuery("Organization","Win32_OperatingSystem")
$PhysicalMemory = VAL( WMIQuery("TotalPhysicalMemory","Win32_LogicalMemoryConfiguration") )/1024
$InitPageFileSize = WMIQUERY("InitialSize","Win32_PagefileSetting")
$MaxPageFileSize = WMIQUERY("MaximumSize","Win32_PagefileSetting")
$ProcessorSpeed = WMIQUERY("CurrentClockSpeed","Win32_Processor")
$ProcessorType = WMIQUERY("Name","Win32_Processor")
$VidCard = WMIQUERY("VideoProcessor","Win32_VideoController")
$VidRes = WMIQuery("VideoModeDescription","Win32_VideoController")
$Modem = WMIQUERY("Description","Win32_POTSModem")
$arrDeviceIDs = SPLIT(WMIQuery("DeviceID","Win32_LogicalDisk"),"|",-1)
$arrFreeSpaces = SPLIT(WMIQuery("FreeSpace","Win32_LogicalDisk"),"|",-1)
$ArrVolNames = SPLIT(WMIQuery("volumename","Win32_LogicalDisk"),"|",-1)
$arrDriveTypes = SPLIT(WMIQuery("DriveType","Win32_LogicalDisk"),"|",-1)
$arrTotalSizes = SPLIT(WMIQuery("Size","Win32_LogicalDisk"),"|",-1)
$arrFormats = SPLIT(WMIQuery("FileSystem","Win32_LogicalDisk"),"|",-1)
$arrNetCards = SPLIT(WMIQuery("Description","Win32_NetworkAdapter"),"|",-1)
$arrPrinters = SPLIT(WMIQuery("Name","Win32_printer"),"|",-1)
ENDIF
IF OPEN( 5 , "$LoginLogPath\Inventory\@WKSTA.txt" , 5 ) = 0
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "[Last inventory]" + @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "User ID = @USERID" + @CRLF )
$Dummy = WRITELINE( 5 , "Full name = $FullName" + @CRLF )
$Dummy = WRITELINE( 5 , "Workstation = @WKSTA" + @CRLF )
$Dummy = WRITELINE( 5 , "Time and date = @TIME on @MDAYNO @MONTH @YEAR" + @CRLF )
$Dummy = WRITELINE( 5 , "File location = $LoginLogPath\Inventory\@WKSTA.txt" + @CRLF )
$Dummy = WRITELINE( 5 , @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "[Tech info]" + @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "IP Address = $IPAddress" + @CRLF )
$Dummy = WRITELINE( 5 , "Hardware Address = $HWAddress" + @CRLF )
$Dummy = WRITELINE( 5 , "Operating system = @PRODUCTTYPE @CSD" + @CRLF )
$Dummy = WRITELINE( 5 , "Explorer version = $IEVersion" + @CRLF )
$Dummy = WRITELINE( 5 , "Windows directory = %WINDIR%" + @CRLF )
IF $WMI <> ""
$Dummy = WRITELINE( 5 , "OS Serial Number = $OSSerialNumber" + @CRLF )
$Dummy = WRITELINE( 5 , "Installation date = $InstallDate" + @CRLF )
$Dummy = WRITELINE( 5 , "Last boot time = $LastBootTime" + @CRLF )
$Dummy = WRITELINE( 5 , "Manufacturer = $SystemManufacturer ($SystemModel)" + @CRLF )
$Dummy = WRITELINE( 5 , "Physical memory = $PhysicalMemory MB" + @CRLF )
$Dummy = WRITELINE( 5 , "Page file (min/max) = $InitPageFileSize MB / $MaxPageFileSize MB" + @CRLF )
$Dummy = WRITELINE( 5 , "Processor = $ProcessorSpeed MHz $ProcessorType" + @CRLF )
$Dummy = WRITELINE( 5 , "Video card = $VidCard" + @CRLF )
$Dummy = WRITELINE( 5 , "Video resolution = $VidRes" + @CRLF )
$Dummy = WRITELINE( 5 , "Modem type = $Modem" + @CRLF )
$Dummy = WRITELINE( 5 , "System Serial number = $SerialNumber" + @CRLF )
$Dummy = WRITELINE( 5 , "BIOS Version = $BiosVersion" + @CRLF )
$Dummy = WRITELINE( 5 , "BIOS Date = $BiosDate" + @CRLF )
$Dummy = WRITELINE( 5 , "Registered user = $RegisteredUser" + @CRLF )
$Dummy = WRITELINE( 5 , "Registered org. = $RegisteredOrg" + @CRLF )
$Dummy = WRITELINE( 5 , @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "[Drive information]" + @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "Drive Type Free(MB) Total(MB) Label" + @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Counter = UBound($arrDeviceIDs)
While $Counter => 0
IF $arrDeviceIDs[$Counter] = "A:"
$Counter = $Counter - 1
ELSE
$DrvLetter = $arrDeviceIDs[$Counter]
SELECT
CASE $arrDriveTypes[$Counter] = 0
$DriveType = "Unknown"
CASE $arrDriveTypes[$Counter] = 1
$DriveType = "No Root"
CASE $arrDriveTypes[$Counter] = 2
$DriveType = "Removable"
CASE $arrDriveTypes[$Counter] = 3
$DriveType = "Logical"
CASE $arrDriveTypes[$Counter] = 4
$DriveType = "Network"
CASE $arrDriveTypes[$Counter] = 5
$DriveType = "CD-ROM"
CASE $arrDriveTypes[$Counter] = 6
$DriveType = "RAM Disk"
ENDSELECT
$Format = $arrFormats[$Counter]
$VolName = $ArrVolNames[$Counter]
$FreeSpace = VAL(SUBSTR($arrFreeSpaces[$Counter],1,LEN($arrFreeSpaces[$Counter])-3))/1024
$TotalSize = VAL(SUBSTR($arrTotalSizes[$Counter],1,LEN($arrTotalSizes[$Counter])-3))/1024
$Dummy = WRITELINE( 5 , "$DrvLetter $DriveType $Format $Freespace $TotalSize $VolName" + @CRLF )
$Counter = $Counter - 1
ENDIF
LOOP
$Dummy = WRITELINE( 5 , @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "[Printers]" + @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
FOR EACH $Printer in $arrPrinters
$Dummy = WRITELINE( 5 , "$Printer" + @CRLF )
NEXT
$Dummy = WRITELINE( 5 , @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "[Network cards]" + @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
FOR EACH $Nic IN $arrNetCards
IF INSTR($nic,"minipo") = 0 AND INSTR($nic,"RAS") = 0 AND INSTR($nic,"Parallel") = 0
$Dummy = WRITELINE( 5 , "$Nic" + @CRLF )
ENDIF
NEXT
ELSE
IF $CpuType = ""
$CpuType = "@CPU"
ENDIF
IF @INWIN <> 1
$Processor = "$CpuType"
ELSE
$Processor = "@MHz MHz $CpuType"
ENDIF
$Ram = MemorySize(0)
$Dummy = WRITELINE( 5 , "Processor = $Processor" + @CRLF )
$Dummy = WRITELINE( 5 , "Physical memory = $Ram MB" + @CRLF )
$Dummy = WRITELINE( 5 , @CRLF )
$Dummy = WRITELINE( 5 , "NOTE: Windows Management Instrumentation is not available. To make a complete inventory" + @CRLF )
$Dummy = WRITELINE( 5 , " of this system, download and install WMI from http://www.microsoft.com." + @CRLF )
ENDIF
$Dummy = WRITELINE( 5 , @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "[Office programs]" + @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$arrOfficeProgs=Split("Word,winword.exe|Excel,Excel.exe|Outlook,outlook.exe|Frontpage,frontpg.exe|Access,msaccess.exe|Powerpoint,powerpnt.exe|Project,winproj.exe|Visio,visio32.exe|Publisher,mspub.exe|OneNote,OneNote.exe|InfoPath,InfoPath.exe","|")
For Each $Program In $arrOfficeProgs
$arrProgram=Split($Program,",")
If Exist(ReadValue("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"+$arrProgram[1],""))
$Version=GetFileVersion(ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"+$arrProgram[1],""))
Select
Case Left($Version,1)=8
$NormalVersion=97
Case Left($Version,1)=9
$NormalVersion=2000
Case Left($Version,2)=10
$NormalVersion=XP
Case Left($Version,2)=11
$NormalVersion=2003
EndSelect
$Dummy = WRITELINE( 5 , "Microsoft "+$arrProgram[0]+" "+$NormalVersion+" ("+$Version+")" + @CRLF )
EndIf
Next
$Dummy = WRITELINE( 5 , @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "[Installed software]" + @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Counter = 1
$key = ENUMKEY( "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" , $Counter )
WHILE $key <> ""
IF READVALUE( "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$key" , "DisplayName" ) <> ""
$DispName = READVALUE( "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$key" , "DisplayName" )
IF READVALUE( "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$key" , "DisplayVersion" ) <> ""
$DispVer = READVALUE( "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$key" , "DisplayVersion" )
$Dummy = WRITELINE( 5 , "$DispName $DispVer" + @CRLF )
ELSE
$Dummy = WRITELINE( 5 , "$DispName" + @CRLF )
ENDIF
ENDIF
$Counter = $Counter + 1
$key = ENUMKEY( "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" , $Counter )
LOOP
ELSE
LOGERROR( "Error opening file '$LoginLogPath\Inventory\@WKSTA.txt' for writing inventory." )
ENDIF
$Dummy = CLOSE( 5 )
SHOWRESULT()
RETURN
============================================================
== TimeSync
============================================================
:TimeSync
Select
Case READPROFILESTRING( "$ScriptDir\custom\Servers.ini" , "ServerRoutines" , "TimeSync" ) <> "YES" AND $SkipServer = 1
RETURN
Case $TimeServer = ""
RETURN
ENDSELECT
IF LEFT( $TimeServer , 2 ) <> "\\"
$TimeServer = "\\" + $TimeServer
ENDIF
If $Timeserver <> "\\@Wksta"
SHOWSTATUS( $TextLabel17 )
SETTIME "$TimeServer"
IF @ERROR <> 0
LOGERROR( "Error synchronizing system time with server '$TimeServer'." )
ENDIF
SHOWRESULT()
EndIf
RETURN
============================================================
== ClientFiles
============================================================
:ClientFiles
IF READPROFILESTRING( "$ScriptDir\custom\Servers.ini" , "ServerRoutines" , "ClientFiles" ) <> "YES" AND $SkipServer = 1
RETURN
ENDIF
$ClientFiles = "$ScriptDir\Custom\ClientFiles"
$SysDrive = LEFT( %WINDIR% , 2 ) + "\"
cd %WINDIR%
SELECT
CASE INSTR( @PRODUCTTYPE , "Windows NT" )
$XcopyParams = "/D /E /C /Q /H /R /K"
CASE 1
$XcopyParams = "/D /E /C /Q /H /R /K /Y"
ENDSELECT
IF %WINDIR% <> ""
SHELL '%COMSPEC% /C xcopy "$ClientFiles\WindowsDir\*.*" "%WINDIR%" $XcopyParams > NUL'
SHELL '%COMSPEC% /C xcopy "$ClientFiles\SystemDrive\*.*" "$SysDrive" $XcopyParams > NUL'
ENDIF
IF $HomeDrivePath <> "" AND EXIST( "$HomeDrivePath" ) = 1
SHELL '%COMSPEC% /C xcopy "$ClientFiles\HomeDrive\*.*" "$HomeDrivePath" $XcopyParams > NUL'
ENDIF
IF %USERPROFILE% <> ""
SHELL '%COMSPEC% /C xcopy "$ClientFiles\UserProfile\*.*" "%USERPROFILE%" $XcopyParams > NUL'
ENDIF
$Dummy = SETTITLE( $LoginScriptTitle )
RETURN
============================================================
== Updates
============================================================
:Updates
IF READPROFILESTRING( "$ScriptDir\custom\Servers.ini" , "ServerRoutines" , "Updates" ) <> "YES" AND $SkipServer = 1
RETURN
ENDIF
IF $SkipServer <> 1
INSTALLPATCH( "ALL" )
INSTALLPATCH( $IEVersion )
ENDIF
INSTALLPATCH( @PRODUCTTYPE )
RETURN
============================================================
== LoginLog
============================================================
:LoginLog
IF $LoginLogPath = "" OR $LoginLogging <> "ENABLED"
RETURN
ENDIF
IF EXIST( $LoginLogPath + "\Users") = 0
MD $LoginLogPath + "\Users"
ENDIF
IF EXIST( $LoginLogPath + "\Computers") = 0
MD $LoginLogPath + "\Computers"
ENDIF
$arrLogFiles = "$LoginLogPath\Users\@USERID.txt" , "$LoginLogPath\Computers\@WKSTA.txt"
FOR EACH $Logfile in $arrLogFiles
IF EXIST ( "$Logfile" )
$Dummy = OPEN( 1 , "$Logfile" , 5 )
ELSE
$Dummy = OPEN( 1 , "$Logfile" , 5 )
$Dummy = WRITELINE( 1 , "Workstation |Logon server |IP Address | Date and time | User name" + @CRLF )
$Dummy = WRITELINE( 1 , "----------------|---------------|---------------|-----------------------|-----------" + @CRLF )
ENDIF
IF LEN( @WKSTA ) < 8
$Dummy = WRITELINE( 1 , "@WKSTA ")
ELSE
$Dummy = WRITELINE( 1 , "@WKSTA ")
ENDIF
IF LEN( $LSERVER ) < 7
$Dummy = WRITELINE( 1 , "|$LServer ")
ELSE
$Dummy = WRITELINE( 1 , "|$LServer ")
ENDIF
IF LEN( $IPaddress ) = 15
$Dummy = WRITELINE( 1 , "|$IPaddress")
ELSE
$Dummy = WRITELINE( 1 , "|$IPaddress ")
ENDIF
$Dummy = WRITELINE( 1 , "| @MDAYNO-@MONTHNO-@YEAR @@ @TIME | @USERID ($FullName)" + @CRLF )
$Dummy = CLOSE( 1 )
NEXT
RETURN
============================================================
== FinishLogin
============================================================
:FinishLogin
$prgProgressBar.Value = $prgProgressBar.Max
IF $EmailErrors <> "YES" OR $ErrorsLogged <> 1 OR $LoginLogging <> "ENABLED" OR $SendTo = "" OR $Sender = "" OR $SMTPServer = ""
Return
ENDIF
$EmailTitle = "Error(s) occurred while @USERID ($Fullname) logged on to @WKSTA (@MDAYNO @MONTH @YEAR at @TIME)"
$EmailSender = JOIN( SPLIT( $Sender , "@" ) , "@@" )
SELECT
CASE INSTR( $SendTo , "," )
$ArrSendTo = SPLIT( $SendTo , "," )
CASE 1
$ArrSendTo = SPLIT( $SendTo , ";" )
ENDSELECT
FOR EACH $Element IN $ArrSendTo
$SendToElement = JOIN( SPLIT( $Element , "@" ) , "@@" )
IF $Inventory = "ENABLED" AND EXIST( "$LoginLogPath\Inventory\@WKSTA.txt" )
SHELL '%COMSPEC% /C $ScriptDir\Data\blat.exe $ScriptDir\Data\ErrorMail.txt -t $SendToElement -s "$EmailTitle" -f $EmailSender -server $SMTPServer -attacht %WINDIR%\LoginErrors.txt -attacht $LoginLogPath\Inventory\@WKSTA.txt -q'
ELSE
SHELL '%COMSPEC% /C $ScriptDir\Data\blat.exe $ScriptDir\Data\ErrorMail.txt -t $SendToElement -s "$EmailTitle" -f $EmailSender -server $SMTPServer -attacht %WINDIR%\LoginErrors.txt -q'
ENDIF
NEXT
Return
============================================================
== Empty all variables
============================================================
:ClearVars
$TextLabel1 = ""
$TextLabel2 = ""
$TextLabel3 = ""
$TextLabel4 = ""
$TextLabel5 = ""
$TextLabel6 = ""
$TextLabel7 = ""
$TextLabel8 = ""
$TextLabel9 = ""
$TextLabel10 = ""
$TextLabel11 = ""
$TextLabel12 = ""
$TextLabel13 = ""
$TextLabel14 = ""
$TextLabel15 = ""
$TextLabel16 = ""
$TextLabel17 = ""
$ScriptLanguage = ""
$LoginScriptTitle = ""
$LoginLogPath = ""
$LoginLogging = ""
$Inventory = ""
$MinInventoryAge = ""
$EmailErrors = ""
$SendTo = ""
$Sender = ""
$SMTPServer = ""
$HomeDrivePath = ""
$HomeDriveLetter = ""
$WordStartUpPath = ""
$UserTemplates = ""
$WorkgroupTemplates = ""
$ConfigureOutlook = ""
$ExchangeServer = ""
$MyDocumentsDir = ""
$FavoritesDir = ""
$MyPicturesFolder = ""
$DesktopDir = ""
$RecentDir = ""
$ApplicationData = ""
$TempInternetFiles = ""
$Cookies = ""
$History = ""
$ProxyServer = ""
$ProxyServerPort = ""
$ProxyBypassString = ""
$MandatoryStartupPage = ""
$TimeServer = ""
$DeleteNetworkPrinters = ""
$Dummy = ""
$ScriptDir = ""
$Result = ""
$CpuType = ""
$IEVersion = ""
$IPaddress = ""
$HWAddress = ""
$Lserver = ""
$Blue = ""
$BlueGrey = ""
$Grey = ""
$Green = ""
$Red = ""
$Printer = ""
$LoginScrIni = ""
$Letter = ""
$Share = ""
$Persistent = ""
$PrinterShare = ""
$Default = ""
$Status = ""
$ErrorLevel = ""
$KixErrorCode = ""
$StatusCount = ""
$OpenScript = ""
$FileError = ""
$Errorfile = ""
$arrErrorFiles = ""
$ErrorsLogged = ""
$what = ""
$where = ""
$WMIQuery = ""
$strQuery = ""
$objEnumerator = ""
$value = ""
$objInstance = ""
$objEnumerator = ""
$GetFileAge = ""
$File = ""
$UpdateCommandLine = ""
$UpdateName = ""
$IniFileTitle = ""
$Prompt = ""
$Silent = ""
$PCounter = ""
$element = ""
$Array = ""
RETURN
Well.. good luck :P
Edited by Collin (2004-05-12 09:32 AM)
_________________________
Ruud is my hero
|
|
Top
|
|
|
|
#118969 - 2004-05-12 09:31 AM
Re: Proper way to end a script
|
Collin
Fresh Scripter
Registered: 2002-01-18
Posts: 21
Loc: Amsterdam - NL
|
Quote:
Yes Windows 9x does have more limitations in KiXforms then NT/2000/XP/2003 does and is documented in the helpfile for KiXforms.
Also, as Lonkero mentioned, remove the GOSUB and just leave the command such as UDFTASK()
OK, did that
Quote:
You're also doing a REGSVR32 every logon (which requires the user to be a local Admin on the system, but don't see you doing such a check)
I would use another method to perform that task so it is not done every time.
Yeah I know about that, I need to first logon with admin privs or the scrip will fail, but to check if you have local admin privs, you need a kxpcp service and I don't want to implement that in the script (lots of clients and companies use this script, if I update this script, they replace only this part)
Quote:
You don't need to CD a simple SHELL to the REGSVR32 should be sufficient.
Perhaps use the @DOS or @ProductType if you need or want to do something for 9x that you do or don't want to do for NT or newer type systems.
You don't appear to centrally log any type of failure for user logons, so I don't see any way of knowing of such an error until a user calls in (if they ever call in).
I'd recommend logging any failures (that don't crash KiXtart) so that you know the user or system is not properly processing the script. Then you can review the user account or the system to see what is causing an issue when other users or systems don't havwe an issue with the script.
I do log stuff (check the UDF LogError() ) of the users login to a share (errors, logon times per user and computer) just no logging of the progress of the script. The script itself never crashes, when the script is done, most of the time it crashes a few seconds after the script has completed.
Thanks for commenting the code, it's very useful. I'll make a progress 'logging' feature. Maybe after every GOSUB routine, write a line to a text file and the last line of the script will be to delete the textfile, so if it is there the script has crashed and I can see in which routine it crashed.
Edited by Collin (2004-05-12 09:39 AM)
_________________________
Ruud is my hero
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|