#204110 - 2012-01-25 11:31 AM
Speeding up Login process
|
sparkie
Getting the hang of it
Registered: 2010-09-14
Posts: 92
Loc: UK
|
We have a number of items in our script that re-run every morning, as the script grows we're starting to experience extended time for it to complete.
These items are there because someone might login to another PC so the entries need applying.
Here's an example of an Office setting, we have about 15 of these
; ### Outlook Office 2007 registry entry to set default fonts ###
IF ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\MailSettings","OutlookDefaultFonts") <> "Arial"
$rc = WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\MailSettings","OutlookDefaultFonts", "Arial", "REG_SZ")
$rc = WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\MailSettings","OutlookDefaultFontsDate", "@DATE", "REG_SZ")
$rc = WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\MailSettings","OutlookDefaultFontsTime", "@TIME", "REG_SZ")
RUN "regedit.exe /s \\<servername>\Office2007ProPlus\scripts\OutlookDefaultFonts.reg"
ELSE
?"Value is already there (Outlook Default Font). No need to change."
ENDIF
Appreciate I could remove the entry for planting the insertion date/time!
The script can sit waiting to complete for long periods of time on occasions, moreso when people are logging into a Terminal Server or when many people are logging in for the first time in the morning (all at the same time).
Does anyone have some ideas how we could speed the process up.
Thanks
Mark
Edited by Mart (2012-01-25 03:43 PM) Edit Reason: Please use code tags when posting code.
|
Top
|
|
|
|
#204117 - 2012-01-26 10:48 AM
Re: Speeding up Login process
[Re: BradV]
|
sparkie
Getting the hang of it
Registered: 2010-09-14
Posts: 92
Loc: UK
|
Why are you running regedit after you just used kixtart to write to the registry? What is it doing?
Good question, I'm sure I could plant these with WriteValue. Would this speed things up?
Are you adding printers in your script?
Yes
if your script is getting larger, you would do good if you considered adding some logging in to it, just a simple: run "%comspec% /c echo doing office registry mod %time% >> %temp%\logon.log" would suffice. add those lines after the parts and examine the log to see where it is taking the long time to execute. do remember to start your script with something like "echo logon start >" (instead of >>) so the log won't keep on accumulating in size.
One of the main pauses is where it's running a vBscript for our Outlook Signature (something I guess we're going to have to live with).
|
Top
|
|
|
|
#204119 - 2012-01-26 03:37 PM
Re: Speeding up Login process
[Re: BradV]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Brad - Notice that he's using RUN and not SHELL, so - while there's some brief delay to launch, these processes run asynchronously to the login script. Improves performance, but you can't tell if they are successful. The LoadHive() function is often overlooked and can load many reg values with a single command, similar to running "RegEdit /s file.reg" and could be used to eliminate the RUN commands entirely with little or no change to the REG file.
Sparkie - Calls to VB and other external processes all affect performance. It's crucial to bring as many processes internal as possible, and to not duplicate effort during each login. Group common processes together and only run all of them if one particular test fails whenever possible. For example - Test for "User Customization" - if the reg key is not present, do all user customization tasks, rather than individually testing for Outlook, Office, accounting, Acrobat, Flash, and whatever else might be in a per-user customization. Use a date rather than a boolean, and set a flag externally that defines the last time the user customization was changed. If the user's reg value is older than the external date, run all the updates.
I've spent a lot of time optimizing our login script, and it's been in service at many companies in one form or another since 1996. Our login script runs so fast I was asked to add a delay option. Timing our script with 5 drive and 3 printer mappings results in 0.88 seconds of process time(seven-eighths of a second). This includes the time to process various authorization tests to determine which of several resources should be mapped. Adding the Outlook signature refresh using the code from the vault adds another half-second.
Two key elements of our script are that all data is external to the script in an INI file, and all authorization is performed before any actions are actually processed. One way to optimize your code is to display (or log) the elapsed time, in milliseconds, at various points in your script. Here's an example:$STime = @TICKS ; place this at the top of the script
;
; script commands...
'Task - Elapsed: ' 1.0 * (@TICKS - $STime) / 1000.0 ' seconds' @CRLF
;
; more script commands, then repeat above to show cumulative time Insert the "Elapsed" line after each major code block, or after functions that you suspect are taking a long time. If you use my fMsg function, you can configure it so it will display these messages only when a DEBUG variable is set (or set to a specific value or greater). "Task" should represent the recently completed task, so the time between the prior and current tasks can be determined without guesswork.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#204136 - 2012-01-28 01:09 PM
Re: Speeding up Login process
[Re: Allen]
|
ChristopheM
Hey THIS is FUN
Registered: 2002-05-13
Posts: 309
Loc: STRASBOURG, France
|
an other point with inifile if you use some one for reading configuration ...
for one read in an inifile, the windows api loads all the file. if the file is on a local disk, the first read loads the file in the system cache. for next reads, the file is probably still in memory so no need to access to disk.
if the file is on a network share, there is no system cache. for each read you need to do, the all file is read through the network !!!
Suppose you have a file of 1024 bytes and you need to read 5 keys in a section : locally, the script reads 1024 bytes from disk one time and other reads get data from memory. through the network, the script reads 5 * 1024 bytes. This is always slower, especially if computers are on a WAN.
try the simple code below
$nb=100
Test( @scriptdir+"\"+@scriptname+".ini", $nb )
Test( "\\servername\sharename"+@scriptname+".ini", $nb )
function test( $inifile, $nb )
$handle = freefilehandle()
if open( $handle, $inifile, 1+4 )=0
$=WriteLine( $handle,"[OPTIONS]"+@crlf )
for $i=0 to $nb
$=WriteLine( $handle,""+$i+"=toto "+$i+@crlf )
next
$=close($handle)
endif
$start = @ticks
$arrKeys = ReadProfileString( $inifile, "OPTIONS", "" )
$arrkeys = split( $arrkeys, chr(10) )
for each $key in $arrKeys
if $key
$value = ReadProfileString( $inifile, "OPTIONS", $key )
endif
next
$start = @ticks - $start
"executed in " $start " ms" ?
del $inifile
endfunction This code generates a file of 1205 bytes and the difference is significant you can try differents ini file size by changing $nb.
Globally, it is a good thing to copy locally a remote inifile, then use local file. In my login script, i use robocopy or replace /u to get file locally (with these tools, copies are done only if files change). If you don't want to keep files locally, delete them after use.
_________________________
Christophe
|
Top
|
|
|
|
#204151 - 2012-01-30 05:54 PM
Re: Speeding up Login process
[Re: ChristopheM]
|
sparkie
Getting the hang of it
Registered: 2010-09-14
Posts: 92
Loc: UK
|
Thanks guys, some food for thought and good ideas.
I'm going over the Kix part first (before the vBscript runs) and change to use lookups such as registry return codes and the printer name pre-check.
For the timebeing, we're sticking with our Outlook vBscript because it works for us but maybe I could add some code for Kix to perform a lookup on the existing signature, whether it exists or if any changes....
....anyone got any ideas on that (I did try some code in the vB script but that sort of defeats the object).
|
Top
|
|
|
|
#204159 - 2012-01-31 10:18 AM
Re: Speeding up Login process
[Re: ShaneEP]
|
sparkie
Getting the hang of it
Registered: 2010-09-14
Posts: 92
Loc: UK
|
Thanks, we have three vBscript files. I have merged them into one file to see if there was a difference in time running and there wasn't.
The first (which is below) is our main default 'new message', we also have a reply one that omits the image and an International one with a different address and telephone number.
These sigantures get planted for domain users logging in using PC's and Terminal Server sessions.
I've also included after, some other code I was playing around with that checks for the signature folder and whether any changes have been made, though I don't think it works because if I delete the rtf file it's re-creating it.
' ######## New Signature ########
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
Set WshShell = CreateObject("WScript.Shell")
strUser = objSysInfo.UserName
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & strUser)
Set objGroup1 = GetObject("LDAP://cn=All RCDAs,ou=User Accounts,dc=our domain,dc=local")
Set objGroup2 = GetObject("LDAP://cn=All National Office,ou=User Accounts,dc=<our domain>,dc=local")
'map Active Directory objUser to str names'
strName = objUser.FullName
strNotes = objuser.Info
strTitle = objUser.Title
strPhone = objUser.TelephoneNumber
strMobile = objUser.Mobile
strEmail = objUser.mail
'set pointers for image insertion with linked URL'
sPicFile = "\\ARTIC\Office2007ProPlus\Scripts\edin4.png"
sLinkFile = "http://www.our domain.org/blah.html"
'Use Word (required) to create the format'
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
objSelection.Style = "No Spacing"
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
'If you get problems with line spacing, use vbNewline instead of Chr(11)'
'Select what is displayed in the Signature based upon the str to ObjUser mappings above'
objSelection.Font.Bold = True
'objSelection.Font.Name = "Arial"
objSelection.Font.Size = 11
'if (strCred) Then objSelection.TypeText strName & ", " & strCred Else objSelection.TypeText strName & Chr(32) & strNotes & Chr(11)
'if (strName) Then objSelection.TypeText strName & ", " & strNotes & Chr(11)
if (strName) Then objSelection.TypeText strName & strNotes & Chr(11)
objSelection.Font.Bold = False
objSelection.TypeText strTitle & Chr(11)
objSelection.TypeText "Our company name" & Chr(11)
' If member of AD group All National Office (as defined above) then plant National Office address
if (objGroup2.IsMember(objUser.AdsPath) = True) Then
objSelection.TypeText "PO Box address here" & Chr(11)
else
'display nothing
end if
' If Telephone number is populated in AD then set and plant Internationally defined number (lines 1 and 2 are only required for the International Signature)
'strPhone = right(strPhone,len(strPhone)-1) 'strips off left most digit
'strPhone = "+44 " & strPhone
if (objUser.TelephoneNumber) Then objSelection.TypeText "DD: " & strPhone & Chr(11)
' if member of AD group RCDS's (as defined above) do nothing, otherwise plant Mobile number
'if (objGroup1.IsMember(objUser.AdsPath) = True) Then
' CHR(11)
'else
' if (strMobile) Then objSelection.TypeText "Mobile: " & strMobile & Chr(11)
'end if
if (strMobile) Then objSelection.TypeText "Mobile: " & strMobile & Chr(11)
objSelection.Hyperlinks.Add objSelection.Range, "http://www.our domain",, "Our company Homepage", "www.our domain"
With objDoc.Styles("Hyperlink").Font
.Name = "Arial"
.Bold = False
'.Underline = wdUnderlineNone
.Color = RGB(227,114,34)
End With
objSelection.TypeParagraph()
objSelection.TypeParagraph()
Set objShape1 = objSelection.InlineShapes.AddPicture(sPicFile, True)
objDoc.Hyperlinks.Add objShape1.Range, sLinkFile
'add the entire range of what you want displayed and set the global font'
Set objSelection = objDoc.Range()
objSelection.Font.Name = "Arial"
'Add a siganture entry, name it and assign to new message'
objSignatureEntries.Add "Full Signature", objSelection
objSignatureObject.NewMessageSignature = "Full Signature"
'Save the content and exit'
objDoc.Saved = True
objWord.Quit
----------------------------------------
Other code I've been working on.
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
Set UserObj = GetObject("LDAP://" & objADSysInfo.UserName)
' work in progress check signature existence and exit if exist or not changed
strAppData = WshShell.ExpandEnvironmentStrings("%APPDATA%")
SigFolder = StrAppData & "\Microsoft\Signatures\"
strQuteChr = chr(34)
SigFile = SigFolder & UserObj.sAMAccountName & ".htm"
'check existence of signature folder, if not exist create it
if not FileSysObj.FolderExists(SigFolder) then
FileSysObj.CreateFolder(SigFolder)
end if
if FileSysObj.FileExists(SigFile) then
'get amended date of file, then compare it to the changed date of the user
Set objFile = FileSysObj.GetFile(SigFile)
datSigAlt = objFile.DateLastModified
intTimeDiff = DateDiff("n", datSigAlt, UserObj.whenChanged)
'if the difference is less than 0 then we do not need to do anything as the sig file is uptodate
if intTimeDiff < 0 then wscript.Quit
end if
'end work in progress
Edited by Mart (2012-01-31 04:01 PM) Edit Reason: Please use code tags when posting code.
|
Top
|
|
|
|
#204187 - 2012-02-02 12:52 PM
Re: Speeding up Login process
[Re: Mart]
|
sparkie
Getting the hang of it
Registered: 2010-09-14
Posts: 92
Loc: UK
|
Well, I've started the conversion process of my vBscript to Kix. It's steady progress but at least in the longrun it will detract from the 'bandit' vB comments.
|
Top
|
|
|
|
#204188 - 2012-02-02 05:20 PM
Re: Speeding up Login process
[Re: sparkie]
|
sparkie
Getting the hang of it
Registered: 2010-09-14
Posts: 92
Loc: UK
|
Ok, this one is posing problems, I'm using Code...
$objLink = $objSelection.Hyperlinks.Add($objSelection.Range....
but cannot change the font colour, I've tried various methods but it isn't having it.
Edited by sparkie (2012-02-02 05:21 PM)
|
Top
|
|
|
|
#204194 - 2012-02-03 12:49 PM
Re: Speeding up Login process
[Re: Mart]
|
sparkie
Getting the hang of it
Registered: 2010-09-14
Posts: 92
Loc: UK
|
Thanks Mart, I sorted it this morning, though I used your little trick of converting the RGB color to Kix (Word interpretation) using the Macro Recording.
I used this code in the end.
$objLink = $objSelection.Hyperlinks.Add($objSelection.Range,"http://www.domain.org",, "company name", "www.domain.org")
$objLink.Range.Font.Color = "2257635"
Getting there but still got a couple of issues which I'm trying to persist with before asking.
Edited by sparkie (2012-02-03 12:51 PM)
|
Top
|
|
|
|
#204195 - 2012-02-03 03:50 PM
Re: Speeding up Login process
[Re: sparkie]
|
sparkie
Getting the hang of it
Registered: 2010-09-14
Posts: 92
Loc: UK
|
Ok, trying to covert this vB to Kix.
Set objGroup2 = GetObject("LDAP://cn=a_group,ou=User Accounts,dc=<domain>,dc=local")
if (objGroup2.IsMember(objUser.AdsPath) = True) Then
objSelection.TypeText "text here" & Chr(11)
else
'display nothing
end if
I've tried this
IF INGROUP("???")
objSelection.TypeText.....
and numerous other permitations but no go.
|
Top
|
|
|
|
#204196 - 2012-02-03 05:00 PM
Re: Speeding up Login process
[Re: sparkie]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
You may need to list what you tried or what kind of account you are using.... it should be as simple as putting in the Group Name, however if you are looking for a computer in a group, that requires another UDF.
for a user...
if ingroup("Domain Users")
;do stuff
endif
|
Top
|
|
|
|
#204213 - 2012-02-06 02:11 PM
Re: Speeding up Login process
[Re: Allen]
|
sparkie
Getting the hang of it
Registered: 2010-09-14
Posts: 92
Loc: UK
|
Can't remember what I tried, too many things to try and recall. Here's an example of what should work, but doesn't
IF ingroup("usergroup")
$objSelection.TypeText("TEXT")
ELSE
?
ENDIF
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 515 anonymous users online.
|
|
|