; GLOBAL VARIABLE DEFINITION
$homedrive = "G:\"
$printsetlocation = "\\storage\clients\"
; Use the workstation name to determine printserver
IF Left(@WKSTA, 5) = "55PUL"
$printserver = "\\print2\"
Else
$printserver = "\\print\"
Endf
; LOGON.LOG creation
; Creates a log file (logon.log) in a user's home directory with the date and time of logon, userid,
; client name logged on to. Logs mapped drives, printers connected and errors
; Create a backup copy of the last log, delete the last backup
IF EXIST($homedrive + "logon.log")
IF EXIST($homedrive + "logon.bak")
DEL $homedrive + "logon.bak"
ENDIF
MOVE $homedrive + "logon.log" $homedrive + "logon.bak"
ENDIF
; Obtain an available file handle
$logfilehandle = FreeFileHandle()
; Use handle to open logfile
If OPEN($logfilehandle,$homedrive + "\logon.log",5) <> 0
; If unable to open/create a log file that would probably indicate a permissions issue with a user's home drive
; Display a message and force user interaction.
? "Unable to open log file."
? "There may be a problem with your home drive. Please contact Information Systems"
? "Hit a key to continue"
?
get $nul ; pauses till a key is pressed
EXIT 1
ENDIF
$nul = WRITELINE($logfilehandle, @DATE + " " + @TIME + @CRLF)
$nul = WRITELINE($logfilehandle, "UserID: " + @USERID + " " + "Client Name: " + %clientname% + @CRLF)
; MAP NETWORK DRIVES
IF INGROUP("Information Systems")
Mapdrive ("H:", "\\storage\is",$logfilehandle)
ENDIF
IF INGROUP ("pcon")
Mapdrive ("P:", "\\pcon\cmapp",$logfilehandle)
ENDIF
IF INGROUP("Network Admins")
Mapdrive ("I:", "\\storage\network",$logfilehandle)
ENDIF
IF INGROUP("OrSchdRpt") OR INGROUP("Information Systems")
Mapdrive ("S:", "\\orsos\orsos",$logfilehandle)
ENDIF
IF INGROUP("Systoc")
Mapdrive ("T:", "\\ohrsystoc\systoc71",$logfilehandle)
ENDIF
IF INGROUP("Kronos")
Mapdrive ("J:", "\\kronos\kronos",$logfilehandle)
ENDIF
IF INGROUP("MRDATA")
Mapdrive ("M:", "\\mhsprint\mr-data",$logfilehandle)
ENDIF
IF INGROUP("nrmi")
Mapdrive ("R:", "\\mhsprint\nrmi",$logfilehandle)
ENDIF
IF INGROUP("App - Nebo")
Mapdrive ("x:", "\\nebo\nebo",$logfilehandle)
ENDIF
IF INGROUP("MapFDrive")
Mapdrive ("f:", "\\client\f$",$logfilehandle)
ENDIF
IF INGROUP("MSSO")
Mapdrive ("T:", "\\MSSO\MSSO",$logfilehandle)
ENDIF
IF INGROUP("PeerReview")
Mapdrive ("R:", "\\storage\Peerreview",$logfilehandle)
ENDIF
; MAP PRINTERS
; Open Printset.INI from $printsetlocation\%clientname%
; If The FileExist variable is 2, that means the file does not exist. Display an error message
; Obtain available file handle for printer file
$printerfilehandle = FreeFileHandle()
; Use file handle to open printer file
IF OPEN($printerfilehandle, $printsetlocation + %clientname% + "\printset.ini") = 2
? "No Printer Mapping File found"
$nul = WRITELINE($logfilehandle, "No Printer Mapping File found" + @CRLF)
$nul = CLOSE($logfilehandle)
Exit 0
ENDIF
; Read and discard the first 9 lines of the file
FOR $count = 1 TO 9
$nextline = READLINE($printerfilehandle)
NEXT
; Read the next line of the file which will be the default printer if it exists
$nextline = READLINE($printerfilehandle)
; The printset.ini has 9 lines of text description and then the following 5 lines look like
; Printer1 = 00is-lan
; Printer2 = 00is-ops
$printer = Trim(Split($nextline,"=")[1])
; a VARTYPE of 8 means that the value of $printer is a string, try to map the printer
IF VARTYPE($printer) = 8
IF AddPrinterConnection($printserver + $printer) = 0
WRITELINE($logfilehandle, "Mapped Default Printer to " + $printserver + $printer + @CRLF)
; The SetDefaultPrinter command relies on the printer NAME not the printer SHARE
$nul = SetDefaultPrinter($printserver + $printer)
ELSE
$nul = WRITELINE($logfilehandle, "An error occurred mapping the Default Printer to " + $printserver + $printer +@CRLF)
ENDIF
ENDIF
; Read the next 4 lines of the file and concatenate them. Check to see if they are empty.
FOR $count = 1 TO 4
$nextline = READLINE($printerfilehandle)
$printer = Trim(Split($nextline,"=")[1])
IF VARTYPE($printer) = 8
IF AddPrinterConnection($printserver + $printer) = 0
$nul = WRITELINE($logfilehandle,"Created a Printer Connection to " + $printserver + $printer + @CRLF)
ELSE
$nul = WRITELINE($logfilehandle,"An error occurred creating a printer connection to " + $printserver + $printer + @CRLF)
ENDIF
ENDIF
NEXT
$nul = CLOSE($printerfilehandle)
;Setup PCON application
IF INGROUP("Pcon") OR INGROUP("Helpdesk")
$pw = %clientname% + %username%
$bivstak = substr($pw,1,10)
shell "c:\logon\setx.exe bivstak " + $bivstak
IF EXIST ("G:\WINDOWS\CMTEMPDB.MDB") = 0
COPY "c:\LOGON\PATHWAYS\CMTEMPDB.MDB" "G:\WINDOWS\CMTEMPDB.MDB"
ENDIF
ENDIF
;Close Log File
$nul = CLOSE($logfilehandle)
FUNCTION MapDrive ($drive,$drivepath,$fh)
USE $drive /DELETE
USE $drive $drivepath
IF (@ERROR = 0)
$nul = WRITELINE($fh, "Mapped Drive " + $drive + " to " + $drivepath + @CRLF)
ELSE
$nul = WRITELINE($fh, "An error occurred when mapping drive " + $drive + " to " + $drivepath + @CRLF)
ENDIF
ENDFUNCTION