Solved

# Script code Explain

Posted on 2013-10-19
Medium Priority
930 Views
Any Kixstart expert to explain this code:

Thank you

``````;;; Function List ;;;
;
; 1)  ArrayEnumKey - Enumerates keys within Array
; 2)  QS() -- a very fast quicksort algorithm to sort arrays

Function ArrayEnumKey(\$regsubkey)

DIM \$retcode, \$subkeycounter, \$currentsubkey, \$subkeyarray

If Not KeyExist(\$regsubkey)
Exit 87
EndIf

\$subkeycounter=0

Do

\$currentsubkey=EnumKey(\$regsubkey,\$subkeycounter)

If Not @ERROR

ReDIM Preserve \$subkeyarray[\$subkeycounter]
\$subkeyarray[\$subkeycounter]=\$currentsubkey

\$subkeycounter=\$subkeycounter+1

EndIf

Until @ERROR

\$arrayenumkey=\$subkeyarray
Exit 0

EndFunction

Function ArrayEnumValue(\$regsubkey)

DIM \$retcode, \$subvaluecounter, \$currentsubvalue, \$subvaluearray

If Not KeyExist(\$regsubkey)
Exit 87
EndIf

\$subvaluecounter=0

Do

\$currentsubvalue=EnumValue(\$regsubkey,\$subvaluecounter)
If Not @ERROR

ReDIM Preserve \$subvaluearray[\$subvaluecounter]
\$subvaluearray[\$subvaluecounter]=\$currentsubvalue

\$subvaluecounter=\$subvaluecounter+1

EndIf

Until @ERROR

\$arrayenumvalue=\$subvaluearray
Exit 0

EndFunction

Function QS(\$a)

DIM \$b[32],\$c[32],\$d,\$e,\$f,\$g,\$h,\$i,\$j,\$k,\$l

\$b[0]=0
\$c[0]=UBound(\$a)
\$d=0

While \$d >=0

\$e=\$b[\$d]
\$f=\$c[\$d]

While \$e < \$f

\$h=\$e+(\$f-\$e)/2
\$k=\$a[\$e]
\$A[\$e]=\$A[\$h]
\$A[\$h]=\$k
\$i=\$e+1
\$j=\$f
\$l=0

Do

While (\$i<\$j) And \$A[\$e] > \$A[\$i]
\$i=\$i+1
Loop

While (\$j>=\$i) And \$A[\$j] > \$A[\$e]
\$j=\$j-1
Loop

If \$i>=\$j
\$l=1
Else
\$k=\$A[\$i]
\$A[\$i]=\$A[\$j]
\$A[\$j]=\$k
\$j=\$j-1
\$i=\$i+1
EndIf

Until \$l=1

\$k=\$a[\$e]
\$a[\$e]=\$a[\$j]
\$a[\$j]=\$k
\$g=\$j

If \$g-\$e <= \$f - \$g

If \$g+1 < \$f
\$b[\$d]=\$g+1
\$c[\$d]=\$f
\$d=\$d+1
EndIf

\$f=\$g-1

Else

If \$g-1 > \$e

\$b[\$d]=\$e
\$c[\$d]=\$g-1
\$d=\$d+1

EndIf

\$e=\$g+1

EndIf

Loop

\$d=\$d-1

Loop

\$qs=\$a

EndFunction

Function Ping ( \$ip)

\$cmd="Ping -4 -n 1 "+ \$ip+ ' | Find /I "TTL=" >NUL'

Shell "%COMSPEC% /C "+\$cmd

If @ERROR = 0
\$Ping = 1
Else
\$Ping = 0
EndIf

EndFunction

Function whichsite ()

\$fnSiteName="HQ-LosAngeles"
\$tmpwhichsite=""

do
\$cmd='gpresult /scope computer |find /i "'+\$fnSiteName+'"'
shell "%comspec% /c "+\$cmd

if @error=0
\$tmpwhichsite=1
endif

select
case \$tmpwhichsite<>1 and \$fnSiteName="HQ-LosAngeles"
\$fnSiteName="Europe"
case \$tmpwhichsite<>1 and \$fnSiteName="Europe"
\$whichsite=0
endselect

until \$tmpwhichsite=1 or \$tmpwhichsite=0

if \$fnsitename<>"Europe" and \$fnsitename<>"HQ-LosAngeles"
\$WhichSite="unknown"
else
\$whichSite=\$fnSiteName
endif

endfunction

function DateCalc(\$date1, \$DateOrMod, optional \$SingleDigit)

dim \$_intDate1, \$_intYear1, \$_intMonth1, \$_intDay1
dim \$_intDate2, \$_intYear2, \$_intMonth2, \$_intDay2

\$date1 = split(\$date1,'/')
if ubound(\$date1) <> 2
;        exit 1
endif

\$_intYear1  = val(\$date1[0])
\$_intMonth1 = val(\$date1[1])
\$_intDay1   = val(\$date1[2])

if \$_intMonth1 < 3
\$_intMonth1 = \$_intMonth1 + 12
\$_intYear1  = \$_intYear1  - 1
endif

\$_intDate1 = \$_intDay1 + ( 153 * \$_intMonth1 - 457 ) / 5 + 365 * \$_intYear1 +
\$_intYear1 / 4 - \$_intYear1 / 100 + \$_intYear1 / 400 - 306

select

case vartype(\$DateOrMod) = 3

\$_intDate2  = \$_intDate1 + \$DateOrMod
if instr(\$_intDate2,'-') \$_intDate2 = val(substr(\$_intDate2,2,len(\$_intDate2)-1)) endif

\$_intYear2  = ( 100 * ( ( ( 100*(\$_intDate2+306)-25)/3652425)
- ( ((100*(\$_intDate2+306)-25)/3652425)/4)
) + (100*(\$_intDate2+306)-25)
) / 36525

\$_intMonth2 = (   5 * ( ( ( 100*(\$_intDate2+306)-25)/3652425)
- ( ((100*(\$_intDate2+306)-25)/3652425)/4)
+ (\$_intDate2+306) - 365 * \$_intYear2 - \$_intYear2 / 4
) + 456
) / 153

\$_intDay2   = ( ( ( 100*(\$_intDate2+306)-25)/3652425)
- ( ((100*(\$_intDate2+306)-25)/3652425)/4)
+ (\$_intDate2+306) - 365 * \$_intYear2 - \$_intYear2 / 4
)         - ( 153 * \$_intMonth2 - 457
) / 5

if \$_intMonth2 > 12 \$_intYear2 = \$_intYear2 + 1 \$_intMonth2 = \$_intMonth2 - 12 endif

if not \$SingleDigit
if len(\$_intYear2 ) < 4
\$_ = execute("for \$i=1 to 4-len(\$\$_intYear2) \$\$_intYear2 = '0' + \$\$_intYear2 next")
endif
\$_intMonth2 = right("0" + \$_intMonth2,2)
\$_intDay2   = right("0" + \$_intDay2,2)
endif

\$DateCalc = '' + \$_intYear2 + '/' + \$_intMonth2 + '/' + \$_intDay2

case vartype(\$DateOrMod) = 8

\$DateOrMod = split(\$DateOrMod,'/')

if ubound(\$DateOrMod) <> 2
;                exit 1
endif

\$_intYear2  = val(\$DateOrMod[0])
\$_intMonth2 = val(\$DateOrMod[1])
\$_intDay2   = val(\$DateOrMod[2])

if \$_intMonth2 < 3
\$_intMonth2 = \$_intMonth2 + 12
\$_intYear2  = \$_intYear2  - 1
endif

\$_intDate2 = \$_intDay2 + ( 153 * \$_intMonth2 - 457 ) / 5 + 365 * \$_intYear2 +
\$_intYear2 / 4 - \$_intYear2 / 100 + \$_intYear2 / 400 - 306

\$DateCalc  = \$_intDate1 - \$_intDate2

;comment the next line if you wish to return negative results also !!!
if instr(\$DateCalc,'-') \$DateCalc = val(substr(\$DateCalc,2,len(\$DateCalc)-1)) endif

case 1

;            exit 1

endselect

endfunction

Function Getsubfolders (\$path)
\$fnObjFSO=CreateObject("Scripting.FileSystemObject")
\$fnFolderObj=\$fnObjFSO.GetFolder(\$path)
\$Getsubfolders=\$fnFolderObj.SubFolders
;  \$fnObjFSOGetFolder=0
;  \$fnFolderObj=0
EndFunction

Function Getsubfiles (\$path)
\$fnObjFSOGetFolder=CreateObject("Scripting.FileSystemObject")
\$fnFolderObj=\$fnObjFSOGetFolder.GetFolder(\$path)
\$GetSubFiles=\$fnFolderObj.Files
\$fnObjFSOGetFolder=0
\$fnFolderObj=0
EndFunction

Function GetAttribute (\$path,\$type)

\$fnObjFSO=CreateObject("Scripting.FileSystemObject")

If \$type="File"
\$fnFolderObj=\$fnObjFSO.GetFile(\$path)
Else
\$fnFolderObj=\$fnObjFSO.GetFolder(\$path)
EndIf

If \$fnFolderObj.Size=0
\$Size=0
Else
\$Size=\$fnFolderObj.size
EndIf

\$_=WriteLine(1,",")
\$_=WriteLine(1,CHR(34)+\$Path+CHR(34)+",")
\$_=WriteLine(1,\$Type+",")
\$_=WriteLine(1,CHR(34)+\$Size+CHR(34)+",")
\$_=WriteLine(1,CHR(34)+\$Size/1048576+CHR(34)+",")
\$_=WriteLine(1,\$fnFolderObj.DateCreated+",")
\$_=WriteLine(1,\$fnFolderObj.DateLastModified)
\$_=WriteLine(1,@CRLF)

