#203064 - 2011-09-08 08:30 PM
Custom Login Script
|
estradac
Fresh Scripter
Registered: 2003-09-11
Posts: 18
|
Hello All,
Its been awhile since I worked with KIX so please excuse my ignorance. I am working on a site that requires a KIX script to do the following:
1. check for existence of a particular software a. if missing software install 2. check for existence of mcafee dat a. if missing software install b. also update DATS if required.
I have this existing script for them -maybe someone can guide me on where I can modify to accomplish my goal. I am assuming most if not all of this is no longer used or applicable.
;============================================================
;== Login script written by CXXXXXXXXXXXXXXXXX ==
;============================================================
;============================================================
GOSUB Preparation
GOSUB HomeDrive
GOSUB Printers
GOSUB Outlook
GOSUB InternetExplorer
GOSUB TimeSync
GOSUB ClientFiles
GOSUB ShellFolders
GOSUB Word
GOSUB CustomScripts
GOSUB Inventory
GOSUB Updates
GOSUB LoginLog
GOSUB FinishLogin
SLEEP 2
Del "%Temp%\LoginScriptDebugLog.txt"
QUIT 0
============================================================
== Preparation
============================================================
:Preparation
WriteDebugLog( "Started subroutine '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..."
$TextLabel18 = "Executing computer specific script..."
$TextLabel19 = "Task: "
EndIf
IF EXIST( "%WINDIR%\Kixforms.dll" )
IF 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 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 = READVALUE( "HKLM\Software\Microsoft\Internet Explorer" , "Version" )
$MDACVersion = READVALUE( "HKLM\SOFTWARE\Microsoft\DataAccess" , "Version" )
$DotNetVersion = IIF( GetFileVersion("%Windir%\system32\mscoree.dll"),"Version "+GetFileVersion("%Windir%\system32\mscoree.dll"),"Not installed")
$IPaddress = LTRIM(SUBSTR(@IPADDRESS0 , 1 , 3)) + "." + LTRIM(SUBSTR(@IPADDRESS0 , 5 , 3)) + "." + LTRIM(SUBSTR(@IPADDRESS0 , 9 , 3)) + "." + LTRIM(SUBSTR(@IPADDRESS0 , 13 , 3))
$HWAddress = @ADDRESS
$Lserver = SUBSTR( @LSERVER , 3 , LEN( @LSERVER ) - 2 )
$LocalAdmin = ingroup(@wksta+'\'+sidtoname('S-1-5-32-544'))-1+@INWIN
$Blue = 50,111,166
$BlueGrey = 123,148,177
$Grey = 198,195,198
$Green = 0,180,0
$Red = 180,0,0
WriteDebugLog( "Started in 'Preparation' initialization of Kixforms GUI (needs kixforms.dll to be registered)" )
$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
$lblAction = $Easykix.Label("",35,360,436,20)
$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
============================================================
== User defined Functions
============================================================
Function SetAction( $Action )
$lblAction.Text = "$Action"
EndFunction
;-------------------------------------------------------------------
FUNCTION MAPDRIVE( $Letter , $Share , Optional $Persistent , Optional $PrettyName )
WriteDebugLog( "UDF 'Mapdrive' is mapping letter '$Letter' to share '$Share'" )
IF %UserProfile% = ""
$Persistent = ""
EndIf
IF RIGHT( $Letter , 1 ) <> ":" AND $Letter <> ":"
$Letter = $Letter + ":"
ENDIF
SELECT
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
If $PrettyName <> "" And Left( $Share , 2 ) = "\\"
$arrPath = Split( $Share , "\" )
$NewName = "#"
For Each $Part in $arrPath
If $Part <> ""
$NewName = $NewName + "#$part"
EndIf
Next
$=WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\$NewName","_LabelFromReg","$PrettyName","REG_SZ")
EndIf
ENDFUNCTION
;-------------------------------------------------------------------
FUNCTION MAPPRINTER( $PrinterShare , optional $Default )
WriteDebugLog( "UDF 'MapPrinter' is mapping printer '$printerShare'.")
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
SetAction( "Connecting printer $PrinterShare" )
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
SetAction( "" )
ENDSELECT
ENDFUNCTION
;-------------------------------------------------------------------
Function WriteDebugLog( $LineToWrite )
$Dummy=open(9,"%Temp%\LoginScriptDebugLog.txt",5)
$Dummy=WriteLine(9,"@TIME @MDAYNO-@MONTHNO-@YEAR > @USERID@@@WKSTA > $LineToWrite"+@CRLF)
$Dummy=Close(9)
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 )
WriteDebugLog( "UDF 'LogError' logged an error: $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 = "%TEMP%\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 )
WriteDebugLog( "UDF 'CallScript' called '$script' to run." )
$OpenScript = "$script"
Select
Case Right($script,4)=".kix"
CALL "$script"
Case Right($script,4)=".bat"
Shell '%Comspec% /c "$Script"'
EndSelect
$OpenScript = ""
$lblAction.Text = ""
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 DaysAD()
$MonthDays = 0,0,31,59,90,120,151,181,212,243,273,304,334
$=Execute("$YearDay = $MonthDays["+@MonthNo+"]+"+@MDayNo)
$DaysAD = ((VAL(@YEAR)*365)+$YearDay)
EndFunction
;-------------------------------------------------------------------
FUNCTION RUNUPDATE( $UpdateCommandLine )
WriteDebugLog( "UDF 'RunUpdate' is running '$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 )
WriteDebugLog( "UDF 'SetShellFolder' is setting shell folder '$ShellFolder' to location '$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
;-------------------------------------------------------------------
;FUNCTION DBCommand()
;
;ACTION Executes a SQL statement and returns an array of records if applicable
;
;AUTHOR Jens Meyer (sealeopard@usa.net)
;
;VERSION 1.1
;
;KIXTART 4.12+
;
;SYNTAX RETCODE = DBCOMMAND(DSN, SQL)
;
;PARAMETERS DSN
; Database connection string (ODBC format)
;
; SQL
; SQL statement to be executed
;
;RETURN 2-D array of records or an empty string (SELECT) or 0 if other SQL
; statement (CREATE, INSERT, UPDATE, DELETE, DROP,...) was executed successfully.
;
;REMARKS See also DBConnOpen(), DBConnClose(), DBRecordsetOpen(), DBRecordsetClose(), DBGetRecordset(), DBExecuteSQL()
;
;DEPENDENCIES none
;
;EXAMPLE $dsn='DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=test.mdb'
; $sql="INSERT INTO Table1 VALUES('eee','fff')"
; $recordset = DBCommand($dsn,$sql)
; ? 'Error = '+@ERROR+' - '+@SERROR
; $sql="SELECT Field1, Field2 FROM Table1"
; $recordset = DBCommand($dsn,$sql)
; ? 'Error = '+@ERROR+' - '+@SERROR
; for $row=0 to ubound($recordset,1)
; for $column=0 to ubound($recordset,2)
; ? 'Field(row='+$row+', column='+$column+') ='+$recordset[$row,$column]
; next
; next
;
;KIXTART BBS http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000328
;
function DBCommand($ConnDSN,$sql)
Dim $objConn, $adStateOpen
dim $Conntimeout, $CmdTimeout
dim $cmdCommand, $rsRecordset
dim $Records, $FinalRecords
dim $adCmdText, $adLockReadOnly, $adOpenStatic
dim $row, $rows, $column, $columns
$ConnDSN=trim($ConnDSN)
if not $ConnDSN
exit 87
endif
$sql=trim($sql)
if not $sql
exit 87
endif
; default database parameters
$adStateOpen=1
$ConnTimeout=15
$CmdTimeout=30
$adCmdText = 1
$adOpenStatic = 3
$adLockReadOnly = 1
; open the database connection
$objConn = CreateObject("ADODB.Connection")
if @ERROR
exit @ERROR
endif
$objConn.ConnectionTimeout = $ConnTimeout
if @ERROR
exit @ERROR
endif
$objConn.CommandTimeout = $CmdTimeout
if @ERROR
exit @ERROR
endif
$objConn.Open($ConnDSN)
if @ERROR
exit @ERROR
endif
if not $objConn.State=$adStateOpen
$objConn=''
$DBCommand=''
exit @ERROR
endif
; create the database command object
$cmdCommand = CreateObject('ADODB.Command')
if @ERROR
exit @ERROR
endif
$cmdCommand.ActiveConnection = $objConn
if @ERROR
exit @ERROR
endif
$cmdCommand.CommandType = $adCmdText
if @ERROR
exit @ERROR
endif
$cmdCommand.CommandText = $sql
if @ERROR
$DBCommand=@ERROR
exit @ERROR
endif
if instr($sql,'SELECT')=1
; create the recordset object
$rsRecordSet = CreateObject('ADODB.Recordset')
if @ERROR
exit @ERROR
endif
$rsRecordset.CursorType = $adOpenStatic
if @ERROR
exit @ERROR
endif
$rsRecordset.LockType = $adLockReadOnly
if @ERROR
exit @ERROR
endif
$rsRecordset.Open($cmdCommand)
if @ERROR
exit @ERROR
endif
if $rsRecordset.EOF and $rsRecordSet.BOF
; recordset is empty
$FinalRecords=''
else
if @ERROR
exit @ERROR
endif
; retrieve all records at once and transpose into tabular format
$Records = $rsRecordset.GetRows()
$columns=ubound($records,1)
$rows=ubound($records,2)
redim $FinalRecords[$rows,$columns]
for $row=0 to $rows
for $column=0 to $columns
$FinalRecords[$row,$column]=$records[$column,$row]
next
next
endif
; close recordset
if $rsRecordset.state=$adStateOpen
$rsRecordset.Close()
if @ERROR
exit @ERROR
endif
endif
$rsRecordset=''
$cmdCommand=''
$DBCommand=$FinalRecords
else
$rsRecordset=$cmdCommand.Execute()
$cmdCommand=''
$rsRecordset=''
if @ERROR
exit @ERROR
endif
$DBCommand=0
endif
; close the database connection
If $objConn.State = $adStateOpen
$objConn.Close()
if @ERROR
exit @ERROR
endif
EndIf
$objConn=''
exit 0
endfunction
============================================================
== HomeDrive
============================================================
:HomeDrive
WriteDebugLog( "Started subroutine '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
If Exist("$HomeDrivePath")=0
md $HomeDrivePath
EndIf
SHOWSTATUS( $TextLabel9 )
MAPDRIVE( $HomeDriveLetter , $HomeDrivePath , "Persistent" , "$HomeDriveLabel" )
SHOWRESULT()
ENDSELECT
RETURN
============================================================
== Printers
============================================================
:Printers
WriteDebugLog( "Started subroutine '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
============================================================
== ShellFolders
============================================================
:ShellFolders
WriteDebugLog( "Started subroutine 'ShellFolders'" )
SELECT
CASE READPROFILESTRING( "$ScriptDir\custom\LaptopUsers.ini" , "Laptop users" , @USERID ) <> ""
RETURN
CASE $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
If $MyPicturesFolder <> ""
LOGERROR( "Illegal path '$MyPicturesFolder' set for the 'My Pictures' folder. Set the 'MyDocumentsDir' variable in the LoginScript.ini file." )
EndIf
ENDIF
ENDIF
SHOWRESULT()
RETURN
============================================================
== Office 97/2000/XP/2003
============================================================
:Word
WriteDebugLog( "Started subroutine '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' could not be accesses and/or 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")
$Dummy = Writevalue("$OfficeKey\12.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' could not be accesses and/or 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")
$Dummy = Writevalue("$OfficeKey\12.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 '$WordStartUpPath' could not be accesses and/or 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")
$Dummy = Writevalue("$OfficeKey\12.0\Word\Options" , "STARTUP-PATH" , "$WordStartUpPath" , "REG_EXPAND_SZ")
ENDIF
ENDIF
SHOWRESULT()
RETURN
============================================================
== Outlook
============================================================
:Outlook
WriteDebugLog( "Started subroutine 'Outlook'" )
If $ProfileName = ""
$ProfileName = @USERID
EndIf
del "%TEMP%\$ProfileName.prf"
Select
Case KeyExist("HKCU\Software\Microsoft\Windows Messaging Subsystem\Profiles\$ProfileName")
$Dummy = Writevalue("HKCU\Software\Microsoft\Windows Messaging Subsystem\Profiles" , "DefaultProfile" , "$ProfileName" , "REG_SZ")
Return
Case KeyExist("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\$ProfileName")
$Dummy = Writevalue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" , "DefaultProfile" , "$ProfileName" , "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
Case Left($OutlookVersionNr,2)=12
$OutlookVersion=2007
EndSelect
ShowStatus("$TextLabel15 $OutlookVersion...")
copy "$ScriptDir\data\Outlook\Outlook.prf" "%TEMP%\$ProfileName.prf"
copy "$ScriptDir\data\Outlook\Fixprf.exe" %TEMP%
copy "$ScriptDir\data\Outlook\Newprof.exe" %TEMP%
If $ResolveMailboxVar <> ""
SHELL '%COMSPEC% /C %TEMP%\fixprf "%TEMP%\$ProfileName.prf" "$ResolveMailboxVar" "$ProfileName" $ExchangeServer'
Else
SHELL '%COMSPEC% /C %TEMP%\fixprf "%TEMP%\$ProfileName.prf" @USERID "$ProfileName" $ExchangeServer'
EndIf
Select
Case $OutlookVersion=97
SHELL '%COMSPEC% /C %TEMP%\newprof -p "%TEMP%\$ProfileName.prf" -x'
If @error<>0
Logerror("Error configuring Outlook")
EndIf
Case $OutlookVersion=2000
SHELL '%COMSPEC% /C %TEMP%\newprof -p "%TEMP%\$ProfileName.prf" -x'
If @error<>0
Logerror("Error configuring Outlook")
EndIf
Case $OutlookVersion=XP
Run '$OutlookPath /importprf "%TEMP%\$ProfileName.prf"'
If @error<>0
Logerror("Error configuring Outlook")
EndIf
Case $OutlookVersion=2003
Run '$OutlookPath /importprf "%TEMP%\$ProfileName.prf"'
If @error<>0
Logerror("Error configuring Outlook")
EndIf
Case $OutlookVersion=2007
Run '$OutlookPath /importprf "%TEMP%\$ProfileName.prf"'
If @error<>0
Logerror("Error configuring Outlook")
EndIf
EndSelect
Sleep 1
del "%TEMP%\Fixprf.exe"
del "%TEMP%\Newprof.exe"
ShowResult()
RETURN
============================================================
== Configuring Internet Explorer
============================================================
:InternetExplorer
WriteDebugLog( "Started subroutine 'InternetExplorer'" )
If $MandatoryStartupPage <> ""
$Dummy=WriteValue("HKCU\Software\Microsoft\Internet Explorer\Main","Start Page",$MandatoryStartupPage,"REG_SZ")
EndIf
if $ConfigureProxy = "YES"
If $EnableProxy = "YES"
$Dummy=WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyEnable","1","REG_DWORD")
Else
$Dummy=WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyEnable","0","REG_DWORD")
EndIf
$Dummy=WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyServer","$ProxyServer","REG_SZ")
$Dummy=WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyOverride","$ProxyBypassString","REG_SZ")
EndIf
RETURN
============================================================
== Inventory
============================================================
:Inventory
WriteDebugLog( "Started subroutine 'Inventory'" )
IF $Inventory <> "ENABLED" OR $LoginLogPath = ""
RETURN
ENDIF
$InvMacAddress = ReadProfileString( "$LoginLogPath\Inventory\@WKSTA.txt" , "tech info" , "hardware address" )
$Dagen = DaysAD()
$InvTimeStamp = ReadProfileString( "$LoginLogPath\Inventory\@WKSTA.txt" , "inventory" , "timestamp" )
$InventoryAge = Val($Dagen) - Val($InvTimeStamp)
SELECT
CASE Val($InventoryAge) => Val($MinInventoryAge)
SHOWSTATUS( $TextLabel16 )
CASE $HWAddress <> $InvMacAddress
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 user login]" + @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "User ID = @USERID" + @CRLF )
$Dummy = WRITELINE( 5 , "Full name = $FullName" + @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 , "Internet Explorer = Version $IEVersion" + @CRLF )
$Dummy = WRITELINE( 5 , "MDAC Components = Version $MDACVersion" + @CRLF )
$Dummy = WRITELINE( 5 , ".Net Framework = $DotNetVersion" + @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
$Dummy = WRITELINE( 5 , @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "[Inventory]" + @CRLF )
$Dummy = WRITELINE( 5 , "--------------------------------------------------------------" + @CRLF )
$Dummy = WRITELINE( 5 , "TimeStamp = $Dagen" + @CRLF )
$Dummy = WRITELINE( 5 , "Time and Date = @TIME on @MDAYNO @MONTH @YEAR" + @CRLF )
ELSE
LOGERROR( "Error opening file '$LoginLogPath\Inventory\@WKSTA.txt' for writing inventory." )
ENDIF
$Dummy = CLOSE( 5 )
SHOWRESULT()
RETURN
============================================================
== TimeSync
============================================================
:TimeSync
WriteDebugLog( "Started subroutine 'TimeSync'" )
Select
Case READPROFILESTRING( "$ScriptDir\custom\Servers.ini" , "ServerRoutines" , "TimeSync" ) <> "YES" AND $SkipServer = 1
RETURN
Case $TimeServer = ""
RETURN
Case @InWin = 1 And $TimeSyncWin9xOnly = "YES"
RETURN
ENDSELECT
IF LEFT( $TimeServer , 2 ) <> "\\"
$TimeServer = "\\" + $TimeServer
ENDIF
If $Timeserver <> "\\@Wksta"
SETTIME "$TimeServer"
IF @ERROR <> 0
LOGERROR( "Error synchronizing system time with server '$TimeServer'." )
Else
SHOWSTATUS( $TextLabel17 )
SHOWRESULT()
EndIf
EndIf
RETURN
============================================================
== ClientFiles
============================================================
:ClientFiles
WriteDebugLog( "Started subroutine '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'
SHELL '%COMSPEC% /C xcopy "$ClientFiles\ProgramFiles\*.*" "$SysDrive\Program Files\" $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
============================================================
== CustomScripts
============================================================
:CustomScripts
WriteDebugLog( "Started subroutine 'CustomScripts'" )
$EnumGroupCounter = 0
$Group = ENUMGROUP($EnumGroupCounter)
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
IF EXIST( "$ScriptDir\Custom\GroupScripts\" + $Groupname + ".bat" )
IF $FoundGroupScript <> "YES"
SHOWSTATUS( $TextLabel11 )
ENDIF
$FoundGroupScript = "YES"
CALLSCRIPT( "$ScriptDir\Custom\GroupScripts\" + $Groupname + ".bat" )
ENDIF
$EnumGroupCounter = $EnumGroupCounter + 1
$Group = ENUMGROUP($EnumGroupCounter)
LOOP
IF $FoundGroupScript = "YES"
SHOWRESULT()
ENDIF
;---------------------------------------------------------------------
If EXIST( "$ScriptDir\Custom\UserScripts\@USERID.kix" ) Or EXIST( "$ScriptDir\Custom\UserScripts\@USERID.bat" )
SHOWSTATUS( $TextLabel12 )
If EXIST( "$ScriptDir\Custom\UserScripts\@USERID.kix" )
CALLSCRIPT( "$ScriptDir\Custom\UserScripts\@USERID.kix" )
EndIf
If EXIST( "$ScriptDir\Custom\UserScripts\@USERID.bat" )
CALLSCRIPT( "$ScriptDir\Custom\UserScripts\@USERID.bat" )
EndIf
SHOWRESULT()
EndIf
;---------------------------------------------------------------------
IF EXIST( "$ScriptDir\Custom\ComputerScripts\@Wksta.kix" ) Or EXIST( "$ScriptDir\Custom\ComputerScripts\@Wksta.bat" )
SHOWSTATUS( $TextLabel18 )
IF EXIST( "$ScriptDir\Custom\ComputerScripts\@Wksta.kix" )
CALLSCRIPT( "$ScriptDir\Custom\ComputerScripts\@Wksta.kix" )
EndIf
IF EXIST( "$ScriptDir\Custom\ComputerScripts\@Wksta.bat" )
CALLSCRIPT( "$ScriptDir\Custom\ComputerScripts\@Wksta.bat" )
EndIf
SHOWRESULT()
ENDIF
RETURN
============================================================
== Updates
============================================================
:Updates
WriteDebugLog( "Started subroutine '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
WriteDebugLog( "Started subroutine '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
IF EXIST( "$LoginLogPath\Inventory\@WKSTA.txt" )
$Dummy = WriteProfileString("$LoginLogPath\Inventory\@WKSTA.txt","Last user login","User ID",@UserID)
$Dummy = WriteProfileString("$LoginLogPath\Inventory\@WKSTA.txt","Last user login","Full Name",$FullName)
$Dummy = WriteProfileString("$LoginLogPath\Inventory\@WKSTA.txt","Last user login","Time and date","@TIME on @MDAYNO @MONTH @YEAR")
$Dummy = WriteProfileString("$LoginLogPath\Inventory\@WKSTA.txt","Last user login","File location","$LoginLogPath\Inventory\@WKSTA.txt")
EndIf
RETURN
============================================================
== FinishLogin
============================================================
:FinishLogin
WriteDebugLog( "Started subroutine '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 "%TEMP%\LoginErrors.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 "%TEMP%\LoginErrors.txt" -t $SendToElement -s "$EmailTitle" -f $EmailSender -server $SMTPServer -attacht %WINDIR%\LoginErrors.txt -q'
ENDIF
NEXT
Return
|
Top
|
|
|
|
#203072 - 2011-09-10 03:27 PM
Re: Custom Login Script
[Re: Lonkero]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
|
Ugh! Gosubs?? 
The simplest answer would be to write and debug a new script that does what you want using a seriese of functions.. Then, when you are sure that it works, you can add it to the ":Updates" section of your script.
Here's the basic idea:============================================================
== Updates
============================================================
:Updates
WriteDebugLog( "Started subroutine '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 )
If Not CheckSoftware('name') InstallSoftware('name') EndIf
If Not CheckMcAfee() UpdateMcAfee() EndIf
RETURN Note the two lines added just before the RETURN. You will need to write 4 UDFs - CheckSoftware('name') - reads an INI file, checks the section 'NAME' for imformation on how to verify the software is present (Reg Path check?) It returns True if present and False (0) if not. InstallSoftware('Name') - uses the same ini file to determine how to install the software package. CheckMcAfee() - and UpdateMcAfee() - checks the current DAT version and forces an update if necessary.
Note that there are several UDFs available to check for AV info, including a universal UDF that checks for several different products that Doc and I worked on. That UDF uses an external config file to manage the definitions so you don't need to update the code.
One thing - this whole script and concept of a user updating their own software may not work with the enhanced security of Vista, Win-7 and higher systems. We employ a "Detect and Request" method at our client sites so the user can detect if something is needed and then sends a request to a server where the task is immediately performed with Admin rights. Since the install is a separate process, the user login is not delayed, the user account is never granted admin rights, and the user has no access to an admin level account. This has been discussed here before with code samples if you want to give that a try.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 323 anonymous users online.
|
|
|