Page 1 of 1 1
Topic Options
#76379 - 2003-08-15 12:12 AM Service Pack Deployment
Anonymous
Unregistered


I'm currently trying Doc's service pack script, however I work with multiple subnets in our schools. What I'm trying to do is get the script to look at the ip address and then use the appropriate sp server, since I have 9 buildings linked by T1. Any suggestions would be greatly appreciated. Right now the messagebox displays nothing which would tell me if I used this in my script it would fail.


Call "isiniprange.udf"

ServicePack

Function ServicePack()
Dim $ip,$ipaddress,$iparray,$spServer

$ipaddress=@IPADDRESS0

Call "isiniprange.udf"

ServicePack

Function ServicePack()
Dim $iparray[1],$ipaddress,$iparray,$spServer

$ipaddress=@IPADDRESS0

Select
   $iparray[0]='10.125.16.0/20'
   Case isiniprange($ipaddress,$iparray)
      $spServer='jcboe'
   $iparray[1]='10.125.32.0/20'
   Case isiniprange($ipaddress,$iparray)
      $spServer='alt'
EndSelect
      
MessageBox($spServer, "Service Pack Update Required", 64, 60)



[ 15. August 2003, 00:13: Message edited by: cholbrook ]

Top
#76380 - 2003-08-15 02:54 AM Re: Service Pack Deployment
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Either you're not showing us one contiguous script or you don't understand how UDFs work.

The line:
Call "isiniprange.udf"
reads in to memory the UDF definition from the external file "isiniprange.udf". Why would you call it twice in one script?

The line:
servicepack
invokes the UDF defined between "Function" and EndFunction" lines which you don't show in the script or call from any external file.

You show two identical lines:
Function ServicePack()
but not the rest of the code or the EndFuction so not sure what is going on there.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#76381 - 2003-08-15 03:16 AM Re: Service Pack Deployment
Anonymous
Unregistered


I appologize for the odd post, for some reason when I ran the postprep on the script it duplicated everything. I think I may have the problem figured out. I will attempt to repost the code except without the double post.
Top
#76382 - 2003-08-15 03:24 PM Re: Service Pack Deployment
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The whole SELECT-CASE-ENDSELECT stetement is completely wrong and will not work in the present state. It will require a complete rewrite. Additionally, the IsInIPRange() UDF is also being used incorrectly as it will check all elements of the subnet array that is provided to it.

Please read the KiXtart Manual with regards to correct SELECT-CASE-ENDSELECT syntax and the IsInIPRange() header for correct usage.
Finally, please read the FAQ Forum with regards to 'How to use an UDF'.

code:
Select
Case isiniprange($ipaddress,'10.125.16.0/20')
$spServer='jcboe'
Case isiniprange($ipaddress,'10.125.32.0/20')
$spServer='alt'
EndSelect



