kixtart.kix
/*
** Logon Script
** Created by Steve Scotter / Spectrum Computer Solutions
** Dated 15-04-2012
*/
DEBUG OFF
SetConsole("Maximize")
IF @DATE = "2012/04/15"
include "\\domain.local\SysVol\domain.local\Policies\{FCD242C7-4602-4A1B-9484-F54A3D903D41}\User\Scripts\Logon\message.kix"
ENDIF
IF @DATE = "2012/04/16"
include "\\domain.local\SysVol\domain.local\Policies\{FCD242C7-4602-4A1B-9484-F54A3D903D41}\User\Scripts\Logon\message.kix"
ENDIF
include "\\domain.local\SysVol\domain.local\Policies\{FCD242C7-4602-4A1B-9484-F54A3D903D41}\User\Scripts\Logon\functions.kix"
$startTime = @Ticks
$welcome = "Weclome to @Domain, @Fullname (@WkSta)"
SetTitle($welcome)
cls
COLOR W+/n
? $welcome
/**************************************************
**
** Sync workstations times with PDC
**
**************************************************/
COLOR B+/n
?
? "Synchronising time with logon server."
SETTIME @LSERVER
/**************************************************
**
** Mapping network drivers
**
**************************************************/
COLOR Y+/n
?
? "Mapping drives"
? "--------------"
COLOR W+/n
IF REDIRECTOUTPUT(ExpandEnvironmentVars("%USERPROFILE%") + "\KIXTART.LOG", 0) = 0
? "DATE : " + @DATE + ", TIME : " + @TIME
? "Currently mapped network drivers"
USE LIST
REDIRECTOUTPUT("")
ELSE
? "Redirect Output to " + ExpandEnvironmentVars("%USERPROFILE%") + "\KIXTART.LOG failed"
ENDIF
? "Currently mapped network drivers"
USE LIST
? "Deleting all mapped network drivers"
USE * /DELETE
? "Reconnecting mapped network drivers"
map_drive("Z:", "\\SERVER\SHARENAME1")
IF INGROUP("SOME_GROUP")
map_drive("Y:", "\\SERVER\SHARENAME2")
ENDIF
/**************************************************
**
** Removing old printers and reconnecting new ones.
**
**************************************************/
COLOR Y+/n
?
? "Disabling 'Automatically search for Network Folders and Printers'"
? "-----------------------------------------------------------------"
COLOR W+/n
$=WRITEVALUE("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "NoNetCrawling", 1, REG_DWORD)
IF @ERROR = 0
COLOR G+/n
? "'Automatically search for Network Folders and Printers' disabled"
ELSE
COLOR R+/n
? "'Automatically search for Network Folders and Printers' NOT disabled"
ENDIF
COLOR Y+/n
?
? "Removing printers connected to SERVER1"
? "--------------------------------------"
COLOR W+/n
DelPrinterConnections("SERVER1")
IF @PRODUCTTYPE = "Windows XP Professional"
COLOR Y+/n
?
? "Adding printers"
? "---------------"
COLOR W+/n
?
? "Because this machine is Windows XP we have to connect the printers "
? "by logon script instead of Group Policy."
?
? "The fist time this script runs it will take a long time to complete."
? "DO NOT close this window! Minimize it if you feel the need."
COLOR W+/n
$printerList = "\\SERVER\PRT1", "\\SERVER\PRT2", "\\SERVER\PRT3"
For $i = 0 to UBound($printerList)
COLOR W+/n
? "Connecting to " + $printerList[$i] + "..."
IF ADDPRINTERCONNECTION ($printerList[$i]) = 0
COLOR G+/n
? "Connection to " + $printerList[$i] + " was successful"
ELSE
COLOR R+/n
? "Connection to " + $printerList[$i] + " was unsuccessful"
ENDIF
Next
ENDIF
/**************************************************
**
** Put some shortcuts on Desktop.
**
**************************************************/
IF INGROUP("DOMAIN ADMINS")
? "You're in DOMAIN ADMINS, adding shortcuts to desktop"
$=wshShortCut("SpaceMonger","\\server\SUPPORT\PUBLIC\Software\SpaceMonger.exe")
$=wshShortCut("SUPPORT FILES","\\server\SUPPORT")
ENDIF
/**************************************************
**
** Finished. Calculate time taken.
**
**************************************************/
:FINISH
$endTime = @Ticks
$totalTime1 = ($endTime - $startTime) / 1000
$totalTime2 = ($endTime - $startTime) mod 1000
COLOR G+/n
? "Login complete : $totalTime1.$totalTime2 seconds"
Sleep 10
function.kix
/*
** functions.kix
** Created by Steve Scotter / Spectrum Computer Solutions
** Dated 15-04-2012
** Updated 30-09-2012
*/
;FUNCTION ODBCSQL()
;
;ACTION Creates an ODBC Connection on the Client Desktop to a SQL Server Database
;
;AUTHOR Kent Dyer leptonator@hotmail.com
;
;CONTRIBUTORS
;Dixan Martinez
;Ref. - Create a DSN to access a SQL Server database with ODBC
;http://cwashington.netreach.net/depo/view.asp?Index=388&ScriptType=vbscript
;
;VERSION 1.4 - Corrected local connection syntax
; 1.3 - REMOVED UNEEDED code, Added option to create User DSN
; 1.2 Added in DIM Statement
; 1.1
; Renamed to be ODBCSQL
;
;DATE CREATED 14-APRIL-2003
;
;DATE REVISED 7-JULY-2005
;
;KIXTART Minimum required Kixtart version 4.02
;
;SYNTAX ODBCSQL($NAME,$SERVER,$DB,optional $user)
;
;PARAMETERS $NAME
; Name to be listed in the ODBC Connections in the Control Panel
;
; $SERVER
; Server you need to connect to
;
; $DB
; Database on $Server
;
; $USER
; Specified USER DSN
;
;RETURNS Nothing
;
;REMARKS User would need to be a Power User or better to run this Function.
; When creating a User DSN, should be able to run as a user of the machine.
;
;DEPENDENCIES SQL Server, KiXtart 4.02 +, rights for machine-wide connections
;
;EXAMPLE
; -- Create a system-wide ODBC conection
; ODBCSQL('ODBC DATABASE NAME','SERVER','DATABASE')
;
; -- Create local (not machine-wide) ODBC connection
;IF NOT KEYEXIST('HKCU\SOFTWARE\ODBC\ODBC.INI\YOUR ODBC')
; ODBCSQL('YOUR ODBC','SERVER','DATABASE',1)
;ENDIF
;
;KIXTART BBS http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB12&Number=83212
FUNCTION ODBCSQL($NAME,$SERVER,$DB,optional $user)
DIM $reg,$Title,$Driver,$RegEd,$RegEdPath,$RC
IF NOT $user
$reg='HKLM' ; System DSN
ELSE
$reg='HKCU' ; User DSN
ENDIF
$Title='SQL Server'
$Driver=READVALUE('HKLM\SOFTWARE\ODBC\ODBCINST.INI\'+$Title,'Driver')
$RegEd=$reg+'\SOFTWARE\ODBC\ODBC.INI'
$RegEdPath=$RegEd+'\'+$Name
IF NOT KEYEXIST($RegEdPath)
$RC=ADDKEY($RegEdPath)
$RC=WRITEVALUE($RegEdPath,'Database',$DB,'REG_SZ')
$RC=WRITEVALUE($RegEdPath,'Driver',$Driver,'REG_SZ')
$RC=WRITEVALUE($RegEdPath,'LastUser',@USERID,'REG_SZ')
$RC=WRITEVALUE($RegEdPath,'Server',$Server,'REG_SZ')
$RC=WRITEVALUE($RegEdPath,'Trusted_Connection','Yes','REG_SZ')
$RC=WRITEVALUE($RegEd+'\ODBC Data Sources',$Name,$Title,'REG_SZ')
ENDIF
ENDFUNCTION
; wshShortCut(),
;
;Authors and Contributors:
; Shawn, Radimus, Al_Po,
; Richard Farthing, NTDOC
;
;Version:
; 1.3.5
;
;Action:
; Creates Shortcuts for files or Web pages
;
;Syntax:
; wshShortCut($shortcutname,$targetpath,optional $arguments, optional $startdir, optional $iconpath, optional $style, optional $Description)
;
;Parameters:
; SHORTCUTNAME Required. Name of Shortcut. If path is omitted, will be saved to desktop.
; TARGETPATH Required. The path the target point to. To ommit checking if path exists in the function, append the target path
; with ",1"
; ARGUMENTS Optional. Arguments appended to TARGETPATH
; STARTDIR Optional. Working Directory
; ICONPATH Optional. Path to Icon Library. To specify an icon other than the first, separate the icon path with
; ",#" where # represents the icon in the library.
; STYLE Optional. 1 = default, 3 = maximized window, 7 = minimized window
; DESCRIPTION Optional. Description or Comment about Shortcut
; HOTKEY Optional. Keyboard Hotkey. (Note: Shortcut must be saved to desktop or startmenu for Hotkey to function)
;
;Remarks:
; wshShortCut 1.3.5
; - Reworked Code to allow commas in the the targetpath from changes in made in version 1.3.3
; wshShortCut 1.3.4
; - Dimmed undimmed var
; wshShortCut 1.3.3
; - Added option to bypass TARGETPATH exist check on LNK shortcuts. Add ,1 to the end of your Targetpath to bypass
; See Example below.
; wshShortCut 1.3.2
; - Included Option for HotKey(.hotkey)
; wshShortCut 1.3.1
; - Bug Fixes when creating URL shortcuts
; wshShortCut 1.3
; - Attempts to create directory structure to shortcut if it does not exist
; wshShortcut 1.2:
; - Support for NoVarsinStrings
; - Checks for existence of TargetPath in .lnk files
; - Included option for Description (.description)
; wshShortcut 1.1:
; - fixes a logic bug in wshShortCut 1.0 so you can use more than icons 0-9 in a icon library on URLS.
; - Unless path is explicity stated in $ShortCutName, icons are created on the desktop
; - If .lnk or .url is omitted, UDF tries to determine the shortcut type, but defaults to .lnk if it can't figure it out.
; wshShortCut 1.0
; http://www.kixtart.org/ubbthreads/showfl...=true#Post81769
;
;Examples:
; $=wshShortcut("KiXtart Web Page","http://www.kixtart.org")
; $=wshShortcut("Notepad","%systemroot%\system32\notepad.exe")
; $=wshShortcut$=wshshortcut("Server1","\\Server1,1")
function wshShortCut($shortcutname,$targetpath,optional $arguments, optional $startdir, optional $iconpath, optional $style,optional $description,optional $hotkey)
dim $shell, $desktop, $shortcut, $index, $iconinfo, $iconindex,$scdir,$rc
$wshshortcut=1
$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 right($targetpath,2)=",1"
$targetpath=left($targetpath,-2)
else
if instr($shortcutname,".lnk") and not exist($targetpath)
exit 2
endif
endif
if instr($shortcutname,"\")=0
$Desktop = $shell.SpecialFolders("Desktop")
$shortcutname=$desktop + "\" + $shortcutname
else
$scdir=substr($shortcutname,1,instrrev($shortcutname,"\"))
if not exist($scdir)
md $scdir
if @error
exit @error
endif
endif
endif
$shortcut = $shell.createshortcut($shortcutname)
if $shortcut
$shortcut.targetpath = $targetpath
if $iconpath and instrrev($shortcutname,".lnk")
$shortcut.iconlocation = $iconpath
endif
if $arguments
$shortcut.arguments = $arguments
endif
if $startdir
$shortcut.workingdirectory = $startdir
endif
if $style
$shortcut.windowstyle = $style
endif
If $description and instrrev($shortcutname,".lnk")
$shortcut.description = $description
EndIf
if $hotkey
$shortcut.hotkey = $hotkey
endif
$shortcut.save
if @error
exit @error
endif
if instrrev($shortcutname,".url") and $iconpath
$index=instrrev($iconpath,",")
if $index=0
$iconindex=0
else
$iconindex=split($iconpath,",")[1]
$iconpath=split($iconpath,",")[0]
endif
$rc=writeprofilestring($shortcutname,"InternetShortcut","IconFile",$iconpath)
$rc=writeprofilestring($shortcutname,"InternetShortcut","IconIndex",$iconindex)
endif
$shortcut = 0
$wshshortcut=0
else
exit @error
endif
else
exit @error
endif
endfunction
;Function:
; PrinterList()
;
;Author:
; Allen Powell (Al_Po)
;
;Version:
; 1.3.1 (2006/05/10 fixed error detecting Print Servers sharing IP Printers)
;
;Revisions
; 1.3.0 (2005/10/21 added options to distinguish local or remote printers)
; 1.2.0 (2005/07/19 optimized code)
; 1.1.0 (2004/08/09 undimmed variable fix)
; 1.0.0 (2003/06/26 Original)
;
;Action:
; Creates an array/list of Printers, and optionally their ports installed, on a local or remote computer.&n bsp;
;
;Syntax:
; Printerlist(optional $remotepc,optional $displaymode)
;
;Parameters:
; $RemotePC: (Optional)
; Remote Computer. If omitted defaults to localpc.
; $DisplayMode (Optional)
; 0 - show all printers, don't display port info (Default)
; 1 - show all printers, display port info
; 2 - show local printers, don't display port info
; 3 - show local printers, display port info
; 4 - show remote printers, don't display port info
; 5 - show remote printers, display port info
;Returns:
; Array of Printers
;
;Dependencies:
; WMI
;
;Example:
;
;break on
;$RC=Setoption("WrapAtEOL","on")
;
;$array=printerlist()
;for each $printer in $array
; ? $printer
;next
;
;Source:
;
Function PrinterList(optional $remotepc , optional $displaymode )
dim $service ,$printer ,$printers ,$printerdesc [0 ],$counter ,$portname ,$printername
if $remotepc =""
$remotepc ="."
endif
$Service = GetObject ("winmgmts:\" + $remotepc + "\root\cimv2" )
if @error
exit @error
endif
$Printers =$service.execquery ('select * from Win32_Printer' )
for each $printer in $printers
redim preserve $printerdesc [$counter ]
if $displaymode & 1
$portname = "," + $printer.portname
endif
select
case $displaymode & 4 ;remote printers
if left ($printer.portname ,2 )="\" or left ($printer.name ,2 )=="\"
$printername =$printer.name
endif
case $displaymode & 2 ;local printers
if left ($printer.portname ,2 )<>"\" and left ($printer.name ,2 )<>"\"
$printername =$printer.name
endif
case 1 ; all printers
$printername =$printer.name
endselect
if $printername <>""
$printerdesc [$counter ]=$printername + $portname
$counter =$counter + 1
$printername =""
endif
next
$PrinterList =$printerdesc
Endfunction
Function DelPrinterConnections( $ServerName )
? "Removing network printers attached to " + $ServerName
dim $c,$bk,$conn,$printers,$deleted
$c=0
$printers=0
$deleted=0
$bk="HKEY_CURRENT_USER\Printers\Connections"
$conn=enumkey($bk,$c)
while @error=0
$printers=$printers+1
; IF conn CONTAINS $ServerName THEN DELETE THE RECORD AND DONT INCREMENT $C
$split = Split($conn,",")
$printerUNC = "\" + $split[2] + "" + $split[3]
IF INSTR ($conn, $ServerName) <> 0
? "DELETING " + $printerUNC
$conn=delkey($bk+""+$conn)
$deleted=$deleted+1
ELSE
$c=$c+1
? "Not deleting " + $printerUNC
ENDIF
$conn=enumkey($bk,$c)
loop
? "" + $printers + " network printers found, " + $deleted + " deleted"
EndFunction
Function map_drive($drive_letter, $unc)
COLOR W+/n
? "Mapping $drive_letter to $unc"
USE $drive_letter /del /persistent
USE $drive_letter "$unc"
If @ERROR == 0
COLOR G+/n
? " Connection succesful"
Else
print_error(@Error, @SError)
EndIf
EndFunction
Function print_error($errorno, $errorstr)
COLOR R+/n
? " Error $errorno - $errorstr"
EndFunction
Function connect_printer($unc)
COLOR W+/n
? "Connecting to $unc"
If ADDPRINTERCONNECTION ($unc) = 0
COLOR G+/n
? " Connection to $unc succesful."
Else
COLOR R+/n
? " Error connecting to printer $unc"
print_error(@Error, @SError)
Endif
EndFunction
Function defatult_printer($unc)
COLOR W+/n
? "Setting Windows default printer to $unc"
If SetDefaultPrinter ($unc) = 0
COLOR G+/n
? " Defaulting successful."
Else
COLOR R+/n
? " Error defaulting to $unc"
print_error(@Error, @SError)
Endif
EndFunction