Kixtart Delete Printer Problem


Recommended Posts

have a problem at a new site, the previous admin has written a kix script to delete the Microsoft Document Image Writer printer on one of the remote sites (it runs 100% cpu if any of the users are stupid enough to send anything to it)

the problem is, not only does the script delete the document writer, it deletes all the printers.. as far as i can tel lthe only bit of script that would do that is commented out.. any ideas?

;REDIRECTOUTPUT ("c:\logon.txt", 1)

; ############################################
; Exit login script if in Domain Admins group.
; ############################################

; If InGroup("Domain Admins")
;   Exit
; Endif

SetConsole("SHOW")

$sysdate = "@mdayno @month @year " + substr(@time, 1, 5)

CLS
Color b+/n
Box ( 0,  0,  2, 79, "SINGLE")

Color w/n
At ( 1,   2) "Leeds Co-operative Login Script - V1.1"
At ( 1, 78 - len($sysdate)) $sysdate

$row = 3
At ( 3, 0) 

$row = $row + 1
At ($row,  2) "Logged in as " + ucase(@userid) + " (@fullname)"

; ############################################################
; Create IT support folder and copy files from NETLOGON share.
; Could be replaced with MSI file.
; ############################################################

$row = $row + 2
At ($row,  2) "Set-up IT support folder "

$file = "%SystemDrive%\support\printers.ini"
If Exist($file) = 0
  Copy "%LOGONSERVER%\NETLOGON\support\printers.ini" $file
Endif

$file = "%SystemDrive%\support\Bginfo.exe"
If Exist($file) = 0
  Copy "%LOGONSERVER%\NETLOGON\support\Bginfo.exe" $file
Endif

$file = "%SystemDrive%\support\leeds.bgi"
If Exist($file) = 0
  Copy "%LOGONSERVER%\NETLOGON\support\leeds.bgi" $file
Endif

; ###################################################
; Look inside Active Directory and find the users OU.
; ###################################################

$adSys = CreateObject("ADSystemInfo")

$row = $row + 2
At ($row,  2) $adSys.UserName

$len = Len($adSys.UserName)
$delim = InStr($adSys.UserName, ",")
$ou = Right($adSys.UserName,$len-$delim)
$len = Len($ou)
$delim = InStr($ou, "DC=Leeds,DC=Co-op")
$ou = Left($ou, $delim-2)

$row = $row + 2
At ($row,  2) "Users OU " + $ou + " "

$oub = Split($ou, ",")[1]

; #################################
; Only run specific code for an OU. 
; Travel OU adds tcp/ip ports and local printers.
; Telesales OU is empty but has very similar requirements to Travel OU.
; Benyon House OU adds network printers and maps drives.
; ######################################################

Select
  Case $oub = "OU=Telesales"
	$row = $row + 2
	At ($row,  2) "Telesales OU "

  Case $oub = "OU=Travel"
	$row = $row + 2
	At ($row,  2) "Travel OU "

; #########################################################################
; Commented out as their maybe other local printers that wont get re added.
; #########################################################################

;	$row = $row + 2
;	At ($row,  2) "Delete existing printers "
;	$subkey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\"
;	$index = 0
;	:Loop1
;	$keyname = EnumKey($subkey, $index)
;	If @error = 0
;	  $printer = $subkey + $keyname
;	  DelTree($printer)
;	  Goto Loop1
;	Endif

	$file = "%SystemDrive%\support\printers.ini"

; ##########################################################################################
; Opens printers.ini file to find matching OU and create an array of IP addresses at branch.
; ##########################################################################################

	For Each $ip In Split(ReadProfileString($file, $ou, ""), Chr(10))
	  $printer = ReadProfileString($file, $ou, $ip)

	  If $ip <> ""
		$row = $row + 2
		At ($row,  2) "Adding TCP/IP Printer Port: IP_" + $ip + " "
		$key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_" + $ip
		AddKey ($key)
		WriteValue($key, "HostName", "","REG_SZ")
		WriteValue($key, "HWAddress", "","REG_SZ")
		WriteValue($key, "IPAddress", $ip, "REG_SZ")
		WriteValue($key, "PortNumber", "9100","REG_DWORD")
		WriteValue($key, "Protocol", "1","REG_DWORD")
		WriteValue($key, "SNMP Community", "public","REG_SZ")
		WriteValue($key, "SNMP Enabled", "1","REG_DWORD")
		WriteValue($key, "SNMP Index", "1","REG_DWORD")
		WriteValue($key, "Version", "1","REG_DWORD")
	  Endif
	Next

