#202949 - 2011-08-23 04:39 PM
Re: alternate command
[Re: Allen]
|
mtnclimber
Fresh Scripter
Registered: 2011-05-27
Posts: 11
Loc: Chicago, Il
|
Im not a code guy
I don't know how to step thru
This is the full script
; GLOBAL VARIABLE DEFINITION
$homedrive = "G:\"
$printserver = "\\print\"
$printserver2 = "\\print2\"
$printsetlocation = "\\storage\clients\"
; 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
$logopen = OPEN(5,$homedrive + "\logon.log",5)
If ($logopen <> 0)
GOTO Logerror
ENDIF
;? "Logopen is " + $logopen
WRITELINE(5, @DATE + " " + @TIME + @CRLF)
WRITELINE(5, "UserID: " + @USERID + " " + "Client Name: " + %clientname% + @CRLF)
; MAP NETWORK DRIVES
IF INGROUP("Information Systems")
Mapdrive ("H:", "\\storage\is")
ENDIF
IF INGROUP ("pcon")
Mapdrive ("P:", "\\pcon\cmapp")
ENDIF
IF INGROUP("Network Admins")
Mapdrive ("I:", "\\storage\network")
ENDIF
IF (INGROUP("OrSchdRpt") OR INGROUP("Information Systems"))
Mapdrive ("S:", "\\orsos\orsos")
ENDIF
IF INGROUP("Systoc")
Mapdrive ("T:", "\\ohrsystoc\systoc71")
ENDIF
IF INGROUP("Kronos")
Mapdrive ("J:", "\\kronos\kronos")
ENDIF
IF INGROUP("MRDATA")
Mapdrive ("M:", "\\mhsprint\mr-data")
ENDIF
IF INGROUP("nrmi")
Mapdrive ("R:", "\\mhsprint\nrmi")
ENDIF
IF INGROUP("App - Nebo")
Mapdrive ("x:", "\\nebo\nebo")
ENDIF
IF INGROUP("MapFDrive")
Mapdrive ("f:", "\\client\f$")
ENDIF
IF INGROUP("MSSO")
Mapdrive ("T:", "\\MSSO\MSSO")
ENDIF
IF INGROUP("PeerReview")
Mapdrive ("R:", "\\storage\Peerreview")
ENDIF
; MAP PRINTERS
; Open Printset.INI from $printsetlocation\%clientname%, store error code into variable
; FileExist
$FileExist = OPEN(1, $printsetlocation + %clientname% + "\printset.ini")
; If The FileExist variable is 2, that means the file does not exist. Display an error
; message
;? "FileExist Variable is " + $FileExist
IF $FileExist = 2
GOTO NoPrinterFile
ENDIF
; Read and discard the first 9 lines of the file
FOR $count = 1 TO 9
$nextline = READLINE(1)
NEXT
; Read the next line of the file which will be the default printer if it exists
$nextline = READLINE(1)
; The printset.ini has 9 lines of text description and then the following 5 lines look like
; Printer1 = 00is-lan
; Printer2 = 00is-ops
; The name of the printer starts one character after the space following the '=' - the twelfth character from the left
$printer = SUBSTR($nextline,12)
IF Left(@WKSTA, 5) = "55PUL"
GOTO Pulaski
Else
GOTO Mercy
ENDIF
:Mercy
; a VARTYPE of 8 means that the value of $printer is a string, try to map the printer
IF (VARTYPE($printer) = 8)
$error = AddPrinterConnection($printserver + $printer)
IF ($error = 0)
WRITELINE(5, "Mapped Default Printer to " + $printserver + $printer + @CRLF)
; The SetDefaultPrinter command relies on the printer NAME not the printer SHARE
SetDefaultPrinter($printserver + $printer)
ELSE
WRITELINE(5, "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(1)
$printer = SUBSTR($nextline,12)
IF VARTYPE($printer) = 8
$error = AddPrinterConnection($printserver + $printer)
IF $error = 0
WRITELINE(5,"Created a Printer Connection to " + $printserver + $printer + @CRLF)
ELSE
WRITELINE(5,"An error occurred creating a printer connection to " + $printserver + $printer + @CRLF)
ENDIF
;Pulaski
IF (VARTYPE($printer) = 8)
$error = AddPrinterConnection($printserver2 + $printer)
If ($error = 0)
WRITELINE(5, "Mapped Default Printer to " + $printserver2 + $printer + @CRLF)
; The SetDefaultPrinter command relies on the printer NAME not the printer SHARE
SetDefaultPrinter($printserver2 + $printer)
ELSE
WRITELINE(5, "An error occurred mapping the Default Printer to " + $printserver2 + $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(1)
$printer = SUBSTR($nextline,12)
IF VARTYPE($printer) = 8
$error = AddPrinterConnection($printserver2 + $printer)
IF $error = 0
WRITELINE(5,"Created a Printer Connection to " + $printserver2 + $printer + @CRLF)
ELSE
WRITELINE(5,"An error occurred creating a printer connection to " + $printserver2 + $printer + @CRLF)
ENDIF
ENDIF
NEXT
CLOSE(1)
;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
:EndPconSetup
GOTO End
:NoPrinterFile
? "No Printer Mapping File found"
WRITELINE(5, "No Printer Mapping File found" + @CRLF)
Goto End
:Logerror
; 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"
?
WHILE (Kbhit() = 0)
SLEEP 1
LOOP
GOTO End
FUNCTION MapDrive ( $drive, $drivepath)
USE $drive /DELETE
USE $drive $drivepath
IF (@ERROR = 0)
WRITELINE(5, "Mapped Drive " + $drive + " to " + $drivepath + @CRLF)
ELSE
WRITELINE(5, "An error occurred when mapping drive " + $drive + " to " + $drivepath + @CRLF)
ENDIF
ENDFUNCTION
:End
;Close Log File
CLOSE(5)
EXIT
Thanks in advance
Edited by Allen (2011-08-23 05:03 PM) Edit Reason: added code tags
|
|
Top
|
|
|
|
#202956 - 2011-08-24 12:45 AM
Re: alternate command
[Re: ShaneEP]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Also...there is a missing NEXT and a missing ENDIF in the :Mercy section...
:Mercy
; 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(5, "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(5, "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(1)
$printer = SUBSTR($nextline,12)
IF VARTYPE($printer) = 8
IF AddPrinterConnection($printserver + $printer) = 0
$nul = WRITELINE(5,"Created a Printer Connection to " + $printserver + $printer + @CRLF)
ELSE
$nul = WRITELINE(5,"An error occurred creating a printer connection to " + $printserver + $printer + @CRLF)
ENDIF
ENDIF
NEXT
Edited by ShaneEP (2011-08-24 12:47 AM)
|
|
Top
|
|
|
|
#202957 - 2011-08-24 12:51 AM
Re: alternate command
[Re: ShaneEP]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
In your this section...
IF Left(@WKSTA, 5) = "55PUL"
GOTO Pulaski
Else
GOTO Mercy
ENDIF
If they GOTO Mercy...there is no GOTO at the end of the section, are they intended to get the Mercy section as well as the Pulaski section? Because that's what will happen the way it is currently written.
|
|
Top
|
|
|
|
#202993 - 2011-08-30 03:14 PM
Re: alternate command
[Re: ShaneEP]
|
mtnclimber
Fresh Scripter
Registered: 2011-05-27
Posts: 11
Loc: Chicago, Il
|
ShaneEP
No they are not supposed to go to both.
So I added a line at the end of the Mercy section to skip to a different section. Is this correct.
IF Left(@WKSTA, 5) = "55PUL"
GOTO Pulaski
Else
GOTO Mercy
ENDIF
:Mercy
; 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(5, "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(5, "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(1)
$printer = SUBSTR($nextline,12)
IF VARTYPE($printer) = 8
IF AddPrinterConnection($printserver + $printer) = 0
$nul = WRITELINE(5,"Created a Printer Connection to " + $printserver + $printer + @CRLF)
ELSE
$nul = WRITELINE(5,"An error occurred creating a printer connection to " + $printserver + $printer + @CRLF)
ENDIF
ENDIF
GOTO Setup
Thanks for your help!!!!
Edited by Mart (2011-08-30 04:45 PM) Edit Reason: Please use code tags when posting code.
|
|
Top
|
|
|
|
#202994 - 2011-08-30 07:19 PM
Re: alternate command
[Re: mtnclimber]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
No problem. here is another version that should work the same as yours...WITHOUT using any confusing GOTO statements.
Also made use of the FreeFileHandle() function instead of hardcoding filehandles.
You could make things much much easier if you actually used your INI file as it should be used, instead of like a text file. There are numerous functions that can enumerate INI values for you...simpler than using readline and stepping through the whole file one line at a time.
; 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
Edited by ShaneEP (2011-08-30 07:21 PM)
|
|
Top
|
|
|
|
#203053 - 2011-09-07 10:35 PM
Re: alternate command
[Re: mtnclimber]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
ahh yeah youre probably right.
Try changing this line...
IF Left(@WKSTA, 5) = "55PUL" to...IF Left(@WKSTA, 5) = "55PUL" OR Left("%clientname%", 5) = "55PUL"
Edited by ShaneEP (2011-09-07 10:35 PM)
|
|
Top
|
|
|
|
#203054 - 2011-09-07 10:53 PM
Re: alternate command
[Re: ShaneEP]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Also, I would recommend changing both of these lines... to...IF VARTYPE($printer) = 8 AND LEN($printer) This will help ensure it does not try to map a printer if the string is blank.
|
|
Top
|
|
|
|
#203062 - 2011-09-08 06:27 PM
Re: alternate command
[Re: mtnclimber]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
My guess is that those last two lines are caused by trying to map to blank printers. For example if an empty line is at the end of your printer.ini file, it will still be read and will return a vartype of 8, but of course will fail because its blank. I would replace the entire Vartype check with a Len check to verify that it actually contains data.
Maybe change both of the lines from this... To something like this... This will trim all leading and trailing space, and then verify that its still atleast 1 char long.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1188 anonymous users online.
|
|
|