Page 1 of 1 1
Topic Options
#137692 - 2005-04-11 06:49 PM Funny problem with SPLIT( )
DavidH Offline
Lurker

Registered: 2005-04-11
Posts: 3
Hi Guys,

I've finally got around to tidying up our logon script at work - its always just had something bodged onto it when needed.

The basic rewrite includes these two sections that read from an ini file that's been copied to the users temp folder. The variable $logonini=@site+".ini" for most users, I've forced it to KENT.ini for the time being.

The printers section works great and is included to show what I want to happen. The drive mappings section is where the problems lie:

Code:
 

$debug=1
$dodrives=1
$doprinters=1
$title="Logon Script"
$logonini="KENT.ini"
if $debug
$ret=messagebox("Site detected as "+@site+".",$title)
endif

;; Map the network drives
if $debug
$ret=messagebox("Map network drives",$title)
endif
if $dodrives
$strings=""
$section="MAPPINGS"
$strings=ReadProfileString("%temp%\$logonini",$section,"")
if $debug messagebox($strings,$title) endif
$mappingarray=split($strings, chr(10))
;if $debug messagebox($mappingarray,$title) endif ;; For Each $driveletter IN $mappingrarray
if $debug messagebox($driveletter,$title+" 2") endif ;; $driveshare=(ReadProfileString("%temp%\$logonini",$section,$driveletter))
if $debug messagebox("Mapping "+$driveletter+" to "+$driveshare,$title) endif
Use $driveletter $driveshare
Next
endif


;; Printers
if $doprinters
;; Read current default printer
$DefaultPrinter = ""
$RegKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows"
$KeyValue = ReadValue ($RegKey, "Device")
If @ERROR = 0
$DefaultPrinter = SubStr($KeyValue, 1, InStr($KeyValue, ",") - 1)
EndIf
if $debug
messagebox("Default printer is "+$DefaultPrinter,$title)
endif

;; Remove obsolete printers
$strings=ReadProfileString ("%temp%\$logonini","PRINTERDEL","")
$printerarray=split($strings, chr(10))
For Each $printer IN $printerarray
$printername=(ReadProfileString("%temp%\$logonini","PRINTERDEL",$printer))
if $debug
messagebox("Deleting "+$printer,$title)
endif
DelPrinterConnection($printername)
Next

;; Add new printers
$delbeforeadd=1
$delbeforeadd=ReadProfileString("%temp%\$logonini","MISC","delprnbeforeadd")
$strings=""
$strings=ReadProfileString ("%temp%\$logonini","PRINTERS","")
$printerarray=split($strings, chr(10))
For Each $printer IN $printerarray
if $debug
messagebox("Adding "+$printer,$title)
endif
$printername=(ReadProfileString("%temp%\$logonini","PRINTERDEL",$printer))
if $delbeforeadd
DelPrinterConnection($printername)
endif
AddPrinterConnection($printername)
Next

;; Reset Default printer back to the one we had at the beginning!
SetDefaultPrinter($DefaultPrinter)

endif




The INI files contain the following:


KENT.ini

Code:
 
[MAPPINGS]
J:=\\knt-srv-001\projects
K:=\\knt-srv-001\admin
L:=\\knt-srv-001\Archiving
M:=\\knt-srv-001\general
S:=\\knt-srv-001\drivers

[PRINTERS]
printer1=\\knt-srv-003\Kyocera
printer2=\\knt-srv-003\HPDesign
printer3=\\knt-srv-003\KyoceraF
printer4=\\knt-srv-003\Kyocera3
printer5=\\knt-srv-003\HP5500
printer6=\\knt-srv-001\PDFCreat

[PRINTERDEL]
printer1=\\knt-srv-001\Kyocera
printer2=\\knt-srv-001\HPDesign
printer3=\\knt-srv-001\KyoceraF
printer4=\\knt-srv-001\Kyocera3
printer5=\\knt-srv-001\HP5500




Finally, I have an old bit of code which did it completely differently, which is listed below.

Code:
 
$ret=RedirectOutput ("%temp%\pba.tmp", 1)
ReadProfileString ("%temp%\$logonini","MAPPINGS","")
$ret=RedirectOutput ("")
$ret=Open(1,"%temp%\pba.tmp",2)
$letter=SubStr (ReadLine(1),1,2)
While $letter
Use $letter ReadProfileString("%temp%\$logonini","MAPPINGS",$letter)
$letter=SubStr (ReadLine(1),1,2)
Loop
$ret=Close(1)



Any suggestions or reasons why the 'nice' code doesn't do it and the hacky bit does would be gratefully received!

TIA

David.

Top
#137693 - 2005-04-11 07:20 PM Re: Funny problem with SPLIT( )
DavidH Offline
Lurker

Registered: 2005-04-11
Posts: 3
AAAaaaaarrggggghh

It was a typo in $mappingarray which is not spelt $mappingrarray

I've fixed it now - it just goes to show that you can spend all day reading the damn thing and still miss the slippery bugs!

Thanks for looking

David.

Top
#137694 - 2005-04-11 07:43 PM Re: Funny problem with SPLIT( )
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
David,

Glad to hear you found the mistake. On another note I would not personally suggest you maintain an INI file or SCRIPT on the local system. That makes it very difficult to manage and maintain a consistent up to date version, it also allows a user to easily modify it and have it do something else entirely different then what you want to do.

For some Admins they copy the executable locally to reduce traffic, but the script itself should remain on the NETLOGON share. That way you have one file to manage and not hundreds or thousands of files on local systems.

Top
#137695 - 2005-04-11 10:14 PM Re: Funny problem with SPLIT( )
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
What about setting option Explicit on?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#137696 - 2005-04-12 12:09 AM Re: Funny problem with SPLIT( )
DavidH Offline
Lurker

Registered: 2005-04-11
Posts: 3
We keep everything on the netlogon share and cache a copy of the @site.ini file on the local machine.

When I've got the whole thing working tickety boo I'll post it with an ini file.

I just need to add some registry merges and its about done.

Cheers,

David.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2870 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.055 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org