\$fnObjFSO=0
\$fnFolderObj=0
EndFunction

Function IsFile (\$Path)
\$IsFile= \$objFSO.FileExists (\$Path)
EndFunction

Function EnumINI (\$_Filename, \$_Section, optional \$_Value)

DIM \$_MyValues[1], \$i, \$MyKeyValue

\$i=0

Select
Case \$_Section=""
For Each \$element In Split (ReadProfileString (\$_Filename, \$_Section,\$_Value),CHR(10))
ReDIM preserve \$_MyValues[\$i]
\$_MyValues[\$i]=\$element
\$i=\$i+1
Next

Case \$_Value=""
For Each \$element In Split (ReadProfileString (\$_Filename, \$_Section,\$_Value),CHR(10))
ReDIM preserve \$_MyValues[\$i]
\$_MyValues[\$i]=\$element
\$i=\$i+1
Next

EndSelect

;	If (\$_Value=="")

;		For Each \$element In Split (ReadProfileString (\$_Filename, \$_Section,\$_Value),CHR(10))

;			If \$element <> ""
;				\$_MyValues[\$i]=\$element + '|' + \$MyKeyValue
;			EndIf

;			\$i=\$i+1
;			ReDIM Preserve \$_MyValues[\$i]

;		Next

;	Else
;	EndIf

Select
Case UBound(\$_MyValues)>=2
ReDIM Preserve \$_MyValues[\$i-2]
;		Case UBound(\$_MyValues)>=1
;			ReDIM Preserve \$_MyValues[\$i-1]
EndSelect

\$EnumINI=\$_MyValues

EndFunction

Function CleanINIList(\$_File,\$_Item)

DIM \$line,\$tmpLine

If Exist (\$_file)

\$_=Open (1,\$_file)
\$tmpFile="%tmp%\cleanINIList.txt"

If Exist (\$tmpFile)
DEL \$tmpfile
EndIf

\$_=Open (2,\$tmpFile,5)

Do
If InSTR (\$Line,'['+\$_Item+']')

Do
Until InSTR(\$tmpLine,'[') or @ERROR=-1
\$_=WriteLine(2,\$tmpLine+@CRLF)
Else
\$_=WriteLine(2,\$Line+@CRLF)
EndIf

Until @ERROR=-1

\$_=Close (1)
\$_=Close (2)
Copy \$tmpfile \$_File

EndIf

EndFunction

Function enumNWDrives (\$_Machine)

DIM \$_DriveList[1], \$i, \$myprimarykey, \$mysubkey

\$myprimarykey="\\"+\$_Machine+"\HKEY_CURRENT_USER\Network"
\$i=0

\$mysubkey=EnumKey ("\\"+\$_Machine+"\HKEY_CURRENT_USER\Network",\$i)

While @ERROR=0
\$thiskey=\$myprimarykey + "\" + \$mysubkey
\$i=\$i+1
ReDIM preserve \$_DriveList[\$i]
\$mysubkey=EnumKey (\$myprimarykey,\$i)
Loop

If UBound(\$_DriveList)>0
ReDIM preserve \$_DriveList[UBound(\$_DriveList)-1]
EndIf

\$EnumNWDrives=\$_DriveList

EndFunction

Function EnumNWPrinters (\$_Machine)

DIM \$_Printreg, \$i, \$j, \$k, \$_MyRegKey, \$_MyPrinterList, \$_MyTempPrinterList[4], \$_MyPrinters[1]

\$_PrintReg="\\"+\$_Machine+"\HKEY_CURRENT_USER\Printers\Connections"

\$i=0
\$k=0

\$_MyRegKey=EnumKey (\$_PrintReg,\$i)

While @ERROR=0
\$j=0
\$_MyPrinterList=Split (\$_MyRegKey, ",")

For Each \$Element In \$_MyPrinterList
If \$Element <> ""
\$_MyTempPrinterList[\$j]=\$Element
\$j=\$j+1
EndIf
Next

If \$_MyTempPrinterList[0] <> ""
\$_MyPrinters[\$k]="\\" +\$_MyTempPrinterList[0] + "\" + \$_MyTempPrinterList[1]
EndIf

\$k=\$k+1

ReDIM preserve \$_myprinters[\$k]

\$i=\$i+1
\$_MyRegKey=EnumKey ("\\"+\$_Machine+"\HKEY_CURRENT_USER\Printers\Connections",\$i)
Loop

\$EnumNWPrinters=\$_MyPrinters

EndFunction

If not \$_MailServer
\$_Mailserver="smtp2.Mydomain.com"
EndIf

if \$_cc=""
\$fncc=""
else
\$fncc=' -c '+\$_cc
endif

If \$_Attachment and not \$_AttachType
\$blat=\$blat+" -attach "+'"'+\$_attachment+'"'
else
if \$_Attachment and \$_AttachType
\$blat=\$blat+" -attacht "+'"'+\$_attachment+'"'
endif
EndIf

Shell \$blat

\$_MailServer=""
\$_subject=""
\$_body=""
\$_attachment=""

EndFunction

FUNCTION OUTLOOK(\$_FromOffice,\$_machinetype)
DIM \$prfrem,\$waste,\$explorview,\$editorpref,\$prf,\$serverloc,
\$exchgsvr,\$prfloc,\$prffile,\$ppru,\$exe,\$ver,\$idx,\$keyname,\$rc,

\$waste='FALSE'    ; Empty Outlooks Deleted Items Folder on Exit
\$explorview='Yes' ; Outlook Explorer View 'Yes' or Standard View 'No'
\$editorpref=20001 ; Editor Preference 10001=Plain Text, 20001=HTML, and 30001=Rich Text
\$prf='CitrixOutlook2k3.prf'
\$prffile=%userprofile%+'\'+\$prf
\$serverloc='\\Mydomain.corp\NETLOGON\HQ\Scripts\User' ; Outlook Executables files location
if \$_FromOffice="UK"
\$exchgsvr='Myfileserv.Mydomain.inc'     ; Main Exchange Server Location
else
\$exchgsvr='szexchange.Mydomain.inc'
endif

if instr (@fullname, ',')
\$tmpname=split(@fullname,", ")
\$fullname=\$tmpname[0]+" "+\$tmpname[1]
else
\$fullname=@fullname
endif

if \$_MachineType="Laptop"
\$CacheMode="0x00000100"
else
\$CacheMode="0x00000000"
endif

IF @INWIN ;Windows NT/2k/XP/2003
\$prfloc='HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles'
ELSE
;Windows 9x
\$prfloc='HKCU\Software\Microsoft\Windows Messaging Subsystem\Profiles'
ENDIF
; -- Current User Profile
\$ppru=\$prfloc+'\'+@USERID

; -- Determine version of Outlook
\$ver=SPLIT(GetFileVersion(\$exe),'.')[0]+'.0'
\$MSOdir=SUBSTR(\$exe,1,Len(\$exe)-11)

;?"found version "+\$ver
; -- This is used for when you have people come into the company from another Exchange Server into yours
\$rc=WriteValue(\$ppru+'\13dbb0c8aa05101a9bb000aa002fc45a','001e6602',\$exchgsvr,'REG_SZ')
\$rc=WriteValue(\$ppru+'\13dbb0c8aa05101a9bb000aa002fc45a','001e6608',\$exchgsvr,'REG_SZ')
ENDIF

; -- Look for Outlook Profile

\$MBAnswer=messagebox("Did not find an Outlook profile.  Would you like to set one up for this machine? Select NO to permanently disable this message without configuring Outlook on this machine.  Choose CANCEL to try again later.","Setup Outlook Profile",515,20)

select
COPY \$serverloc+'\'+\$prf \$prffile
\$rc=WriteProfileString(\$prffile,'General','ProfileName',\$Fullname+" - Exchange")
\$rc=WriteProfileString(\$prffile,'General','DefaultProfile','Yes')
\$rc=WriteProfileString(\$prffile,'General','OverwriteProfile','Yes')
\$rc=WriteProfileString(\$prffile,'General','BackupProfile','No')
\$rc=WriteProfileString(\$prffile,'Service1','AutoNameCheck','TRUE')
\$rc=WriteProfileString(\$prffile,'Service1','CloseOriginalMessage','TRUE')
\$rc=WriteProfileString(\$prffile,'Service1','HomeServer',\$exchgsvr)
\$rc=WriteProfileString(\$prffile,'Service1','MailboxName',\$fullname)
\$rc=WriteProfileString(\$prffile,'ServiceEGS','MailboxName',\$fullname)
\$rc=WriteProfileString(\$prffile,'ServiceEGS','HomeServer',\$exchgsvr)
\$rc=WriteProfileString(\$prffile,'ServiceEGS','CachedExchangeConfigFlags',\$CacheMode)

if \$_MachineType="Laptop"
\$rc=writeprofilestring(\$prffile,'ServiceEGS','RPCoverHTTPflags','0x0023')
\$rc=writeprofilestring(\$prffile,'ServiceEGS','RPCProxyServer','webmail.Mydomaininc.com')
\$rc=writeprofilestring(\$prffile,'ServiceEGS','RPProxyAuthScheme=0x0002')
\$rc=writeprofilestring(\$prffile,'ServiceEGS','RPCProxyPrincipalName','')

if \$_fromOffice="UK"
\$rc=writeprofilestring(\$prffile,'ServiceEGS','RPCProxyServer','ukwebmail.Mydomain.com')
endif
endif