; #########################################################################################
; Have to stop and start print spooler so that new ports will be seen when adding printers.
; #########################################################################################

	Shell "net stop spooler"
	Sleep 5
	Shell "net start spooler"

	For Each $ip In Split(ReadProfileString($file, $ou, ""), Chr(10))
	  $printer = ReadProfileString($file, $ou, $ip)
	  If $ip <> ""
		$row = $row + 2
		At ($row,  2) "Adding Printer : " + $printer
		$port = "IP_" + $ip
		Shell 'rundll32 printui.dll,PrintUIEntry /if /b "$printer" /f "%windir%\inf\ntprint.inf" /q /r "$port" /m "HP LaserJet 2100" /z /u'
	  Endif
	Next

	$row = $row + 2
	At ($row,  2) "Set-up default printer "
	$ip = Split(ReadProfileString($file, $ou, ""), Chr(10))[0]
	$printer = ReadProfileString($file, $ou, $ip)
	SetDefaultPrinter ($printer)

  Case $oub = "OU=Benyon House"
	$row = $row + 2
	At ($row,  2) "Benyon House OU "

	$row = $row + 2
	At ($row,  2) "Mounting drive letters "

; ########################################################################
; Mount drive letters based upon a combination of security groups and OUs.
; ########################################################################

	If InGroup("ManagementExec")
	Endif

	If InGroup("Management Accounts")
	  USE Q: "\\enterprise\Maninfo "
	Endif

	If InGroup("Payroll")
	 ;USE : "\\enterprise\Contracts"
	Endif

	If InGroup("Membership")
	 ;USE : "\\enterprise\Membership"
	Endif

	If $ou = "OU=Executive,OU=Benyon House"
	  USE E: "\\enterprise\Personnel_Exec"
	  USE X: "\\enterprise\Executive"
	Endif

	If $ou = "OU=Finance,OU=Benyon House"
	  USE M: "\\enterprise\Accounts"
	  USE S: "\\Ds9\Intech"
	Endif

	If $ou = "OU=Food Admin,OU=Benyon House"
	Endif

	If $ou = "OU=Marketing,OU=Benyon House"
	Endif

	If $ou = "OU=Personnel,OU=Benyon House"
	  USE O: "\\enterprise\Grampian"
	  USE P: "\\enterprise\dlc"
	  USE T: "\\enterprise\Personnel"
	Endif

	If $ou = "OU=Property,OU=Benyon House"
	  USE P: "\\enterprise\Property"

	Endif

	If $ou = "OU=Travel Admin,OU=Benyon House"
	  USE M: "\\enterprise\Accounts"
	  USE T: "\\enterprise\Travel"
	Endif

;	$row = $row + 2
;	At ($row,  2) "Delete network existing printers "
;	$subkey = "HKEY_CURRENT_USER\Printers\Connections\"
;	$index = 0
;	:Loop1
;	$keyname = EnumKey($subkey, $index)
;	If @error = 0
;	  $printer = $subkey + $keyname
;	  DelTree($printer)
;	  Goto Loop1
;	Endif

; ##############################################################################
; Will add a network printer and install any drivers required from print server.
; ##############################################################################

	$row = $row + 2
	At ($row,  2) "Add network printers "
	AddPrinterConnection("\\Voyager\CanonGP")
	AddPrinterConnection("\\Voyager\DellLase.2")
	AddPrinterConnection("\\Voyager\EpsonFX")
	AddPrinterConnection("\\Voyager\exec1700")

	AddPrinterConnection("\\Voyager\Exec5100PS")
	AddPrinterConnection("\\Voyager\HP_CLJ")
	AddPrinterConnection("\\Voyager\HP2564B")
	AddPrinterConnection("\\Voyager\IT5100")
	AddPrinterConnection("\\Voyager\Nash colour")
	AddPrinterConnection("\\Voyager\Nash-DOWN")
	AddPrinterConnection("\\Voyager\Nash-UP")
	AddPrinterConnection("\\Voyager\SYS$PRIN")

	If @UserId = "AHarrison" Or @UserId = "AMorley" Or @UserId = "DWheeler"
	  AddPrinterConnection("\\Voyager\Exec5100")
	Endif

	$row = $row + 2
	At ($row,  2) "Set default printer "

	If $ou = "OU=Executive,OU=Benyon House"
	Endif

	If $ou = "OU=Finance,OU=Benyon House"
	Endif

	If $ou = "OU=Food Admin,OU=Benyon House"
	Endif

	If $ou = "OU=Marketing,OU=Benyon House"
	Endif

	If $ou = "OU=Personnel,OU=Benyon House"
	Endif

	If $ou = "OU=Property,OU=Benyon House"
	Endif

	If $ou = "OU=Travel Admin,OU=Benyon House"
	Endif

  Case 1