[ 15. August 2003, 15:25: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#76383 - 2003-08-15 03:51 PM Re: Service Pack Deployment
Anonymous
Unregistered


I appologize once again for the the unusual post, I think I have got everything worked out now. Here is the code I'm working with now, many thanks for Doc for posting the code for W2KSP4 and XPSP1a. I've had to modify it to work in my enviroment here, if anyone has any suggestions as to how I can shorten the script I would greatly appreciate it.

Break on

ServicePackUpdate

Function ServicePackUpdate()
Dim $FreeSpace,$spPath,$TimeStop,$TimeStart,$TimeLapse,$UID,$SPAlert,$WR
Dim $LogServer,$UserDomain,$CloseFile,$Out,$Defer,$MarkReg
Dim $log,$A,$B,$FirstAlert, $SecondAlert
Dim $iparray[9],$ipaddress,$spServer
$A = " Due to recent viruses and other security threats @CRLF"
$A = $A+" it has become necessary to update your systems Service Pack. "
$A = $A+"@CRLF You may opt one time not to install this update, however "
$A = $A+"the next time you @CRLF logon it will run automatically. This "
$A = $A+"update will take approximately 30 minutes @CRLF to complete. If "
$A = $A+"you experience any issues with this update, please contact your @CRLF"
$A = $A+" schools principal. @CRLF @CRLF Please click YES to continue and "
$A = $A+"run the update @CRLF or click NO to cancel and run the update the next"
$A = $A+" time you logon."
$B = " Your Service Pack will now be updated. @CRLF This update"
$B = $B+" may take up to 30 minutes or more to complete. @CRLF @CRLF"
$B = $B+" Please DO NOT run any other applications as the computer will "
$B = $B+"automatically reboot when the update has completed. @CRLF @CRLF @CRLF"
$B = $B+" Please press the OK button to continue."
$FirstAlert = $A
$SecondAlert = $B
$LogServer = '\\e285000n2'

Call "isiniprange.udf"
$ipaddress=@IPADDRESS0

$iparray[0]='10.125.16.0/20'
If isiniprange($ipaddress,$iparray)
$spServer='e285000n2'
Goto WinVer
EndIf

$iparray[1]='10.125.32.0/20'
If isiniprange($ipaddress,$iparray)
$spServer='e285050n1'
Goto WinVer
EndIf

$iparray[2]='10.125.48.0/20'
If isiniprange($ipaddress,$iparray)
$spServer='e285000n2'
Goto WinVer
EndIf

$iparray[3]='10.125.64.0/20'
If isiniprange($ipaddress,$iparray)
$spServer='e285100n1'
Goto WinVer
EndIf

$iparray[4]='10.125.80.0/20'
If isiniprange($ipaddress,$iparray)
$spServer='e285000n2'
Goto Winver
EndIf

$iparray[5]='10.125.96.0/20'
If isiniprange($ipaddress,$iparray)
$spServer='e285250n1'
Goto Winver
EndIf

$iparray[6]='10.125.112.0/20'
If isiniprange($ipaddress,$iparray)
$spServer='e285270n1'
Goto WinVer
EndIf

$iparray[7]='10.125.128.0/20'
If isiniprange($ipaddress,$iparray)
$spServer='e285320n1'
Goto WinVer
EndIf

$iparray[8]='10.125.144.0/20'
If isiniprange($ipaddress,$iparray)
$spServer='e2853400n1'
Goto WinVer
EndIf

$iparray[9]='10.125.176.0/20'
If isiniprange($ipaddress,$iparray)
$spServer='e285340n1'
Goto WinVer
EndIf



:WinVer

;******************************************************
;* Run only if workstation is running an NT based OS *
;* and see if system is at latest Service Pack *
;******************************************************

If @INWIN=1
SELECT
CASE @ProductType='Windows 2000 Professional'
IF @CSD = 'Service Pack 4'
RETURN
ENDIF
CASE @ProductType='Windows XP Professional'
If @CSD = 'Service Pack 1'
RETURN
EndIf
EndSelect

;*********************************************************
;* Check system to see if user has deferred service pack *
;*********************************************************

$CheckUpdate=ReadValue('HKLM\SOFTWARE\JohnsonCounty\SP', 'UPDATE2')
$Defer=0

;************************************
;* Check system for available space *
;************************************

$FreeSpace = DiskSpace(,1)
IF $FreeSpace < 250
$SpaceAlert="Low"
ELSE
$SpaceAlert="Sufficient"
EndIf

;*****************************
;* Windows 2000 SP 4 Install *
;*****************************

Select
Case @PRODUCTTYPE='Windows 2000 Professional'
$spPath='SP\W2KSP4\i386'
IF @CSD <> 'Service Pack 4'
IF $CheckUpdate <> 1
$SPAlert = MESSAGEBOX($FirstAlert,"Service Pack Update Required", 4116, 60)
IF $SPAlert=6
ELSE
$MarkReg=WriteValue('HKLM\SOFTWARE\JohnsonCounty\SP', 'UPDATE2', '1', 'REG_SZ')
$Defer=1
ENDIF
ENDIF
IF $Defer=1 or $SpaceAlert="Low"
$WR='Deferred or Space Low'
GOSUB 'SPLOG'
RETURN
ENDIF
$WR='SP Ran'
$SPAlert = MESSAGEBOX($SecondAlert, "Service Pack Update Required", 64, 60)
CLS
Shell '%comspec% /c \\'+$spServer+'\sp\deploy_sp.exe'
ELSE
IF $Defer=1 or $SpaceAlert="Low"
$WR='Too slow and Deferred or Space Low'
GOSUB 'SPLOG'
RETURN
ENDIF
$WR='Copy too slow. Will not run'
EndIf

;***************************
;* XP Service Pack Install *
;***************************

Case @PRODUCTTYPE='Windows XP Professional'
$spPath='SP\XPSP1a\i386'
If @CSD <> 'Service Pack 1'
IF $CheckUpdate <> 1
$SPAlert = MESSAGEBOX($FirstAlert,"Service Pack Update Required", 4116, 60)
IF $SPAlert=6
ELSE
$MarkReg=WriteValue('HKLM\SOFTWARE\JohnsonCounty\SP', 'UPDATE2', '1', 'REG_SZ')
$Defer=1
ENDIF
ENDIF
IF $Defer=1 or $SpaceAlert="Low"
$WR='Deferred or Space Low'
GOSUB 'SPLOG'
RETURN
ENDIF
$WR='SP Ran'
$SPAlert = MESSAGEBOX($SecondAlert, "Service Pack Update Required", 64, 60)
CLS
? 'Please wait.... The Service Pack Update is being silently installed'
? 'Your system will automatically restart once the update has completed.'
SHELL '%comspec% /c \\'+$spServer+'\'+$spPath+'\sp\deploy_sp.exe'
ELSE
IF $Defer=1 or $SpaceAlert="Low"
$WR='Too slow and Deferred or Space Low'
GOSUB 'SPLOG'
RETURN
ENDIF
$WR='Copy too slow. Will not run'
ENDIF
Case 1
RETURN
ENDSELECT
ELSE
$Defer='Not Admin'
$WR='Not Admin'
$LA='Not Admin'
$TimeLapse='Not Admin No Copy'
GOSUB 'SPLOG'
RETURN
ENDIF

;*******************************
;* ServicePackUpdate() LOGGING *
;*******************************

:SPLOG
If Exist ('\\'+$LogServer+'\LOGS$\SP\'+@WKSTA+'.LOG')
Del ('\\'+$LogServer+'\LOGS$\SP\'+@WKSTA+'.LOG')
ENDIF
If Open(1,'\\'+$LogServer+'\LOGS$\SP\'+@WKSTA+'.LOG', 5)= 0
$log=@DATE+'*'+@TIME+'*'+@USERID+'*'+@FULLNAME+'*'+@lserver+'*'+$IP+'*'+@WKSTA+'*'
$log=$log+@ProductType+'*'+@CSD+'*'+$UserDomain+'*'+$LA+'*'+$SpaceAlert+'*'+$FreeSpace+'*'
$log=$log+$spServer+'*'+$TimeLapse+'*'+$WR+'*'+$Defer+@CRLF
$Out = WriteLine(1, $log)
$CloseFile = CLOSE(1)
ENDIF
RETURN
EndFunction

;********************************
;* Function to check disc space *
;********************************

Function diskspace(optional $drive, optional $format)
$format=val($format)
$format=iif($format=1,1024,iif($format=2,1024.0*1024,iif($format=3,1024.0*1024*1024,1)))
if not $drive
$drive='%WINDIR%'
endif
$diskspace=cdbl(GETDISKSPACE($drive))/$format
exit @ERROR
endfunction

[ 15. August 2003, 15:53: Message edited by: cholbrook ]

Top
#76384 - 2003-08-15 04:09 PM Re: Service Pack Deployment
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Did you even read my post? [Confused]

You're still using the ISINIPRange incorrectly, e.g. the last time you call it oyu're providing an array with a toal of ten different subnets to it and it will chekc the subnets for any match. you should also ratehr use the SELECT construct as I outlined in my post.

Your code will not work correctly. You should also get rid of the GOTOs and use proper coding techniques like subroutines or functions.

You might also want to keep the headers of UDFs intact for future reference so you knwo where they came from and how they are being used.
_________________________
There are two types of vessels, submarines and targets.

Top
#76385 - 2003-08-15 06:56 PM Re: Service Pack Deployment
Anonymous
Unregistered


I've just done a simple test using your suggested code and it will return nothing as to what the $spserver is. I'm using a simple text message box to see what it returns and I just get a blank box. What am I doing wrong? I'm still a newbie at using kixtart. I appologize if my coding seems a little strange. Below is the simple code that I'm trying to use.




Call "isiniprange.udf"

$ipaddress = @IPADDRESS0

Select
Case isiniprange($ipaddress,'10.125.16.0/20')
$spserver='jcboe'
Case isiniprange($ipaddress,'10.125.32.0/20')
$spserver='alt'
EndSelect

$SPAlert = MessageBox($spserver, "Simple Test", 64, 60)

Top
#76386 - 2003-08-15 07:09 PM Re: Service Pack Deployment
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Take a look at the header ofIsInIPRange()
quote:

;REMARKS This function is deprecated in favor of IsInSubnet() at
; http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000053

code:
Call "isinsubnet.udf"

$ipaddress = @IPADDRESS0

Select
Case isinsubnet($ipaddress,'10.125.16.0/20')
$spserver='jcboe'
Case isinsubnet($ipaddress,'10.125.32.0/20')
$spserver='alt'
case 1
$spserver='no match'
EndSelect
? 'Error '+@ERROR+' - '+@SERROR
$SPAlert = MessageBox($spserver, "Simple Test", 64, 60)

_________________________
There are two types of vessels, submarines and targets.

Top
#76387 - 2003-08-15 07:24 PM Re: Service Pack Deployment
Anonymous
Unregistered


I just tried the code you suggested, it's doing something now. It returns no match. However it is not returning the jcboe that it should since my machines ip is 10.125.17.1 which would put it in the range of 10.125.16.1 - 10.125.31.254. I'm currently running version 4.21 of kix. I really appreciate your help.
Top
#76388 - 2003-08-15 07:49 PM Re: Service Pack Deployment
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I'll check it over here. Might take me a while, though.
_________________________
There are two types of vessels, submarines and targets.

Top
#76389 - 2003-08-18 05:39 PM Re: Service Pack Deployment
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Okay, I took a look and there was a problem if only one NetworkID/SubnetMask combination was provided as the second parameter together with an empty third parameter. I've fixed the issue and the updated UDF is available at http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000053
_________________________
There are two types of vessels, submarines and targets.

Top
#76390 - 2003-08-18 08:12 PM Re: Service Pack Deployment
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
What!! Updated the UDF today and no PostPrep used [Frown]
Top
#76391 - 2003-08-18 08:18 PM Re: Service Pack Deployment
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I'm a PostPrep-Virgin [Smile]

okay, maybe I should loose my virginity and start using Post-Prep [Wink]
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.17 seconds in which 0.102 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