SELECT
CASE \$ver='8.0' OR \$ver='9.0' ;(e.g. 8.5.5104.0)
SHELL '%COMSPEC% /C '+\$serverloc+'\newprof.exe -p '+\$prffile+' -x'
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook','Machine Name',@WKSTA,'REG_SZ')
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook','CheckInternetAccounts',1,'REG_DWORD')
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook','FirstRunDialog','False','REG_SZ')
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook\Setup','PrimaryClient',1,'REG_DWORD')
\$rc=WriteValue('HKLM\Software\Microsoft\Office\'+\$ver+'\Outlook\Setup','MailSupport',1,'REG_DWORD')

IF \$explorview='Yes'
\$rc=WriteValue(\$prfloc+@userid+'\0a0d020000000000c000000000000046','001e0360','','REG_SZ')
\$expview='010000002c0000000200000003000000ffffffffffffffffffffffffffffffff62000000270000003'
\$expview=\$expview+'c030000ac02000001000000000000000100000000000000c00000006400000003000000'
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook\Office Explorer','Frame',\$expview,'REG_BINARY')
ENDIF

CASE \$ver='10.0' OR \$ver='11.0'  OR \$ver='12.0';(e.g. 10.0.2627.1)
\$rc=DelValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook\Setup','First-Run')
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook\Setup','ImportPRF',\$prffile,'REG_SZ')

IF \$ver='10.0' or \$ver='12.0'
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook\IM','Enabled',0,'REG_DWORD')
ENDIF
; -- This was added as we needed to generate Outlook Profiles in a Citrix Session - thanks Rad!
\$outlook=CreateObject('Outlook.Application')
\$ns=\$outlook.getnamespace('MAPI')
\$fldr=\$ns.getdefaultfolder(6)
\$outlook=0
ENDSELECT

DEL \$MSOdir+'welcome.msg'
if readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"+\$DefaultProfile+"\00000001","New Signature")<>"53686f707a696c6c61000000"
\$objOWord=CreateObject("Word.Application")

;	\$objWord.visible="True"
\$objODoc.Saved="True"
\$objOWord.Quit
sleep 10
\$_=OutlookSignature()
endif

endselect
else
?"found profile"
ENDIF

ENDFUNCTION

;\$objCalendar.Subject="Test Subject"
;\$objCalendar.Body="Test Body"
;\$objCalendar.ReminderSet=1
;\$objCalendar.ReminderTime="4/23/2007 10:20 AM"
;\$objcalendar.DueDate="4/23/2007 10:21 AM"
;\$objcalendar.ReminderPlaySound=1

\$OLCalendar=3

\$objOutlook=CreateObject("Outlook.Application")
\$objCalendar=\$objOutlook.CreateItem(\$OLCalendar)

\$objCalendar.Subject=\$_Subject
\$objCalendar.Body=\$_Body
\$objCalendar.ReminderSet=1
\$objCalendar.ReminderTime=\$_ReminderTime
\$objcalendar.DueDate=\$_DueDate
\$objcalendar.ReminderPlaySound=1
\$objcalendar.ReminderSoundFile="c:\windows\media\ding.wav"

\$objCalendar.save

EndFunction

function EnumSubKey (\$_key)

\$count=0
dim \$aSubkey[0]

\$subkey=enumkey(\$_key,\$count)
while @error=0
\$asubkey[ubound(\$asubkey)]=\$subkey
redim preserve \$asubkey[ubound(\$asubkey)+1]
\$count=\$count+1
\$subkey=enumkey(\$_key,\$count)
loop

\$EnumSubKey=\$aSubKey

endfunction

function OutlookSignature (Optional \$_Office,Optional \$_telephone,optional \$_mobile,optional \$_title,optional \$_Telephone2)

\$ver=SPLIT(GetFileVersion(\$exe),'.')[0]+'.0'
;	?"version="+\$ver

if \$ver<>".0"

if \$telephone=""
if \$office="UK"
\$telephone="+44 (0) 207 029 3300"
else
\$telephone="(310) 571-1235"
endif
endif

\$PlainText="%userprofile%\Application Data\Microsoft\Signatures"

if not exist ("%appdata%\microsoft\signatures\Mydomain")
md "%appdata%\microsoft\signatures\Mydomain"
endif

copy "\\Mydomain.corp\NETLOGON\HQ\Scripts\user\Mydomain" "%appdata%\microsoft\signatures\Mydomain"

if \$_office=""
if instr(\$userCN[0],"ou=UK,")
\$office="UK"
else
\$office="LA"
endif
endif

select
case  \$office="UK" ;or @fullname="Brian Lee"
\$company="Mydomain Europe"
\$Address="4th Floor, 111 Buckingham Palace Rd","Victoria, SW1W 0SR"
if ingroup("sz_UK_NoVAT")
\$legal="Mydomain (Europe) Limited","Registered office at 4th Floor, 111 Buckingham Palace Rd, London, SW1W 0SR"
else
\$legal="Mydomain (Europe) Limited","Registered in England & Wales under No. 05220340","Registered office at 4th Floor, 111 Buckingham Palace Rd, London, SW1W 0SR"
endif
case \$office="LA"
\$company="Mydomain, Inc"
\$Address="12200 W. Olympic Blvd, Ste 300","Los Angeles, Ca 90064"
\$legal="E-MAIL CONFIDENTIALITY NOTICE:  The contents of this e-mail message and any","attachments are intended solely for the addressee and may contain","confidential and/or legally privileged information. If you are not the","intended recipient of this message or if this message has been addressed to","you in error, please immediately alert the sender by reply e-mail and then","delete this message and any attachments. If you are not the intended ","recipient, you are notified that any use, dissemination, distribution,","copying, or storage of this message or any attachment is strictly prohibited."
case \$office="SD"
\$company="Mydomain, Inc"
\$Address="12200 W. Olympic Blvd, Ste 300","Los Angeles, Ca 90064"
\$legal="E-MAIL CONFIDENTIALITY NOTICE:  The contents of this e-mail message and any","attachments are intended solely for the addressee and may contain","confidential and/or legally privileged information. If you are not the","intended recipient of this message or if this message has been addressed to","you in error, please immediately alert the sender by reply e-mail and then","delete this message and any attachments. If you are not the intended ","recipient, you are notified that any use, dissemination, distribution,","copying, or storage of this message or any attachment is strictly prohibited."
endselect

\$objWord=CreateObject("Word.Application")
;\$objWord.visible="True"
\$ObjSelection=\$objWord.Selection

\$objEmailOptions=\$objWord.EmailOptions
\$objSignatureObject=\$objEmailOptions.EmailSignature
\$objSignatureEntries=\$objSignatureObject.EmailSignatureentries

;	\$objSelection.TypeParagraph()
\$objSelection.Font.Name="Verdana"
\$objSelection.Font.Size="10"
\$objSelection.Font.Bold=1
\$objSelection.Font.ColorIndex=15
;	\$objSelection.TypeText (chr(11))
;\$objSelection.TypeParagraph()
\$objSelection.TypeText (@fullname+chr(11))
;\$objSelection.TypeParagraph()
if \$title<>"" and \$title<>"<blank>"
\$objSelection.TypeText (\$title+chr(11))
endif

;\$objSelection.Type
\$objSelection.TypeText (\$company+chr(11))
\$objSelection.Font.Bold=0

if \$office<>"UK"
endif

if \$telephone<>"" and \$telephone<>"<blank>"
if \$telephone2<>"" and \$office="UK"
;\$objSelection.TypeText("Main UK Ph (Temp):  +44 (0) 207 029 3300"+chr(11))
\$objSelection.TypeText ("Tel/Fax (UK):  "+\$telephone+chr(11))
else
if \$office="UK"
;\$objSelection.TypeText("Main Ph:  +44 (0) 207 653 8500"+chr(11))
\$objSelection.TypeText ("Tel/Fax:  "+\$telephone+chr(11))
else
\$objSelection.TypeText("Tel/Fax: "+\$telephone+chr(11))
endif
endif
endif

if \$telephone2<>"" and \$telephone2<>"<blank>"
select
case instr(\$telephone2,"+49")
\$objSelection.TypeText ("Tel (DE):  "+\$telephone2+chr(11))
case instr(\$telephone2,"+33")
\$objSelection.TypeText ("Tel (FR):  "+\$telephone2+chr(11))
Case 1
\$objSelection.TypeText ("Other Tel:  "+\$telephone2+chr(11))
endselect
endif

if \$office="UK" and @fullname<>"Scott Macon"
\$objSelection.TypeText ("Alt Fax:  +44 (0) 207 653 8501"+chr(11))
;		\$objSelection.TypeText ("Alt Fax:  +44 (0) 207 258 7356"+chr(11))
endif

if \$mobile<>"" and \$mobile<>"<blank>"
if \$office="UK"
\$objSelection.TypeText ("Mob:  "+\$Mobile+chr(11))
else
\$objSelection.TypeText ("Cell:  "+\$Mobile+chr(11))
endif
endif

;\$objSelection.TypeParagraph()
;\$objSelection.TypeText (chr(11))
\$objSelection.Font.Size="7.5"

if \$office<>"UK"
\$objSelection.TypeText (chr(11))
endif

for each \$item in \$legal
\$objSelection.TypeText (\$item+chr(11))
next

;\$objSelection.TypeParagraph()
\$objSelection.TypeText(chr(11))
\$objSelection.TypeText(chr(11))
if \$office="UK"
\$objSelection.TypeText(chr(11))
\$objSelection.TypeText(" ")
\$objRange=\$objSelection.Range()
\$objSelection.TypeText(chr(11))
\$objSelection.TypeText(" ")
\$objRange=\$objSelection.Range()
\$objSelection.TypeText(chr(11))
\$objSelection.TypeText(" ")
\$objRange=\$objSelection.Range()
else
\$objSelection.TypeText(chr(11))
\$objRange=\$objSelection.Range()
endif

\$objSelection=\$objDoc.Range()
\$objSignatureObject.NewMessageSignature="Mydomain"
\$objDoc.Saved="True"
\$objSignatureObject.NewMessageSignature="Mydomain"

\$objWord.Quit

\$UserINI="%userprofile%\@userid.ini"
\$_=writeprofilestring(\$UserINI,"General","OutlookSignature","4")

else
?"Did not find Outlook.  Skipping..."
endif

endfunction

function installVNC ()

Dim \$MySite, \$UKVNC, \$LAVNC,\$machineINI

\$machineINI="c:\DOPSSettings"+@wksta+".ini"
\$MySite=DetermineSite()
\$UKVNC='\\Mydomain.corp\NETLOGON\HQ\Scripts\repository\VNC'
\$VNCInstallPath="C:\Program Files\UltraVNC"

?"  Running vnc install"
shell 'regedit /s '+\$UKVNC+'\ORL.Reg'
shell 'cmd /c '+\$UKVNC+'\UltraVNC-102-Setup.exe /loadinf='+\$UKVNC+'\ultravnc.inf /verysilent'
;		shell '%cmd% /c "'+\$UKVNC+'\UltraVNC-102-Setup.exe" /loadinf="'+\$UKVNC+'\ultravnc.inf" /verysilent'
;		sleep 45

if exist (\$vncinstallpath)
?"  Copying encryption application"
copy \$ukvnc+"\MSRC4Plugin_NoReg.dsm" \$VNCInstallPath /c
?"  Copying encryption key"
copy \$ukvnc+"\rc4.key" \$VNCInstallPath /c
?"  Setting up VNC with Mydomain setting"
shell 'regedit /s '+\$UKVNC+'\ORL.Reg'
?"  Enabling vnc to run as service"
shell 'cmd /c "'+\$VNCInstallPath+'\WinVnc.exe" -sinstall'
?
shell 'cmd /c net start "vnc server"'
?
if exist (\$vncinstallpath)
\$_=writeprofilestring(\$machineINI,"General","VNC","2")
endif

if exist(\$vncinstallpath+"\driver")
?"  Installing Mirror Driver"
shell 'cmd /c "'+\$vncinstallpath+'\driver\setupdrv" install'
shell 'cmd /c net stop vnccom'
shell 'cmd /c net start vnccom'
endif

else
sleep 15
?"  Copying encryption application"
copy \$ukvnc+"\MSRC4Plugin_NoReg.dsm" \$VNCInstallPath /c
?"  Copying encryption key"
copy \$ukvnc+"\rc4.key" \$VNCInstallPath /c
?"  Setting up VNC with Mydomain setting"
shell 'regedit /s '+\$UKVNC+'\ORL.Reg'
?"  Enabling vnc to run as service"
shell 'cmd /c "'+\$VNCInstallPath+'\WinVnc.exe" -sinstall'
shell 'cmd /c net start "vnc server"'

if exist (\$vncinstallpath)
\$_=writeprofilestring(\$machineINI,"General","VNC","1")
endif

endif

else
endif

shell 'regedit /s '+\$UKVNC+'\Execs.Reg'
\$_=writeprofilestring(\$machineINI,"General","RefuseVNC","1")
endif

;	\$fnCompOwner=GetOwner(@hostname)
;	?"Owner is "+\$fnCompOwner
;	if \$fnCompOwner<>""
;		\$fnIsExec=MemberOf (\$fnCompOwner,"sz_vnc_default_refuse")
;		?\$fnIsExec
;			?"Setting Default Connection Setting to refuse"
;			shell 'regedit /s '+\$UKVNC+'\Execs.Reg'
;			\$_=writeprofilestring(\$machineINI,"General","ExecVNC","1")
;		endif
;	endif

endfunction

function DetermineChassis(optional \$_Machine)

dim \$ChassisType, \$Chassis

if \$_Machine=""
\$_Machine=@wksta
endif

;Get Chasiss Type
\$WinMGT=GetObject("winmgmts:\\"+\$_Machine+"\root\cimv2")
;? "Attempting to retrieve " \$aResults[\$c,0]+CHR(39) "s Chassis information."
\$Chassis = \$WinMgt.ExecQuery("Select ChassisTypes from Win32_SystemEnclosure")
For Each \$item In \$Chassis
if (\$item.ChassisTypes(0))=8 or (\$item.ChassisTypes(0))=9 or (\$item.ChassisTypes(0))=10 or (\$item.ChassisTypes(0))=11 or (\$item.ChassisTypes(0))=12
\$ChassisType="Laptop"
endif
next

\$DetermineChassis=\$ChassisType
endfunction

function DetermineSite()

dim \$site

for \$nic=0 to 10
select
case instr (enumIPInfo(\$nic,0),"10.40.44")
\$site="UK"
case instr (enumIPInfo(\$nic,0),"10.40.110") or instr (enumIPInfo(\$nic,0),"10.40.9") or instr (enumIPInfo(\$nic,0),"10.40.101") or instr (enumIPInfo(\$nic,0),"10.40.130") or instr (enumIPInfo(\$nic,0),"10.40.132") or instr (enumIPInfo(\$nic,0),"10.40.140") or instr (enumIPInfo(\$nic,0),"10.40.142") or instr (enumIPInfo(\$nic,0),"172.16")
\$site="LA"
endselect
next

\$DetermineSite=\$Site

endfunction

function installVNC2 ()

Dim \$MySite, \$UKVNC, \$LAVNC,\$machineINI

\$machineINI="c:\DOPSSettings"+@wksta+".ini"
\$MySite=DetermineSite()
\$UKVNC='\\MyFileServ\install\$\PCSoftware\VNC'
\$VNCInstallPath="C:\Program Files\UltraVNC"

select
case \$MySite="UK"
?"Site UK..."
?"  Running vnc install"
if not exist (\$vncinstallpath)
md \$vncinstallpath

copy \$ukvnc+"\Programfiles\*.*" "c:\program files" /h /s /c /r
shell 'regedit /s '+\$UKVNC+'\class.Reg'
shell 'regedit /s '+\$UKVNC+'\ORL.Reg'
shell '"'+\$vncinstallpath+'\winvnc" -reinstall'
shell 'net start "WinVNC"'

if exist (\$vncinstallpath)
\$_=writeprofilestring(\$machineINI,"General","VNC","1")
endif
endif

case \$MySite="LA"

endselect
else
endif

endfunction

Function stddate(\$Shortdate)

DIM \$datesplit[2], \$SFormat

Select
Case \$SFormat = "dd/MM/yyyy"
\$stddate = SubSTR(\$Shortdate,7,4) + "/" +  SubSTR(\$Shortdate,4,2)+ "/" + SubSTR(\$Shortdate,1,2)

Case \$SFormat = "dd/MM/yy"
\$stddate = "20" + SubSTR(\$Shortdate,7,2) + "/" +  SubSTR(\$Shortdate,4,2)+ "/" + SubSTR(\$Shortdate,1,2)

Case \$SFormat = "d/M/yy"
\$datesplit = Split(\$Shortdate,"/")
If Len(\$datesplit[0]) = 1
\$datesplit[0] = "0" + \$datesplit[0]
EndIf

If Len(\$datesplit[1]) = 1
\$datesplit[1] = "0" + \$datesplit[1]
EndIf

\$stddate = "20" + \$datesplit[2] + "/" + \$datesplit[1] + "/" + \$datesplit[0]

Case \$SFormat = "d/M/yyyy"
\$datesplit = Split(\$Shortdate,"/")
If Len(\$datesplit[0]) = 1
\$datesplit[0] = "0" + \$datesplit[0]
EndIf

If Len(\$datesplit[1]) = 1
\$datesplit[1] = "0" + \$datesplit[1]
EndIf
\$stddate = \$datesplit[2] + "/" + \$datesplit[1] + "/" + \$datesplit[0]

Case \$SFormat = "d/MM/yyyy"
\$datesplit = Split(\$Shortdate,"/")
If Len(\$datesplit[0]) = 1
\$datesplit[0] = "0" + \$datesplit[0]
EndIf

\$stddate = \$datesplit[2] + "/" + \$datesplit[1] + "/" + \$datesplit[0]

Case \$SFormat = "yyyy-MM-dd"
\$stddate = SubSTR(\$Shortdate,1,4) + "/" +  SubSTR(\$Shortdate,6,2)+ "/" + SubSTR(\$Shortdate,9,2)

Case \$SFormat = "yy-MM-dd"
\$stddate = "20" + SubSTR(\$Shortdate,1,2) + "/" +  SubSTR(\$Shortdate,4,2)+ "/" + SubSTR(\$Shortdate,7,2)

Case \$SFormat = "M/dd/yy"
\$datesplit = Split(\$Shortdate,"/")
If Len(\$datesplit[0]) = 1
\$datesplit[0] = "0" + \$datesplit[0]
EndIf
\$stddate = "20" + \$datesplit[2] + "/" + \$datesplit[0] + "/" + \$datesplit[1]

Case \$SFormat = "M/d/yyyy"
\$datesplit = Split(\$Shortdate,"/")
If Len(\$datesplit[0]) = 1
\$datesplit[0] = "0" + \$datesplit[0]
EndIf
If Len(\$datesplit[1]) = 1
\$datesplit[1] = "0" + \$datesplit[1]
EndIf
\$stddate = \$datesplit[2] + "/" + \$datesplit[0] + "/" + \$datesplit[1]

Case 1
Exit 99
EndSelect

EndFunction

FUNCTION RPCOUTLOOK(\$_FromOffice,\$_machinetype)

DIM \$prfrem,\$waste,\$explorview,\$editorpref,\$prf,\$serverloc,
\$exchgsvr,\$prfloc,\$prffile,\$ppru,\$exe,\$ver,\$idx,\$keyname,\$rc,

\$waste='FALSE'    ; Empty Outlooks Deleted Items Folder on Exit
\$explorview='Yes' ; Outlook Explorer View 'Yes' or Standard View 'No'
\$editorpref=20001 ; Editor Preference 10001=Plain Text, 20001=HTML, and 30001=Rich Text
\$prf='RPCOutlook.prf'
\$prffile=%userprofile%+'\'+\$prf
\$serverloc='\\Mydomain.corp\NETLOGON\HQ\Scripts\User' ; Outlook Executables files location
if \$_FromOffice="UK"
\$exchgsvr='Myfileserv.Mydomain.inc'     ; Main Exchange Server Location
else
\$exchgsvr='szexchange.Mydomain.inc'
endif

if \$_MachineType="Laptop"
\$CacheMode="0x00000100"
else
\$CacheMode="0x00000000"
endif

IF @INWIN ;Windows NT/2k/XP/2003
\$prfloc='HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles'
ELSE
;Windows 9x
\$prfloc='HKCU\Software\Microsoft\Windows Messaging Subsystem\Profiles'
ENDIF
; -- Current User Profile
\$ppru=\$prfloc+'\'+@USERID

; -- Determine version of Outlook
\$ver=SPLIT(GetFileVersion(\$exe),'.')[0]+'.0'
\$MSOdir=SUBSTR(\$exe,1,Len(\$exe)-11)

;?"found version "+\$ver
; -- This is used for when you have people come into the company from another Exchange Server into yours
\$rc=WriteValue(\$ppru+'\13dbb0c8aa05101a9bb000aa002fc45a','001e6602',\$exchgsvr,'REG_SZ')
\$rc=WriteValue(\$ppru+'\13dbb0c8aa05101a9bb000aa002fc45a','001e6608',\$exchgsvr,'REG_SZ')
ENDIF

; -- Look for Outlook Profile

;		\$MBAnswer=messagebox("Did not find an Outlook profile.  Would you like to set one up for this machine? Select NO to permanently disable this message without configuring Outlook on this machine.  Choose CANCEL to try again later.","Setup Outlook Profile",515,20)
select
COPY \$serverloc+'\'+\$prf \$prffile
\$rc=WriteProfileString(\$prffile,'General','ProfileName',@Fullname+" - Exchange")
\$rc=WriteProfileString(\$prffile,'General','DefaultProfile','Yes')
\$rc=WriteProfileString(\$prffile,'General','OverwriteProfile','Yes')
\$rc=WriteProfileString(\$prffile,'General','BackupProfile','No')
\$rc=WriteProfileString(\$prffile,'Service1','AutoNameCheck','TRUE')
\$rc=WriteProfileString(\$prffile,'Service1','CloseOriginalMessage','TRUE')
\$rc=WriteProfileString(\$prffile,'Service1','HomeServer',\$exchgsvr)
\$rc=WriteProfileString(\$prffile,'Service1','MailboxName',@fullname)
\$rc=WriteProfileString(\$prffile,'ServiceEGS','MailboxName',@fullname)
\$rc=WriteProfileString(\$prffile,'ServiceEGS','HomeServer',\$exchgsvr)
\$rc=WriteProfileString(\$prffile,'ServiceEGS','CachedExchangeConfigFlags',\$CacheMode)

if \$_MachineType="Laptop"
\$rc=writeprofilestring(\$prffile,'ServiceEGS','RPCoverHTTPflags','0x002b')
\$rc=writeprofilestring(\$prffile,'ServiceEGS','RPCProxyServer','webmail.Mydomain.com')
\$rc=writeprofilestring(\$prffile,'ServiceEGS','RPProxyAuthScheme=0x0001')
\$rc=writeprofilestring(\$prffile,'ServiceEGS','RPCProxyPrincipalName','')

if \$_fromOffice="UK"
\$rc=writeprofilestring(\$prffile,'ServiceEGS','RPCProxyServer','ukwebmail.Mydomain.com')
endif
endif

SELECT
CASE \$ver='8.0' OR \$ver='9.0' ;(e.g. 8.5.5104.0)
SHELL '%COMSPEC% /C '+\$serverloc+'\newprof.exe -p '+\$prffile+' -x'
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook','Machine Name',@WKSTA,'REG_SZ')
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook','CheckInternetAccounts',1,'REG_DWORD')
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook','FirstRunDialog','False','REG_SZ')
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook\Setup','PrimaryClient',1,'REG_DWORD')
\$rc=WriteValue('HKLM\Software\Microsoft\Office\'+\$ver+'\Outlook\Setup','MailSupport',1,'REG_DWORD')

IF \$explorview='Yes'
\$rc=WriteValue(\$prfloc+@userid+'\0a0d020000000000c000000000000046','001e0360','','REG_SZ')
\$expview='010000002c0000000200000003000000ffffffffffffffffffffffffffffffff62000000270000003'
\$expview=\$expview+'c030000ac02000001000000000000000100000000000000c00000006400000003000000'
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook\Office Explorer','Frame',\$expview,'REG_BINARY')
ENDIF

CASE \$ver='10.0' OR \$ver='11.0'  OR \$ver='12.0';(e.g. 10.0.2627.1)
\$rc=DelValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook\Setup','First-Run')
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook\Setup','ImportPRF',\$prffile,'REG_SZ')

IF \$ver='10.0' or \$ver='12.0'
\$rc=WriteValue('HKCU\Software\Microsoft\Office\'+\$ver+'\Outlook\IM','Enabled',0,'REG_DWORD')
ENDIF
; -- This was added as we needed to generate Outlook Profiles in a Citrix Session - thanks Rad!
\$outlook=CreateObject('Outlook.Application')
\$ns=\$outlook.getnamespace('MAPI')
\$fldr=\$ns.getdefaultfolder(6)
\$outlook=0
ENDSELECT

DEL \$MSOdir+'welcome.msg'
;				if readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"+\$DefaultProfile+"\00000001","New Signature")<>"53686f707a696c6c61000000"
;					\$_=OutlookSignature()
;				endif

endselect
ENDIF

ENDFUNCTION

Function fromSite()

Dim \$MySite

if instr(\$MyOu[0],"ou=UK,")
\$MySite="UK"
else
\$MySite="LA"
endif

\$fromSite=\$Mysite

endfunction

Function RegHextoAscii(\$data)
dim \$return, \$i, \$hex
for \$i = 1 to len(\$data) step 2
\$hex = "&" + substr(\$data,\$i,2)
\$return = \$return + chr(val(\$hex))
next
\$reghextoascii = \$return
endfunction

Function udfSID2String(\$aiSID)
Dim \$i,\$dAuth

\$udfSID2String="S-"+\$aiSID[0]+"-"+\$aiSID[1]+"-"+\$aiSID[8]

For \$i = 12 To UBound(\$aiSID) Step 4
\$dAuth=CDbl(\$aiSid[\$i+3])
\$dAuth=\$dAuth*256+CDbl(\$aiSid[\$i+2])
\$dAuth=\$dAuth*256+CDbl(\$aiSid[\$i+1])
\$dAuth=\$dAuth*256+CDbl(\$aiSid[\$i+0])
\$udfSID2String=\$udfSID2String+"-"+CStr(\$dAuth)
Next

EndFunction

Function udfBytes2Array(\$abBytes)

If @ERROR Exit @ERROR EndIf

\$oStream.Open
\$oStream.Write(\$abBytes)
\$oStream.Position=0

Redim Preserve \$udfBytes2Array[\$oStream.Size-1]

For \$i = 0 To UBound(\$udfBytes2Array)
Next

\$oStream=0

Exit 0

EndFunction

; Convert an array of integers to an array of bytes

Function udfArray2Bytes(\$aiBytes,Optional \$iBytesToConvert)

If Not \$iBytesToConvert \$iBytesToConvert=UBound(\$aiBytes)+1 EndIf

If @ERROR Exit @ERROR EndIf

\$oStream.Open

For \$i = 1 To \$iBytesToConvert
\$oStream.Write(udfIntToByte(\$aiBytes[\$i-1]))
Next

\$oStream.Position=0

Exit 0

EndFunction

; Convert a single integer to a byte array

Function udfIntToByte(\$i)

If @ERROR Exit @ERROR EndIf

\$i=CInt(\$i) & 255
\$oStream.CharSet="unicode"
\$oStream.Open
\$oStream.WriteText(" "+Chr(\$i))
\$oStream.Position=0

If \$i
\$oStream.Position=\$oStream.Size-2
Else
\$oStream.Position=\$oStream.Size-1
EndIf

Exit 0

EndFunction

function wshShortCut(\$shortcutname,\$targetpath,optional \$arguments, optional \$startdir, optional \$iconpath, optional \$style,optional \$description)
;\$_=wshShortcut ("My Documents.lnk",@homeshr+"\"+@homedir,"","","","","")

dim \$shell, \$desktop, \$shortcut, \$index, \$iconinfo, \$iconindex
\$shell = createobject("wscript.shell")
if \$shell

if ucase(right(\$shortcutname,4))=".URL" or ucase(right(\$shortcutname,4))=".LNK"
;do nothing
else
if ucase(left(\$targetpath,5))="HTTP:" or ucase(left(\$targetpath,6))="HTTPS:" or ucase(left(\$targetpath,4))="FTP:"
\$shortcutname=\$shortcutname + ".url"
else
\$shortcutname=\$shortcutname + ".lnk"
endif
endif

if instr(\$shortcutname,".lnk") and not exist(\$targetpath)
;      exit 2
endif

if instr(\$shortcutname,"\")=0
\$Desktop = \$shell.SpecialFolders("Desktop")
\$shortcutname="%userprofile%" + "\" + \$shortcutname
endif

\$shortcut = \$shell.createshortcut(\$shortcutname)

if \$shortcut
\$shortcut.targetpath = \$targetpath
if \$iconpath
\$shortcut.iconlocation = \$iconpath
endif

if \$arguments
\$shortcut.arguments = \$arguments
endif

if \$startdir
\$shortcut.workingdirectory = \$startdir
endif

if \$style
\$shortcut.windowstyle = \$style
endif

If \$description
\$shortcut.description = \$description
EndIf

\$shortcut.save

if instrrev(\$shortcutname,".url") and \$iconpath
\$index=instrrev(\$iconpath,",")

if \$index=0
\$iconindex=0
else
\$iconindex=split(\$iconpath,",")[1]
\$iconpath=split(\$iconpath,",")[0]
endif

\$=writeprofilestring(\$shortcutname,"InternetShortcut","IconFile",\$iconpath)
\$=writeprofilestring(\$shortcutname,"InternetShortcut","IconIndex",\$iconindex)
endif

\$shortcut = 0
\$wshshortcut=0
else
;		      exit @error
endif

else
;    		exit @error
endif

endfunction

function inputpw()

dim \$fnPW1, \$fnPW2, \$fnInput

do
\$fnPW1=""
\$fnPW2=""

do
flushkb
get \$fnInput

if \$fnInput<>chr(8)
if \$fnInput<>chr(13)
'*'
endif

if \$fnPW1="" and \$fnInput<>chr(13)
\$fnPW1=\$fnInput
else
if \$fnInput<>chr(13)
\$fnPW1=\$fnPW1+\$fnInput
endif
endif

if \$fnInput<>chr(13)
\$fnInput=""
endif
else
if len(\$fnPW1)>0
chr(8)+" "+chr(8)
\$fnPW1=left(\$fnPW1,len(\$fnPW1)-1)
endif
endif
until \$fnInput=chr(13)

\$fnInput=""

do
flushkb
get \$fnInput

if \$fnInput<>chr(8)
if \$fnInput<>chr(13)
'*'
endif

if \$fnPW2="" and \$fnInput<>chr(13)
\$fnPW2=\$fnInput
else
if \$fnInput<>chr(13)
\$fnPW2=\$fnPW2+\$fnInput
endif
endif

if \$fnInput<>chr(13)
\$fnInput=""
endif
else
if len(\$fnPW2)>0
chr(8)+" "+chr(8)
\$fnPW2=left(\$fnPW2,len(\$fnPW2)-1)
endif
endif
until \$fnInput=chr(13)

if \$fnPW1<>\$fnPW2
?
?
?
endif
until \$fnPW1=\$fnPW2

\$inputPW=\$fnPW1

endfunction

function inputpw2()

dim \$fnPW1, \$fnPW2, \$fnInput

\$fnPW1=""

do
flushkb
get \$fnInput

if \$fnInput<>chr(8)
if \$fnInput<>chr(13)
'*'
endif

if \$fnPW1="" and \$fnInput<>chr(13)
\$fnPW1=\$fnInput
else
if \$fnInput<>chr(13)
\$fnPW1=\$fnPW1+\$fnInput
endif
endif

if \$fnInput<>chr(13)
\$fnInput=""
endif
else
if len(\$fnPW1)>0
chr(8)+" "+chr(8)
\$fnPW1=left(\$fnPW1,len(\$fnPW1)-1)
endif
endif
until \$fnInput=chr(13)

\$inputPW2=\$fnPW1

endfunction

Function InstallSnare (\$fnSrvName)

Dim \$fnRegSnareVersionPath,\$fnCurrentVersion,\$fnLastVersion, \$fnRobocopy,\$fnVersionPath,\$fnRegSnareVersionPath
Dim \$fnSnareVersion,\$fnRemoteSnareFolder,\$fnRemotePF,\$fnTemplateServer,\$fnError

\$fnRobocopy="\\Mydomain.corp\NETLOGON\HQ\Scripts\robocopy.exe"
\$fnlastVersion="2.6.7"
\$fncurrentVersion="2.6.7"
\$fnRemoteProgramFolder="\c\$\Program Files"
\$fnSnareFolder="\Snare"
\$fninstallLocation="\\thoth\install\snare\ScriptDeploy"
\$fnRegSnareVersionPath="\HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Snare_is1"

if ping (\$fnTemplateServer)

if ping (\$fnSrvName)
if exist ("\\"+\$fnSrvName+"\c\$\Program Files\Snare")
\$fnVersionPath="\\"+\$fnSrvName+\$fnRegSnareVersionPath
if \$fnSnareVersion=\$fncurrentVersion
?"Found version 2.6.7"
\$_=SvcAction(\$fnSrvName,"Snare","Stop")
shell 'cmd /c reg copy "\\'+\$fnTemplateServer+'\hklm\software\InterSect Alliance" "\\'+\$fnSrvName+'\hklm\software\InterSect Alliance" /s /f >NUL'
\$_=SvcAction(\$fnSrvName,"Snare","Start")
else
?"Version unknown."
endif
else
if exist ("\\"+\$fnSrvName+"\c\$")
?"Snare  is not installed.  Deploying..."

\$fnremotePF="\\"+\$fnSrvName+\$fnremoteProgramFolder
\$fnremoteSnareFolder=\$fnremotePF+\$fnSnareFolder
if exist (\$fnremotePF) and exist (\$fninstallLocation)
?"  Creating folder and copying file to "+\$fnremoteSnareFolder
shell 'cmd /c '+\$fnrobocopy+' "'+\$fninstallLocation+'\Snare'+'" "'+\$fnremoteSnareFolder+'" /e /w:0 /r:0 > NUL'

if exist (\$fnremoteSnareFolder+"\snarecore.exe")
?"  Folder created.  Files copied."
?"  Applying Mydomain's base Snare configuration."
shell 'cmd /c reg copy "\\'+\$fnTemplateServer+'\hklm\software\InterSect Alliance" "\\'+\$fnSrvName+'\hklm\software\InterSect Alliance" /s /f >NUL'

if not keyexist('\\'+\$fnSrvName+'\hklm\software\InterSect Alliance')
\$fnError=1
endif

if \$fnError<>1
?"  Installing Service as Snare."
shell 'cmd /c sc \\'+\$fnSrvName+' create Snare binPath= "c:\program files\Snare\SnareCore.exe" start= auto DisplayName= Snare >NUL'
?"  Starting Snare service."
shell 'cmd /c sc \\'+\$fnSrvName+' start Snare >NUL'
endif

shell 'cmd /c sc \\'+\$fnSrvName+' query Snare |find /i "running" > NUL'
\$fnError=@error

if \$fnError=1
?"!!!  Error copying files.  Rolling back installation."
\$_=UninstallSnare(\$fnSrvName)
endif

else
?"!!!  Error copying files.  Rolling back installation."
\$_=UninstallSnare(\$fnSrvName)
endif
else
?"  Aborting.  Did not find either Program Folder on remote machine or the installation folder."
endif

else
?"Unable to connect to \\"+\$fnSrvName+"\c\$\Program Files\Snare"
endif
endif
endif
else
?"Unable to connect to template server ("+\$fnTemplateServer+").  Please try again later."
endif

EndFunction

Function UninstallSnare (\$fnSrvName)

dim \$fnServiceState, \$fnServiceInstall, \$fnREgistry

shell 'cmd /c sc \\'+\$fnSrvName+' query Snare|find /i "Running">NUL'
\$fnServiceState=@error
shell 'cmd /c sc \\'+\$fnSrvName+' query Snare|find /i "Snare">NUL'
\$fnServiceInstall=@error
?"Uninstalling Snare from "+\$fnSrvName
if \$fnServiceState=0
?"  Snare service is running.  Stopping..."
shell 'cmd /c sc \\'+\$fnSrvName+' stop Snare >NUL'
endif

if \$fnServiceInstall=0
?"  Snare service is installed.  Uninstalling service..."
shell 'cmd /c sc \\'+\$fnSrvName+' delete Snare >NUL'
endif

if keyexist('\\'+\$fnSrvName+'\hklm\software\InterSect Alliance') and \$fnSrvName<>""
?"  Removing settings..."
shell 'cmd /c reg delete "\\'+\$fnSrvName+'\HKLM\Software\InterSect Alliance" /f >NUL'
endif

If exist("\\"+\$fnSrvName+"\c\$\Program Files\Snare")
?"  Deleting files"
shell 'cmd /c rd "\\'+\$fnSrvName+'\c\$\Program Files\Snare" /S /Q >NUL'
endif

EndFunction

FUNCTION GetPage(\$URL)

;Function:
;   GetPage()
;
;KiXtart URL:
;   http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000436
;
;Author:
;
;Version:
;   1.1
;
;Version History:
;
;   v.1.0 [2003-07-01 16:05] Original Version.
;   v.1.1 [2003-09-05 10:52] Suggestion by Bryce implemented. The UDF now changes
;                            the IE cache settings to make sure a non-cached page
;                            is retrieved. The original cache setting is restored
;                            after each call.
;
;Action:
;   Loads an (uncached version of a) webpage into a variable.
;
;Syntax:
;   GetPage(STRING)
;
;Parameters:
;   STRING [REQUIRED]: URL of the page you want to retrieve.
;
;
;Remarks:
;   Lonkero has helped me out with this one    I only added the Status bit, and
;   posted it in a UDF-friendly format with a sample
;   HTTP Status Codes:
;   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winhttp/http/http_status_codes.asp
;   For example, An unknown DNS name returns .Status = 12xxx (ex: 12007), and
;   .Statustext = "Unknown"
;
;Returns:
;   * The Response text (non-cached version) if successful
;   * Error code 1 along with the returned HTTP status code and status text if
;     there was an error getting the page.
;
;Dependencies:
;   KiX 4.02, IE v.5+
;
;Example:
;   ; *** Get the webpage, and extract the title ***
;   \$myPage = GetPage("http://www.kixtart.org/cgi-bin/ultimatebb.cgi")
;   IF @ERROR = 0
;       \$myPageTitle = SPLIT(\$myPage, "</title>")[0]
;       \$myPageTitle = SUBSTR(\$myPageTitle, INSTR(\$myPageTitle, "<title>") + 7, LEN(\$myPageTitle))
;       ? "Web page title: " + \$myPageTitle
;   ELSE
;       ? "An error occured: " + \$myPage
;   ENDIF

DIM \$HTML, \$IECacheKey, \$IECacheVal
\$IECacheKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
If \$IECacheVal <> 3
\$nul = WriteValue(\$IECacheKey, "SyncMode5", "3", "REG_DWORD")
EndIf

\$HTML = CreateObject("microsoft.XMLhttp")
\$HTML.Open("GET", \$URL, NOT 1)
\$HTML.Send

If \$HTML.Status = 200
\$GetPage = \$HTML.ResponseText ;or ResponseBody
Else
\$GetPage = "HTTP Status Code: " + \$HTML.Status + " (" + \$HTML.StatusText + ")"
Exit 1
EndIf

\$nul = WriteValue(\$IECacheKey, "SyncMode5", \$IECacheVal, "REG_DWORD")

ENDFUNCTION

Function NemoHostStatus(\$fnHost)
Dim \$fnNemoServer,\$fnAuthor, \$fnMSG

\$fnNemoServer="nemo.Mydomain.com"

\$IECacheKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"

IF \$IECacheVal <> 3
\$nul = WRITEVALUE(\$IECacheKey, "SyncMode5", "3", "REG_DWORD")
ENDIF

\$fnURL='https://'+\$fnNemoServer+'/nagios/cgi-bin/extinfo.cgi?type=1&host='+\$fnHostFQDN
\$fnHTMLObj = CREATEOBJECT("microsoft.XMLhttp")
\$fnHTMLObj.Open("GET", \$fnURL, NOT 1)
\$fnHTMLObj.Send

;	?\$fnURL
;	?\$fnHTMLObj.responsetext

if not instr (\$fnHTMLObj.responsetext,"It appears as though you do not have permission to view information for this host")
if instr (\$fnHTMLObj.responsetext,'In Scheduled Downtime?</td><td CLASS='+chr(39)+'dataVal'+chr(39)+'><DIV CLASS='+chr(39)+'downtimeINACTIVE'+chr(39)+'>&nbsp;&nbsp;NO&nbsp;&nbsp;</DIV></td></tr>')
\$NemoHostStatus=1
endif

if instr (\$fnHTMLObj.responsetext,'In Scheduled Downtime?</td><td CLASS='+chr(39)+'dataVal'+chr(39)+'><DIV CLASS='+chr(39)+'downtimeACTIVE'+chr(39)+'>&nbsp;&nbsp;YES&nbsp;&nbsp;</DIV></td></tr>')
\$NemoHostStatus=2
endif

else

\$fnHostFQDN=lcase(\$fnHost+".Mydomain.com")
\$fnURL='https://'+\$fnNemoServer+'/nagios/cgi-bin/extinfo.cgi?type=1&host='+\$fnHostFQDN
\$fnHTMLObj = CREATEOBJECT("microsoft.XMLhttp")
\$fnHTMLObj.Open("GET", \$fnURL, NOT 1)
\$fnHTMLObj.Send

if not instr (\$fnHTMLObj.responsetext,"It appears as though you do not have permission to view information for this host")
if instr (\$fnHTMLObj.responsetext,'In Scheduled Downtime?</td><td CLASS='+chr(39)+'dataVal'+chr(39)+'><DIV CLASS='+chr(39)+'downtimeINACTIVE'+chr(39)+'>&nbsp;&nbsp;NO&nbsp;&nbsp;</DIV></td></tr>')
\$NemoHostStatus=1
endif

if instr (\$fnHTMLObj.responsetext,'In Scheduled Downtime?</td><td CLASS='+chr(39)+'dataVal'+chr(39)+'><DIV CLASS='+chr(39)+'downtimeINACTIVE'+chr(39)+'>&nbsp;&nbsp;YES&nbsp;&nbsp;</DIV></td></tr>')
\$NemoHostStatus=2
endif
else
\$fnHostFQDN=lcase(\$fnHost+".bizrate.com")
\$fnURL='https://'+\$fnNemoServer+'/nagios/cgi-bin/extinfo.cgi?type=1&host='+\$fnHostFQDN
\$fnHTMLObj = CREATEOBJECT("microsoft.XMLhttp")
\$fnHTMLObj.Open("GET", \$fnURL, NOT 1)
\$fnHTMLObj.Send

if not instr (\$fnHTMLObj.responsetext,"It appears as though you do not have permission to view information for this host")
if instr (\$fnHTMLObj.responsetext,'In Scheduled Downtime?</td><td CLASS='+chr(39)+'dataVal'+chr(39)+'><DIV CLASS='+chr(39)+'downtimeINACTIVE'+chr(39)+'>&nbsp;&nbsp;NO&nbsp;&nbsp;</DIV></td></tr>')
\$NemoHostStatus=1
endif

if instr (\$fnHTMLObj.responsetext,'In Scheduled Downtime?</td><td CLASS='+chr(39)+'dataVal'+chr(39)+'><DIV CLASS='+chr(39)+'downtimeINACTIVE'+chr(39)+'>&nbsp;&nbsp;YES&nbsp;&nbsp;</DIV></td></tr>')
\$NemoHostStatus=2
endif
else
\$NemoHostStatus=0
endif
endif

\$nul = WRITEVALUE(\$IECacheKey, "SyncMode5", \$IECacheVal, "REG_DWORD")

EndFunction

Function NemoHostMaintenance(\$fnHost,\$fnMinutes)

Dim \$fnNemoServer,\$fnAuthor, \$fnMSG

\$fnNemoServer="nemo.Mydomain.com"
\$fnAuthor="WinKixScript"
\$fnMSG="Nagios+down+time+script"

\$fnMinutes=val(\$fnMinutes)
\$fnCurTime=NemoTimeCalc(0)
\$fnEndTime=NemoTimeCalc(\$fnMinutes)
\$IECacheKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"

IF \$IECacheVal <> 3
\$nul = WRITEVALUE(\$IECacheKey, "SyncMode5", "3", "REG_DWORD")
ENDIF

\$fnURL='https://'+\$fnNemoServer+'/nagios/cgi-bin/cmd.cgi?cmd_typ=55&cmd_mod=2&host='+\$fnHostFQDN+'&com_author='+\$fnAuthor+'&com_data='+\$fnMSG+'&trigger=0&start_time='+\$fnCurTime+'&end_time='+\$fnEndTime+'&fixed=1&btnSubmit=Commit'
;	?\$fnURL
\$fnHTMLObj = CREATEOBJECT("microsoft.XMLhttp")
\$fnHTMLObj.Open("GET", \$fnURL, NOT 1)
\$fnHTMLObj.Send

if instr (\$fnHTMLObj.responsetext,"Your command request was successfully submitted to Nagios")
?"Nagios successfully updated"
\$NemoHostMaintenance=1
else

\$fnHostFQDN=lcase(\$fnHost+".Mydomain.com")
\$fnURL='https://'+\$fnNemoServer+'/nagios/cgi-bin/cmd.cgi?cmd_typ=55&cmd_mod=2&host='+\$fnHostFQDN+'&com_author='+\$fnAuthor+'&com_data='+\$fnMSG+'&trigger=0&start_time='+\$fnCurTime+'&end_time='+\$fnEndTime+'&fixed=1&btnSubmit=Commit'
\$fnHTMLObj = CREATEOBJECT("microsoft.XMLhttp")
\$fnHTMLObj.Open("GET", \$fnURL, NOT 1)
\$fnHTMLObj.Send

if not instr (\$fnHTMLObj.responsetext,"Your command request was successfully submitted to Nagios")

\$fnHostFQDN=lcase(\$fnHost+".bizrate.com")
\$fnURL='https://'+\$fnNemoServer+'/nagios/cgi-bin/cmd.cgi?cmd_typ=55&cmd_mod=2&host='+\$fnHostFQDN+'&com_author='+\$fnAuthor+'&com_data='+\$fnMSG+'&trigger=0&start_time='+\$fnCurTime+'&end_time='+\$fnEndTime+'&fixed=1&btnSubmit=Commit'
\$fnHTMLObj = CREATEOBJECT("microsoft.XMLhttp")
\$fnHTMLObj.Open("GET", \$fnURL, NOT 1)
\$fnHTMLObj.Send

if not instr (\$fnHTMLObj.responsetext,"Your command request was successfully submitted to Nagios")
\$Subject="@wksta Restarted.  Please ignore Nemo warning"
\$Body="ComputerName: "+\$fnHost+chr(13)+chr(13)+"Unable to update Nemo maintenance schedule.  If the warning persists for more than "+\$fnMinutes+" minutes, please power down and power up the server.  Current time is @time"
\$NemoHostMaintenance=0
else
\$NemoHostMaintenance=1
endif

else
\$NemoHostMaintenance=1
endif
endif

;	if \$fnHTMLObj.STatus=200
;		\$NemoHostMaintenance=\$fnHTMLObj.responsetext
;	else
;		\$NemoHostMaintenance="HTTP Status Code: "+\$fnHTMLObj.Status+" ("+\$fnHTMLObj.StatusText+") "
;	endif

\$nul = WRITEVALUE(\$IECacheKey, "SyncMode5", \$IECacheVal, "REG_DWORD")

EndFunction

Function NemoTimeCalc (\$fnMinutes)

\$fnTime=split(@time,":")
\$fnSec=val(\$fnTime[2])
\$fnSecMin=val(\$fnTime[1])*60
\$fnSecHR=val(\$fnTime[0])*3600
\$fnTimeSec=\$fnSec+\$fnSecMin+\$fnSecHR
\$fnMinLater=60*\$fnMinutes
\$fnFuture=\$fnTimeSec+\$fnMinLater
\$fnHR=\$fnFuture/3600
\$fnTmp=\$fnFuture mod 3600
\$fnMin=\$fnTmp/60
\$fnS=\$fnTmp mod 60

if \$fnHR>23
\$fnFutureDate=datecalc(@date,1)
\$fnHR=\$HR-24
else
\$fnFutureDate=@date
endif

\$fnTmpDate=split(stddate(\$fnFutureDate),"/")

if \$fnHR<10
\$fnHR="0"+cstr(\$fnHR)
endif

if \$fnMin<10
\$fnMin="0"+cstr(\$fnMin)
endif

if \$fnS<10
\$fnS="0"+cstr(\$fnS)
endif

\$fnNemoDate=\$fntmpDate[2]+"-"+\$fntmpDate[0]+"-"+\$fntmpDate[1]
\$NemoTimeCalc=\$fnNemoDate+" "+cstr(\$fnHR)+":"+cstr(\$fnMin)+":"+cstr(\$fnS)

EndFunction

Function ClearLog (\$fnLogName,\$fnLogSize,optional \$fnBackup)

if exist (\$fnLogName)
\$fnObjFSO=CreateObject("Scripting.FileSystemObject")
\$fnFolderObj=\$fnObjFSO.GetFile(\$fnLogName)
if val (\$fnFolderObj.Size)>\$fnLogSize
del \$fnLogName
endif
endif

Endfunction

function CompareFile (\$fnFolder1,\$fnFolder2)
Dim \$fnCommand

\$fnCommand='@@echo y|comp "'+\$fnFolder1+'" "'+\$fnFolder2+'"|find /i "files compare OK"'
if exist (\$fnFolder1)
;		?\$fnFolder1
endif

if exist (\$fnFolder2)
;		?\$fnFolder2
endif

?
shell 'cmd /c '+\$fnCommand+'>NUL'

if @error=0
\$CompareFile=1
else
\$CompareFile=0
endif

endfunction

function DatePassed (\$_Date1,\$_Date2)

if instr (\$_Date1,"/") and instr (\$_Date2,"/")
\$fnTmpDate1=split(\$_Date1,"/")
\$fnTmpDate2=split(\$_Date2,"/")

\$tmpDatePassed=1

if val(\$fnTmpDate1[0])>val(\$fnTmpDate2[0])
\$tmpDatePassed=0
else
;			?"  year1="+\$fnTmpDate1[0]+"   year2="\$fnTmpDate2[0]
if val(\$fnTmpDate1[1])>val(\$fnTmpDate2[1]) and val(\$fnTmpDate1[0])>=val(\$fnTmpDate2[0])
\$tmpDatePassed=0
else
;				?"  month1="+\$fnTmpDate1[1]+"   month2="\$fnTmpDate2[1]
if val(\$fnTmpDate1[2])>val(\$fnTmpDate2[2]) and val(\$fnTmpDate1[1])>=val(\$fnTmpDate2[1]) and val(\$fnTmpDate1[0])>=val(\$fnTmpDate2[0])
\$tmpDatePassed=0
else
;					?"  day1="+\$fnTmpDate1[2]+"   day2="\$fnTmpDate2[2]
endif
endif
endif

\$DatePassed=\$tmpDatePassed

endif

endfunction

function DBCommand(\$ConnDSN,\$sql)

dim \$Conntimeout, \$CmdTimeout
dim \$cmdCommand, \$rsRecordset  dim \$Records, \$FinalRecords
dim \$row, \$rows, \$column, \$columns

\$ConnDSN=trim(\$ConnDSN)

if not \$ConnDSN
exit 87
endif

\$sql=trim(\$sql)

if not \$sql
exit 87
endif

; default database parameters
\$ConnTimeout=15
\$CmdTimeout=30

; open the database connection

if @ERROR
exit @ERROR
endif

\$objConn.ConnectionTimeout = \$ConnTimeout

if @ERROR
exit @ERROR
endif

\$objConn.CommandTimeout = \$CmdTimeout

if @ERROR
exit @ERROR
endif

\$objConn.Open(\$ConnDSN)

if @ERROR
exit @ERROR
endif

\$objConn=''
\$DBCommand=''
exit @ERROR
endif

; create the database command object
if @ERROR
exit @ERROR
endif

\$cmdCommand.ActiveConnection = \$objConn

if @ERROR
exit @ERROR
endif

if @ERROR
exit @ERROR
endif

\$cmdCommand.CommandText = \$sql

if @ERROR
\$DBCommand=@ERROR
exit @ERROR
endif

if instr(\$sql,'SELECT')=1
; create the recordset object

if @ERROR
exit @ERROR
endif

if @ERROR
exit @ERROR
endif

if @ERROR
exit @ERROR
endif

\$rsRecordset.Open(\$cmdCommand)

if @ERROR
exit @ERROR
endif

if \$rsRecordset.EOF and \$rsRecordSet.BOF
; recordset is empty
\$FinalRecords=''
else

if @ERROR
exit @ERROR
endif

; retrieve all records at once and transpose into tabular format
\$Records = \$rsRecordset.GetRows()
\$columns=ubound(\$records,1)
\$rows=ubound(\$records,2)
redim \$FinalRecords[\$rows,\$columns]

for \$row=0 to \$rows
for \$column=0 to \$columns
\$FinalRecords[\$row,\$column]=\$records[\$column,\$row]
next
next

endif    ; close recordset

\$rsRecordset.Close()

if @ERROR
exit @ERROR
endif

endif

\$rsRecordset=''
\$cmdCommand=''
\$DBCommand=\$FinalRecords

else
\$rsRecordset=\$cmdCommand.Execute()
\$cmdCommand=''
\$rsRecordset=''

if @ERROR
exit @ERROR
endif

\$DBCommand=0

endif

; close the database connection

\$objConn.Close()

if @ERROR
exit @ERROR
endif

EndIf

\$objConn=''

exit 0

endfunction

Function fnInteger8Date(\$objDate,Optional \$lngBias)
Dim \$lngHigh,\$lngLow,\$lngDate,\$Pow,\$l,\$jdate,\$lngYear,\$lngMonth,\$lngDay,\$s,\$m,\$h
If Not (VarType(\$objDate) & 9) Exit 87 EndIf
If VarType(\$lngBias)=0
If @ERROR Exit @ERROR EndIf
EndIf

\$lngHigh = \$objDate.HighPart
\$lngLow = \$objDate.LowPart
If \$lngLow < 0 \$lngHigh=\$lngHigh+1 EndIf
If \$lngHigh = 0 And \$lngLow = 0 \$lngBias=0 EndIf
\$Pow=2.0
For \$l = 1 to 31 \$Pow=2.0*\$Pow Next
\$lngDate = ((CDBL(\$lngHigh)*\$Pow+\$lngLow)/600000000-\$lngBias)/1440
If \$lngDate > 0
\$jdate = 584389 + Fix(\$lngDate)
\$lngYear = (100*(((100*(\$jdate+306)-25)/3652425)-(((100*(\$jdate+306)-25)/3652425)/4))+
(100*(\$jdate+306)-25))/36525
\$lngMonth = (5*(((100*(\$jdate+306)-25)/3652425)-(((100*(\$jdate+306)-25)/3652425)/4)+
(\$jdate+306)-365*\$lngYear-\$lngYear/4)+456)/153
\$lngDay = (((100*(\$jdate+306)-25)/3652425)-(((100*(\$jdate+306)-25)/3652425)/4)+
(\$jdate+306)-365*\$lngYear-\$lngYear/4)-(153*\$lngMonth-457)/5
If \$lngMonth>12 \$lngYear=\$lngYear+1 \$lngMonth=\$lngMonth-12 EndIf
\$lngMonth = Right("0"+\$lngMonth,2)
\$lngDay = Right("0"+\$lngDay,2)

\$s = Fix(86400.0 * (\$lngDate-Fix(\$lngDate)))
\$m = \$s / 60
\$s = \$s mod 60
\$h = \$m / 60
\$m = \$m mod 60
\$fnInteger8Date=''+\$lngYear+'/'+\$lngMonth+'/'+\$lngDay+' '+\$h+':'+Right("0"+\$m,2)+':'+Right("0"+\$s,2)
EndIf
EndFunction
``````
0
Question by:jskfan

LVL 15

Assisted Solution

Giovanni Heward earned 1000 total points
ID: 39585440
This function enumerates keys within an array. :)
0

LVL 35

Accepted Solution

YZlat earned 1000 total points
ID: 39600503
If Not KeyExist(\$regsubkey)
Exit 87
EndIf

--if registry key passed to the function does not exist in the registry, then exit.

\$subkeycounter=0

-- set a counter to a starting value opf 0
-- and enter a loop and loop intill error occurs
Do

\$currentsubkey=EnumKey(\$regsubkey,\$subkeycounter)
-- EnumKey method enumerates the subkeys for a path

If Not @ERROR
-- if no error then declare an array and insert the enumerated subkey into that array
ReDIM Preserve \$subkeyarray[\$subkeycounter]
\$subkeyarray[\$subkeycounter]=\$currentsubkey

\$subkeycounter=\$subkeycounter+1
--increment the loop counter

EndIf

Until @ERROR

\$arrayenumkey=\$subkeyarray
Exit 0
0

Author Closing Comment

ID: 39619298
Thanks
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.