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.