What version of KiXforms are you using? You should be using the latest, it is version 2.46.54.0. You can get it here: http://www.kixforms.org/forum/viewtopic.php?t=503
If you do not know what version you are using, run this script.
Code:
Break On
$System = CreateObject("Kixtart.System")
If Not $System
$nul= MessageBox("KiXforms Not Initiated. This Script Will Now Close.","Error",262160)
Quit()
EndIf
$Form = $System.Form()
$Form.Text = 'KiXforms.Classic Version'
$Form.Size = 300,100
$Lbl = $Form.Controls.Label()
$Lbl.Text = 'KiXforms.Classic Version '+$system.Version
$Lbl.TextAlign = 32
$Lbl.Dock = 'Fill'
$Form.Show
While $Form.Visible
$nul= Execute($Form.DoEvents)
Loop
Exit 0
Goto and GoSub can cause problems and can make it difficult to follow a script when you need to modify your script 6 months or a year later.
They should be converted to User Defined Functions (UDFs).
How to use UDFs can be found here: http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=81594&an=0&page=0#81594
How to write a UDF can be found here: http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=81656&an=0&page=0#81656
Do your users have Admin rights on there machines?
If they do not, this code will not work:
Code:
$ReturnCode = KEYEXIST("HKEY_CLASSES_ROOT\KixTart.Form\CLSID")
IF $ReturnCode = 0 ;** KixForms not registered
;** Copy .DLL
$SourceFile = @LServer + "\netlogon\kixforms.dll"
$Value = ReadValue( "HKLM\System\CurrentControlset\Control\Windows", "SystemDirectory")
$Destination = ExpandEnvironmentVars( $Value )
COPY $SourceFile $Destination
;** Register .DLL silently
$CMDLine = "regsvr32 /s " + $Destination + "\kixforms.dll"
$ObjShell = CreateObject("WScript.Shell")
$ObjShell.run($CMDLine, 1, true)
;** Kill shell object
$ObjShell = nothing
ENDIF
;** Wait for registration to take effect
sleep 2
If they do, it should be converted to a UDF and placed at the end of the script.
This is your CheckDll converted to a function:
Code:
Function CheckDLL()
;*************************************************
;** Check that KIXFORMS.DLL is registered and **
;** copy and register if not **
;*************************************************
;$ReturnCode = KeyExist("HKEY_CLASSES_ROOT\KixTart.Form\CLSID")
$ReturnCode = KeyExist("HKEY_CLASSES_ROOT\Kixtart.System\CLSID")
If $ReturnCode = 0 ;** KixForms not registered
;** Copy .DLL
$SourceFile = @LServer + "\netlogon\kixforms.dll"
$Value = ReadValue("HKLM\System\CurrentControlset\Control\Windows", "SystemDirectory")
$Destination = ExpandEnvironmentVars($Value)
Copy $SourceFile $Destination
;** Register .DLL silently
$CMDLine = "regsvr32 /s " + $Destination + "\kixforms.dll"
$ObjShell = CreateObject("WScript.Shell")
$ObjShell.run($CMDLine, 1, true)
;** Kill shell object
$ObjShell = ""
EndIf
;** Wait for registration to take effect
Sleep 2
EndFunction
To call the function use this code:
Code:
CheckDLL()
Code containing forms should be placed at the beginning of the script.
UDFs should be placed at the end of the script.
I have moved the form code to the beginning.
I have changed this line:
Code:
$ReturnCode = KEYEXIST("HKEY_CLASSES_ROOT\KixTart.Form\CLSID")
To:
Code:
$ReturnCode = KeyExist("HKEY_CLASSES_ROOT\Kixtart.System\CLSID")
“KiXtart.Form” is outdated and has been replaced with “KiXtart.System”
With that said, the KiXforms Object should be created like this:
Code:
$System = CreateObject("Kixtart.System")
After the KiXforms Object is created you should verify that it was actually created, if it was not created it is more than likely that the KiXforms.dll is not installed.
Here is the suggested code:
Code:
If Not $System
$nul= MessageBox("KiXforms Not Initiated."+@CRLF+
"Please Verify KiXforms.dll is installed."+@CRLF+
"This Script Will Now Close.","Error...",16)
Quit()
EndIf
In your code you are using ‘GoSub DoProgress’ to increment the ProgressBar.Value, this should be converted to a UDF.
Change these lines:
Code:
:DoProgress
$prgProgress.value = $prgProgress.value + $Step
Return
To:
Code:
Function DoProgress()
$prgProgress.Value = $prgProgress.Value + $Step
EndFunction
And move the function to the end of the script.
Changing the “GoSub DoProgress” to a function, this line:
Code:
GoSub DoProgress
Will need to be changed to:
Code:
DoProgress()
In every other script that you are calling.
The .Caption property is out dated and should be replaced with the .Text property.
This line:
Code:
$frmForm.Caption = ("NetCare3.2 - D5PS2Z0J Logon System ")
Should be replaced with this line:
Code:
$frmForm.Text = "NetCare3.2 - D5PS2Z0J Logon System "
The parentheses should not be used.
The .Center property should be move to just before showing the form.
This line:
Code:
$frmForm.center
Should be moved here:
Code:
$frmForm.Center
$frmForm.Show
In the older versions of KiXforms, Controls were created like you have done here:
Code:
$fraBanner = $frmForm.PictureBox
In the current versions Controls should be created like this:
Code:
$fraBanner = $frmForm.Controls.Add("PictureBox")
For forms to function correctly there needs to be a loop that checks for form events. This code should be placed after showing the form.
This is the suggested code:
Code:
While $frmForm.Visible
$=Execute($frmForm.DoEvents())
Loop
When the form Exits it should exit with a 0 not a 1, the reason for this is to show that the form exited with out errors.
Code:
Exit 0
In your code you call these other scripts:
Code:
Call "$LSD\prep.kix"
Call "$LSD\MapDrives.kix"
Call "$LSD\DoAudit.kix"
Call "$LSD\LogUser.kix"
Call "$LSD\DoAntiVirus.kix"
Call "$LSD\time.kix"
Call "$LSD\snd.kix"
With all the changes suggested, it might be a good idea for you to post these scripts one at time for us to review and help you perfect the code.
This code should be placed after calling this other scripts, and before exiting the script, to be able to change the text you want to change use this format:
Code:
$fraMain.ForeColor = $fraMain.BackColor
$fraMain.PrintXY (10,40,"Please wait while you logon script executes...")
$fraMain.ForeColor = $frmForm.RGB(0,100,100)
$fraMain.PrintXY (10,40,"Logon has been successful.")
To exit the form I have added this function:
Code:
Function ExitScript()
Quit()
EndFunction
It should be called after the text has been changed, to call it use this code:
Code:
ExitScript()
Here is your updated code:
Code:
;***************************************************************
;***************************************************************
;**
;** NetCare3.2 - D5PS2Z0J Login System
;** Netlogon.kix
;** D5PS2Z0J NetServices
;**
;** Dependencies:
;**
;** Kixforms.dll Ver 2.46.54.0
;**
;**
;**
;***************************************************************
;***************************************************************
;** Dim some global vars.
Dim $frmForm
Dim $fraBanner, $fraForm
;Dim $prgProgress
Dim $Hour
;** Set some global vars.
$strVersion = "V.3.2.09"
$LSD = @LServer + "\netlogon"
$WaitTime = 1 ;** Time to wait after each task
$DoProgressCalls = 25 ;** Maximum times DoProgress is called
$Step = 100/$DoProgressCalls ;** Increment progress bar
$Blanker = " " ;** Blank captions
;******************
;** START HERE **
;******************
CheckDLL()
;Create KiXforms Object
$System = CreateObject("Kixtart.System")
;Verify KiXforms Object was created
If Not $System
$nul= MessageBox("KiXforms Not Initiated."+@CRLF+
"Please Verify KiXforms.dll is installed."+@CRLF+
"This Script Will Now Close.","Error...",16)
Quit()
EndIf
;***************
;** Main form **
;***************
$frmForm = $System.Form()
$frmForm.Text = "NetCare3.2 - D5PS2Z0J Logon System "
$frmForm.SysMenu = 0
$frmForm.Height = 300
$frmForm.Width = 450
$frmForm.FontName = "Verdana"
$frmForm.FontSize = 9
;*************
;** Banner **
;*************
$fraBanner = $frmForm.Controls.Add("PictureBox")
;$fraBanner.Image = "C:\my projects\NetCare3\Images\NC32SM.gif"
$fraBanner.BackColor = $frmForm.RGB(255,255,255)
$fraBanner.Width = $frmForm.Width - 4
$fraBanner.Height = 60
$fraBanner.Left = -2
$fraBanner.Top = -2
;** Draw On the banner **
$fraBanner.FontSize = 14
$fraBanner.FontName = "verdana"
$fraBanner.FontBold = 1
$fraBanner.FontItalic = 1
$fraBanner.ForeColor = $frmForm.RGB(0, 0, 200)
$fraBanner.PrintXY (10,0,"Netlogon.kix")
$fraBanner.FontItalic = 0
$fraBanner.FontSize = 8
$fraBanner.ForeColor = $frmForm.RGB(0,0,0)
$fraBanner.PrintXY (10,24,$strVersion +" Powered by KiXforms (Shamil Nunhuck) ")
$fraBanner.FontSize = 9
$fraBanner.PrintXY (10,35,"D5PS2Z0J NetServices")
$fraBanner.FontBold = 0
$fraBanner.FontSize = 10
;******************
;** Progress Bar **
;******************
$prgProgress = $frmForm.Controls.Add("ProgressBar")
$prgProgress.Width = $frmForm.Width - 10
$prgProgress.Left = 2
$prgProgress.Height = 20
$prgProgress.Top = 245;$frmForm.Height - $prgProgress.Height - 5
$prgProgress.Style = 1
;****************
;** Main Frame **
;****************
$fraMain = $frmForm.Controls.Add("PictureBox")
$fraMain.BackColor = $frmForm.RGB(255,255,255)
$fraMain.Width = $frmForm.Width
$fraMain.Height = 182 ;$frmForm.Height - $fraBanner.Height - 35
$fraMain.Left = -2
$fraMain.Top = $fraBanner.Height - 5
$lblJob = $fraMain.Controls.Add("label")
$lblJob.FontSize = 10
$lblJob.Top = 80
$lblJob.Width = 440 ;fraMain.Width - 20
$lblJob.Left = 10
$lblTask = $fraMain.Controls.Add("label")
$lblTask.FontSize = 10
$lblTask.Top = 120
$lblTask.Width = 440 ;fraMain.Width - 20
$lblTask.Left = 50
;** Draw on the frame **
;** Greeting
$Hour = Val(Trim(Left(@Time,2)))
If $Hour < 12
$Greeting = "Good Morning @userid "
Else
If $Hour < 17
$Greeting = "Good Afternoon @userid"
Else
$Greeting = "Good Evening @userid "
EndIf
EndIf
$fraMain.FontSize = 11
$fraMain.FontName = "verdana"
$fraMain.FontBold = 1
$fraMain.ForeColor = $frmForm.RGB(0,100,100)
$fraMain.PrintXY (10,10,$Greeting)
$fraMain.PrintXY (10,40,"Please wait while you logon script executes...")
$frmForm.Center
$frmForm.Show
;Call "$LSD\prep.kix"
;Call "$LSD\MapDrives.kix"
;Call "$LSD\DoAudit.kix"
;Call "$LSD\LogUser.kix"
;Call "$LSD\DoAntiVirus.kix"
;Call "$LSD\time.kix"
;Call "$LSD\snd.kix"
Sleep 2
$fraMain.ForeColor = $fraMain.BackColor
$fraMain.PrintXY (10,40,"Please wait while you logon script executes...")
$fraMain.ForeColor = $frmForm.RGB(0,100,100)
$fraMain.PrintXY (10,40,"Logon has been successful.")
Sleep 2
ExitScript()
While $frmForm.Visible
$=Execute($frmForm.DoEvents())
Loop
Exit 0
;**************
;** END HERE **
;**************
Function CheckDLL()
;*************************************************
;** Check that KIXFORMS.DLL is registered and **
;** copy and register if not **
;*************************************************
;$ReturnCode = KeyExist("HKEY_CLASSES_ROOT\KixTart.Form\CLSID")
$ReturnCode = KeyExist("HKEY_CLASSES_ROOT\Kixtart.System\CLSID")
If $ReturnCode = 0 ;** KixForms not registered
;** Copy .DLL
$SourceFile = @LServer + "\netlogon\kixforms.dll"
$Value = ReadValue("HKLM\System\CurrentControlset\Control\Windows", "SystemDirectory")
$Destination = ExpandEnvironmentVars($Value)
Copy $SourceFile $Destination
;** Register .DLL silently
$CMDLine = "regsvr32 /s " + $Destination + "\kixforms.dll"
$ObjShell = CreateObject("WScript.Shell")
$ObjShell.run($CMDLine, 1, true)
;** Kill shell object
$ObjShell = ""
EndIf
;** Wait for registration to take effect
Sleep 2
EndFunction
Function DoProgress()
$prgProgress.Value = $prgProgress.Value + $Step
EndFunction
Function ExitScript()
Quit()
EndFunction
;*******************************
;*******************************
;** END OF FILE **
;*******************************
;*******************************