EndSelect

; ###############################
; This code will run for all OUs.
; ###############################

$row = $row + 2
At ($row,  2) "Remove Microsoft Office Document Image Writer printer "
Shell 'rundll32 printui.dll,PrintUIEntry /dl /n "Microsoft Office Document Image Writer" /q'

; ####################################################################################
; Note the proxy server and Windows Update feature CNAME aliases for server locations.
; ####################################################################################

$row = $row + 2
At ($row,  2) "Set-up proxy server "
$key = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
;WriteValue($key, "ProxyServer", "www-cache.Leeds.Co-op:8080", "REG_SZ")
WriteValue($key, "ProxyServer", "********:8080", "REG_SZ")
WriteValue($key, "ProxyOverride", ";<local>", "REG_SZ")
WriteValue($key, "ProxyEnable", "01000000", "REG_BINARY")

; #########################################################################
; Do not think the Windows Update registry code will work for normal users.
; #########################################################################

;$row = $row + 2
;At ($row,  2) "Set-up Windows Update "
;$key = "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
;WriteValue($key, "WUServer", "http://windows-update.Leeds.Co-op", REG_SZ")
;WriteValue($key, "WUStatusServer", "http://windows-update.Leeds.Co-op", REG_SZ")
;$key = "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU"
;WriteValue($key, "NoAutoUpdate", "00000000", REG_DWORD")
;WriteValue($key, "AUOptions", "00000004", REG_DWORD")
;WriteValue($key, "ScheduledInstallDay", "00000000", REG_DWORD")
;WriteValue($key, "ScheduledInstallTime", "0000000a", REG_DWORD")
;WriteValue($key, "UseWUServer", "00000001", REG_DWORD")
;WriteValue($key, "NoAutoRebootWithLoggedOnUsers", "00000001", REG_DWORD")
;WriteValue($key, "DetectionFrequencyEnabled", "00000001", REG_DWORD")
;WriteValue($key, "DetectionFrequency", "00000016", REG_DWORD")
;WriteValue($key, "AutoInstallMinorUpdates", "00000001", REG_DWORD")

; ######################################################
; Only create MAPI profile if Outlook 2003 is installed.
; ######################################################

If Exist("%SystemDrive%\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE") = 1
  $file = "%USERPROFILE%\Application Data\Microsoft\Outlook\EXCHANGE.PRF"
  If Exist($file) = 0
	$row = $row + 2
	At ($row,  2) "Create Outlook 2003 MAPI profile "
	Md "%USERPROFILE%\Application Data\Microsoft\Outlook"
	Copy "%LOGONSERVER%\NETLOGON\Outlook\EXCHANGE.PRF" $file
	$key = "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Setup"
	DelValue($key, "First-Run")
	WriteValue($key, "ImportPRF", $file, "REG_SZ")
	Copy "%LOGONSERVER%\NETLOGON\support\Microsoft Office Outlook 2003.lnk" "%USERPROFILE%\Desktop"
  Endif
Endif

; #################################################
; Policy settings can only be set via Group Policy.
; #################################################

;$row = $row + 2
;At ($row,  2) "Set-up desktop "
;$key = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
;WriteValue($key, "NoWelcomeScreen", "1", "REG_DWORD")

$row = $row + 2
At ($row,  2) "Start bginfo.exe "
Run "%SystemDrive%\support\bginfo.exe /timer0 %SystemDrive%\support\leeds.bgi"

; ######################################################################
; Check the version of KIX32.EXE installed on PC and set-up error level.
; An error level of 1 will tell logon.cmd to copy the files.
; ######################################################################

$row = $row + 2
At ($row,  2) "Check KiXtart version "
$file = "%SystemDrive%\support\KIX32.EXE"
If Exist ($file)
  $a = GetFileVersion("%LOGONSERVER%\NETLOGON\support\KIX32.EXE", "FileVersion")
  $b = GetFileVersion($file, "FileVersion")
  If $b <> $a
	$updatekix = 1
  Endif
Endif

$row = $row + 2
At ($row,  2) "Script processing complete "
Sleep 5

If $updatekix = 1
  Exit (1)
Else
  Exit
Endif

Link to comment
https://www.neowin.net/forum/topic/404892-kixtart-delete-printer-problem/
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.