#163736 - 2006-06-27 05:53 PM
Critique my login script please!
|
Mstudinski
Fresh Scripter
Registered: 2006-05-19
Posts: 25
|
I am new at this so please be gentle. This is a revised version. Sorry for the delay in responding.. Things got crazy at my job. This is what is happening. Nothing is being logged even though it should be. I run a debug on the code and don't get any error's back. It must be a logic problem. All the drives map sucessfully and if the file it is writing to does not exist it will create the file but not write lines to it.
Thanks in advance..
Matt Code:
Break On Dim $vDiscard $vDiscard=SetOption('Explicit','On') $vDiscard=SetOption('NoVarsInStrings','On') $vDiscard=SetOption('NoMacrosInStrings','On') ;$vDiscard=SetConsole("HIDE") ;User Cannot See Script Running Dim $LFile, $SFile, $LVersion, $SVersion, $Msg, $FFile Dim $LPNAFile, $SPNAFile, $LPNAVersion, $SPNAVersion Dim $IcaClientName Dim $DefaultFiles Dim $sKey $sKey=@MONTH+@MDAYNO+@YEAR ; SKip this script for service accounts
If InGroup ("No Login Scripts") Exit 0 EndIf
;Don't run on CTX Servers
If @WKSTA = "VPOINT6CTX1" or @WKSTA = "VPOINT6CTX2" Exit 0 EndIf
; Check for ODBC Shell "%logonserver%\netlogon\netlogonODBC.bat" ; Check Citrix client versions where installed If KeyExist("HKEY_LOCAL_MACHINE\SOFTWARE\CITRIX") $LFile = "C:\Program Files\Citrix\Ica Client\pn.exe" ;Client Citrix Client Location $LVersion = GetFileVersion($LFile,'BinFileVersion') ;Client Citrix Client Version $SFile = "\\tctunicenter\ctx$\pn.exe" ;Compare Client Citrix Version to this file $SVersion = GetFileVersion($SFile,'BinFileVersion') If @ERROR popMessage('Error getting pn.exe file information: ' + @ERROR + ' - ' + @SERROR) EndIf If $SVersion <> $LVersion $vDiscard=Log("\\tctunicenter\ctx$\citrix\"+$sKey+"_ICACLIENTVERSION.TXT"," has old ica client version "+$LVersion) EndIf $LPNAFile = "C:\Program Files\Citrix\Ica Client\pnagent.exe" ;Client Citrix PNA Location $LPNAVersion = GetFileVersion($LPNAFile,'BinFileVersion') ;Client Citrix CLient PNA Version $SPNAFile = "\\tctunicenter\ctx$\pnagent.exe" ;Compare Client Citrix PNA Version to this file $SPNAVersion = GetFileVersion($SPNAFile,'BinFileVersion') If @ERROR popMessage('Error getting pnagent.exe file information: ' + @ERROR + ' - ' + @SERROR) EndIf If $SPNAVersion == $LPNAVersion $vDiscard=Log("\\tctunicenter\ctx$\citrix\"+$sKey+"_PNA.TXT"," has PNA Installed and it is version " + $LPNAVersion) EndIf $IcaClientName = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\ICA Client", "ClientName") If @ERROR = 0 $vDiscard=Log("\\tctunicenter\ctx$\citrix\"+$sKey+"_ICACLIENTNAME.TXT"," has a static client name and it is "+$IcaClientName) Endif EndIf If Not Exist("C:\Program Files\CA\Unicenter Software Delivery\BIN\sdconf.exe") $vDiscard=Log("\\tctunicenter\ctx$\CA\"+$sKey+"unisoftdelivery.txt"," does not have CA Software Delivery Installed") EndIf If Not Exist("C:\Program Files\CA\Unicenter Asset Management\Agents\UMCLIWNT.EXE") $vDiscard=Log("\\tctunicenter\ctx$\CA\"+$sKey+"uniassman.TXT" , " does not have CA Asset Management Installed") EndIf If @Producttype = "Windows XP Professional" or @Producttype = "Windows 2000 Professional" $DefaultFiles=ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Personal") If @ERROR = 0 If $DefaultFiles <> "U:\" Log("\\tctunicenter\ctx$\office\"+@MONTH+@MDAYNO+@YEAR+"_DefaultFiles.TXT"," has a defined file location other than U:\ and it is "+$DefaultFiles) Endif EndIf ; Skipping drives for Domain Admins group ; If InGroup ("Domain Admins") Exit 0 EndIf If InGroup("Metafile") OR InGroup("Metafile Users") Use O: /Delete /Persistent Use Z: /Delete /Persistent Use o: "\\tctmetafile\e" Use z: "\\tctmetafile\z" EndIf If InGroup ("CT Credit") Use J: /Delete /Persistent Use j: "\\bituminous\credit" EndIf If InGroup ("Heavy & Highway") Use L: /Delete /Persistent Use l: "\\tcthcss\data" EndIf If InGroup ("Concrete Plants") Use X: /Delete /Persistent Use x: "\\tctcdi1\e" EndIf If InGroup ("Infohub Users") Use g: /Delete /Persistent Use g: "\\tctinfohub\BmgSeltec" Use i: /Delete /Persistent Use i: "\\tctinfohub\DataXfer" EndIf If InGroup ("Niche Bid2Win") Use y: /Delete /Persistent Use y: "\\ct_bid2win\bid2win" EndIf If InGroup ("Tilcon CT - Safety") Use s: /Delete /Persistent Use s: "\\tctcorp01\safety" EndIf Exit 0 ; ---------------------------------------------------------------------- ; Logical end of script ; ---------------------------------------------------------------------- ; Log status messages to file Function Log($sPath,$sMessage) Dim $fh $Log=0 $fh=FreeFileHandle() If @ERROR $Log=@ERROR popMessage("Cannot allocate file handle for file open") Else If Open($fh,$sPath,1+4) $Log=@ERROR popMessage("Failed to open file '"+$sPath+@CRLF+"Error code : [" + @ERROR + "] "+@SERROR) $vDiscard=WriteLine($fh,@TIME+" "+@DATE+" "+@WKSTA+$sMessage+@CRLF) $vDiscard=Close($fh) EndIf EndIf Exit $Log EndFunction ; Display pop-up message Function popMessage($sMessage) $popMessage=MessageBox($sMessage,@SCRIPTNAME+" Warning",0+64+4096,10) EndFunction
Exit
Edited by Mstudinski (2006-07-10 09:14 PM)
|
|
Top
|
|
|
|
#163737 - 2006-06-28 08:50 AM
Re: Critique my login script please!
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Hah, GOTO is bad 
No, seriously, you can prevent these GOTOs quite easily to make your script easier to understand for yourself and others.
For example this :
Code:
If NOT something() goto "next" EndIf
code for something=true . . . . . . . . . :next
is more readable(due to indentation) like this:
Code:
If NOT something() code for something=true . . . . . . . Endif
This is also unneccessary : Code:
If @PRODUCTSUITE = "Terminal Server" ;Skipping Servers goto "exit" EndIf
better: Code:
If @PRODUCTSUITE = "Terminal Server" exit 0 EndIf
Note the exit code, this is to prevent EXIT to return rubbish to calling scripts, maybe causing expression errors, as EXIT does return the following code anytime!
Code:
OPEN ( .... WRITELINE ( .... Close(...
No big deal in this case as you hide the console, but unsilenced function calls will display the return codes in the console, so consider the habit of assigning function calls to dummy variables.
Code:
ELSE BEEP ? "failed to open file, error code : [" + @ERROR + "]" ENDIF
err, your console is set to be hidden, so what's this for ?
_________________________
|
|
Top
|
|
|
|
#163738 - 2006-06-28 11:28 AM
Re: Critique my login script please!
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
GoTo very bad.
Rewriting the same bit of code over and over again is also not good - I'm sure you could be doing something better with your time. Use functions - they save a lot of typing and mean that if you want to change something you only need to do it once.
I've tidied the script up, used functions for common code, used pop-up windows for error message and a bunch of other stuff.
The script is untested, so I apologise in advance for any typos: Code:
Break On Dim $vDiscard $vDiscard=SetOption('Explicit','On') $vDiscard=SetOption('NoVarsInStrings','On') $vDiscard=SetOption('NoMacrosInStrings','On') $vDiscard=SetConsole("HIDE") ;User Cannot See Script Running ; Don't run script for Terminal Server logins If @PRODUCTSUITE = "Terminal Server" Exit 0 EndIf Dim $LFile, $SFile, $LVersion, $SVersion, $Msg, $FFile Dim $LPNAFile, $SPNAFile, $LPNAVersion, $SPNAVersion Dim $IcaClientName Dim $DefaultFiles Dim $sKey $sKey=@MONTH+@MDAYNO+@YEAR ; Check for ODBC Shell "%logonserver%\netlogon\netlogonODBC.bat" ; Check Citrix client versions where installed If KeyExist("HKEY_LOCAL_MACHINE\SOFTWARE\CITRIX") $LFile = "C:\Program Files\Citrix\Ica Client\pn.exe" ;Client Citrix Client Location $LVersion = GetFileVersion($LFile,'BinFileVersion') ;Client Citrix Client Version $SFile = "\\tctunicenter\ctx$\pn.exe" ;Compare Client Citrix Version to this file $SVersion = GetFileVersion($SFile,'BinFileVersion') If @ERROR popMessage('Error getting pn.exe file information: ' + @ERROR + ' - ' + @SERROR) EndIf If $SVersion <> $LVersion $vDiscard=Log("\\server\ctx$\citrix\"+$sKey+"_ICACLIENTVERSION.TXT"," has old ica client version "+$LVersion) EndIf $LPNAFile = "C:\Program Files\Citrix\Ica Client\pnagent.exe" ;Client Citrix PNA Location $LPNAVersion = GetFileVersion($LPNAFile,'BinFileVersion') ;Client Citrix CLient PNA Version $SPNAFile = "\\server\ctx$\pnagent.exe" ;Compare Client Citrix PNA Version to this file $SPNAVersion = GetFileVersion($SPNAFile,'BinFileVersion') If @ERROR popMessage('Error getting pnagent.exe file information: ' + @ERROR + ' - ' + @SERROR) EndIf If $SPNAVersion == $LPNAVersion $vDiscard=Log("\\server\ctx$\citrix\"+$sKey+"_PNA.TXT"," has PNA Installed and it is version " + $LPNAVersion) EndIf $IcaClientName = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\ICA Client", "ClientName") If @ERROR = 0 $vDiscard=Log("\\server\ctx$\citrix\"+$sKey+"_ICACLIENTNAME.TXT"," has a static client name and it is "+$IcaClientName) Endif EndIf If Not Exist("C:\Program Files\CA\Unicenter Software Delivery\BIN\sdconf.exe") $vDiscard=Log("\\server\ctx$\CA\"+$sKey+"unisoftdelivery.txt"," does not have CA Software Delivery Installed") EndIf If Not Exist("C:\Program Files\CA\Unicenter Asset Management\Agents\UMCLIWNT.EXE") $vDiscard=Log("\\server\ctx$\CA\"+$sKey+"uniassman.TXT"," does not have CA Asset Management Installed") EndIf If @Producttype = "Windows XP Professional" or @Producttype = "Windows 2000 Professional" $DefaultFiles=ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Personal") If @ERROR = 0 If $DefaultFiles <> "U:\" Log("\\server\ctx$\office\"+@MONTH+@MDAYNO+@YEAR+"_DefaultFiles.TXT"," has a defined file location other than U:\ and it is "+$DefaultFiles) Endif EndIf EndIf ; Skipping drives for Domain Admins group If InGroup ("Domain Admins") Exit 0 EndIf If InGroup("Metafile") OR InGroup("Metafile Users") Use O: /Delete /Persistent Use Z: /Delete /Persistent Use o: "\\tctmetafile\e" Use z: "\\tctmetafile\z" EndIf If InGroup ("CT Credit") Use J: /Delete /Persistent Use j: "\\bituminous\credit" EndIf If InGroup ("Heavy & Highway") Use L: /Delete /Persistent Use l: "\\tcthcss\data" EndIf If InGroup ("Concrete Plants") Use X: /Delete /Persistent Use x: "\\tctcdi1\e" EndIf Exit 0 ; ---------------------------------------------------------------------- ; Logical end of script ; ---------------------------------------------------------------------- ; Log status messages to file Function Log($sPath,$sMessage) Dim $fh $Log=0 $fh=FreeFileHandle() If @ERROR $Log=@ERROR popMessage("Cannot allocate file handle for file open") Else If Open($fh,$sPath,1+4) $Log=@ERROR popMessage("Failed to open file '"+$sPath+@CRLF+"Error code : [" + @ERROR + "] "+@SERROR) $vDiscard=WriteLine($fh,@TIME+" "+@DATE+" "+@WKSTA+$sMessage+@CRLF) $vDiscard=Close($fh) EndIf EndIf Exit $Log EndFunction ; Display pop-up message Function popMessage($sMessage) $popMessage=MessageBox($sMessage,@SCRIPTNAME+" Warning",0+64+4096,10) EndFunction
|
|
Top
|
|
|
|
#163739 - 2006-06-28 04:22 PM
Re: Critique my login script please!
|
ChristopheM
Hey THIS is FUN
   
Registered: 2002-05-13
Posts: 311
Loc: STRASBOURG, France
|
you can also use functions so that the main script is more readable. It's also a good solution to "dim" variables only where they are needed Code:
;---------------------------------------------------------- ; begin of the main script ;---------------------------------------------------------- Break On InitializeGlobalOptionsAndVars() CheckForODBC() CheckForCitrix() CheckForCASoftware() MapDrive() exit 0 ;---------------------------------------------------------- ; end of the main script ;----------------------------------------------------------
;---------------------------------------------------------- ; List of main script functions ;---------------------------------------------------------- function InitializeGlobalOptionsAndVars() Dim $ $=SetOption('Explicit','On') $=SetOption('NoVarsInStrings','On') $=SetOption('NoMacrosInStrings','On') $=SetConsole("HIDE") ;User Cannot See Script Running ; Don't run script for Terminal Server logins If @PRODUCTSUITE = "Terminal Server" Quit 0 EndIf endfunction
function CheckForODBC() Dim $..... Shell "%logonserver%\netlogon\netlogonODBC.bat" endfunction function CheckForCitrix() Dim $..... If not KeyExist("HKEY_LOCAL_MACHINE\SOFTWARE\CITRIX") exit 0 endif $LFile = "C:\Program Files\Citrix\Ica Client\pn.exe" ;Client Citrix Client Location $LVersion = GetFileVersion($LFile,'BinFileVersion') ;Client Citrix Client Version $SFile = "\\tctunicenter\ctx$\pn.exe" ;Compare Client Citrix Version to this file $SVersion = GetFileVersion($SFile,'BinFileVersion') If @ERROR popMessage('Error getting pn.exe file information: ' + @ERROR + ' - ' + @SERROR) EndIf If $SVersion <> $LVersion $vDiscard=Log("\\server\ctx$\citrix\"+$sKey+"_ICACLIENTVERSION.TXT"," has old ica client version "+$LVersion) EndIf $LPNAFile = "C:\Program Files\Citrix\Ica Client\pnagent.exe" ;Client Citrix PNA Location $LPNAVersion = GetFileVersion($LPNAFile,'BinFileVersion') ;Client Citrix CLient PNA Version $SPNAFile = "\\server\ctx$\pnagent.exe" ;Compare Client Citrix PNA Version to this file $SPNAVersion = GetFileVersion($SPNAFile,'BinFileVersion') If @ERROR popMessage('Error getting pnagent.exe file information: ' + @ERROR + ' - ' + @SERROR) EndIf If $SPNAVersion == $LPNAVersion $vDiscard=Log("\\server\ctx$\citrix\"+$sKey+"_PNA.TXT"," has PNA Installed and it is version " + $LPNAVersion) EndIf $IcaClientName = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\ICA Client", "ClientName") If @ERROR = 0 $vDiscard=Log("\\server\ctx$\citrix\"+$sKey+"_ICACLIENTNAME.TXT"," has a static client name and it is "+$IcaClientName) Endif endfunction function CheckForCASoftware() Dim $..... If Not Exist("C:\Program Files\CA\Unicenter Software Delivery\BIN\sdconf.exe") $vDiscard=Log("\\server\ctx$\CA\"+$sKey+"unisoftdelivery.txt"," does not have CA Software Delivery Installed") EndIf If Not Exist("C:\Program Files\CA\Unicenter Asset Management\Agents\UMCLIWNT.EXE") $vDiscard=Log("\\server\ctx$\CA\"+$sKey+"uniassman.TXT"," does not have CA Asset Management Installed") EndIf endfunction function MapDrive() Dim $.....
; Skipping drives for Domain Admins group If InGroup ("Domain Admins") Exit 0 EndIf If InGroup("Metafile") OR InGroup("Metafile Users") Use O: /Delete /Persistent Use Z: /Delete /Persistent Use o: "\\tctmetafile\e" Use z: "\\tctmetafile\z" EndIf If InGroup ("CT Credit") Use J: /Delete /Persistent Use j: "\\bituminous\credit" EndIf If InGroup ("Heavy & Highway") Use L: /Delete /Persistent Use l: "\\tcthcss\data" EndIf If InGroup ("Concrete Plants") Use X: /Delete /Persistent Use x: "\\tctcdi1\e" EndIf endfunction
;---------------------------------------------------------- ; List of utility functions ;---------------------------------------------------------- ; Log status messages to file Function Log($sPath,$sMessage) Dim $fh $Log=0 $fh=FreeFileHandle() If @ERROR $Log=@ERROR popMessage("Cannot allocate file handle for file open") Else If Open($fh,$sPath,1+4) $Log=@ERROR popMessage("Failed to open file '"+$sPath+@CRLF+"Error code : [" + @ERROR + "] "+@SERROR) $vDiscard=WriteLine($fh,@TIME+" "+@DATE+" "+@WKSTA+$sMessage+@CRLF) $vDiscard=Close($fh) EndIf EndIf Exit $Log EndFunction ; Display pop-up message Function popMessage($sMessage) $popMessage=MessageBox($sMessage,@SCRIPTNAME+" Warning",0+64+4096,10) EndFunction
Take care with my code. I haven't "dim" variables in the functions. So, comment the setconsole line, debug the script and uncomment the setconsole line when the script is OK.
_________________________
Christophe
|
|
Top
|
|
|
|
#163740 - 2006-06-29 12:48 AM
Re: Critique my login script please!
|
Mstudinski
Fresh Scripter
Registered: 2006-05-19
Posts: 25
|
Thanks for the input. I'll be back at work tommorow to test these.
Thanks again
Matt
|
|
Top
|
|
|
|
#163742 - 2006-06-29 08:44 PM
Re: Critique my login script please!
|
Mstudinski
Fresh Scripter
Registered: 2006-05-19
Posts: 25
|
I have been testing this script (I used a slightly modified version of Richards) and for some reason it is still running on Citrix boxes. (Both Windows 2000 and 2003 server on PS4) Any ideas? I shouldn't have to use IF @WKSTA = CitrixServerName should I?
|
|
Top
|
|
|
|
#163745 - 2006-06-30 09:23 AM
Re: Critique my login script please!
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
I have been testing this script (I used a slightly modified version of Richards) and for some reason it is still running on Citrix boxes. (Both Windows 2000 and 2003 server on PS4) Any ideas? I shouldn't have to use IF @WKSTA = CitrixServerName should I?
No, but you do have to use the macros correctly 
@PRODUCTSUITE returns a number which is the sum of all the possible values. For example a "DataCenter" (128) edition of "Terminal Server" (16) would return (128+16)=144 - if there is any such thing.
The check that you need to be making is: Code:
If 16 & @PRODUCTSUITE "Terminal Server" EndIf
Personally I check %WINSTATIONNAME%, as I perform different processing depending on whether the connection is "RDP-xxx" (terminal server) or "ICA-xxx" (Citrix)
|
|
Top
|
|
|
|
#163747 - 2006-06-30 03:43 PM
Re: Critique my login script please!
|
Mstudinski
Fresh Scripter
Registered: 2006-05-19
Posts: 25
|
Quote:
The check that you need to be making is: Code:
If 16 & @PRODUCTSUITE "Terminal Server" EndIf
Ok.. that part is fixed. Thanks! Now I am having a problem that it is not running on Windows 2000 SP4 Domain PC's and only running parts on the XP machines. I have made GPO changes as needed for waiting for the network to be ready before logging on.. Any ideas?
|
|
Top
|
|
|
|
#163748 - 2006-06-30 03:54 PM
Re: Critique my login script please!
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
Now I am having a problem that it is not running on Windows 2000 SP4 Domain PC's
What is @PRODUCTSUITE on these machines?
Quote:
and only running parts on the XP machines
Well we could guess which parts don't work, but it would make it easier if you told us.
Run through the script on non-working computers in debug mode to see what is happening, then post your entire script and tell us which bits don't work.
|
|
Top
|
|
|
|
#163750 - 2006-07-10 09:14 PM
Re: Critique my login script please!
|
Mstudinski
Fresh Scripter
Registered: 2006-05-19
Posts: 25
|
Updated my code with the problems I am having with it. Please see top post.
Thanks!
Matt
|
|
Top
|
|
|
|
#163751 - 2006-07-17 03:40 PM
Re: Critique my login script please!
|
Mstudinski
Fresh Scripter
Registered: 2006-05-19
Posts: 25
|
Anyone?
Thanks
Matt
|
|
Top
|
|
|
|
#163753 - 2006-07-17 06:17 PM
Re: Critique my login script please!
|
Mstudinski
Fresh Scripter
Registered: 2006-05-19
Posts: 25
|
That's my problem. It doesn't log anything.
|
|
Top
|
|
|
|
#163754 - 2006-07-18 03:22 AM
Re: Critique my login script please!
|
Gargoyle
MM club member
   
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
Have you checked what the return values of your IF statements? are any of them returning what is expected to fire the Log() function?
ex: Code:
? "SVersion = "$SVersion ? "LVersion = "$LVersion
If $SVersion <> $LVersion $vDiscard=Log("\\server\ctx$\citrix\"+$sKey+"_ICACLIENTVERSION.TXT"," has old ica client version "+$LVersion) EndIf
|
|
Top
|
|
|
|
#163755 - 2006-07-20 04:42 PM
Re: Critique my login script please!
|
Mstudinski
Fresh Scripter
Registered: 2006-05-19
Posts: 25
|
Good call Gargoyle. Thanks a lot. I figured it out.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1050 anonymous users online.
|
|
|