IF setconsole("hide")
ENDIF
;
; NT/95 logging - Kixtart 3.62
;
; (c) scripting@wanadoo.nl - 2000
;
; vs 1.00 - program (printers)
;
; 1.00 (20001010) original version
;
$prgrm_version="1.00"
;
; --------------------------------------------------------------------------
; - Site Specific Codes
; -
; - 1. "$file" log printer information to specified file. it is the prefix value.
; - extension are:
; - - .lst (= historical list with a total list of all configured printers)
; - - .usr (= dynamic list by username)
; - - .def (= dynamic list by printer & username)
; - _debug.txt (= debug information)
; - advise: use a hidden directory on server with read + write access.; - 2. "$debug_mode". usefull for kixtar programmers.
; - 3. "$debug_file". log printers debug information to specified file.
; --------------------------------------------------------------------------
;
$file="c:\printers"
;
$debug_mode="no" ; - no/yes - for additional information about checking registry keys -
$debug_file=$file+"_debug.txt"
;
; --------------------------------------------------------------------------
;
$cr=CHR(10)
$lf=CHR(13)
$eol=$cr
;
IF (@inwin = 1)
$NT_mode="yes"
ELSE
$NT_mode="no"
ENDIF
IF (len(@ipaddress0) = 0)
$offline_mode="yes"
ELSE
$offline_mode="no"
ENDIF
;
break off
flushkb
;
IF ($debug_mode = "yes")
IF (RedirectOutput("c:\printers_debug.txt",1) = 0)
ENDIF
ENDIF
; --------------------------------------------------------------------------
; - -
; --------------------------------------------------------------------------
:script_collect_pc_info
$x="" ; - it will contains all kind of information about workstation and server -
; - f.e. 00127_000505_23:23:23 DOMAIN=(NT - vs 1.01 L DOMAIN \\SPLxxxxx) 171.077.077.100 00A02ABABEEE mca SPLzzzzz ('MCA')
$domain=""
$ldomain=""
IF ($NT_mode = "yes")
$ikey="HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Winlogon"
IF (ExistKey($ikey) = 0)
$domain=ReadValue($ikey, "DefaultDomainName")
ENDIF
$ikey="HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Winlogon"
IF (ExistKey($ikey) = 0)
$ldomain=ReadValue($ikey, "CachePrimaryDomain")
ENDIF
ELSE
$ikey="HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\MSNP2\NetworkProvider"
IF (ExistKey($ikey) = 0)
$domain=ReadValue($ikey, "AuthenticatingAgent")
ENDIF
$ikey="HKEY_LOCAL_MACHINE\Security\Provider"
IF (ExistKey($ikey) = 0)
$ldomain=ReadValue($ikey, "Container")
ENDIF
ENDIF
IF (len($domain) = 0)
IF (len(@ldomain) <> 0)
$domain=@ldomain
ELSE
$domain=@domain
ENDIF
IF (len($domain) = 0)
$domain="~domain" ; - unknown @domain/@ldomain value -
ENDIF
ENDIF
IF (len($ldomain) = 0)
$ldomain=$domain
ENDIF
;
IF ($NT_mode = "yes")
$time_start=@time
$log_info="Kixtart-VIC "+$prgrm_version+" script started"
$log_info=$log_info+" for '"+LCASE(@userid)+"'"
$log_info=$log_info+" ("+$time_start+" - '"+@ipaddress0+"')"
IF logevent(0, 1, $log_info, "", "Kixtart PRT @kix")
ENDIF
ENDIF
; --------------------------------------------------------------------------
; - special variables settings -
; --------------------------------------------------------------------------
$section=substr(@date,3,2)
IF (@ydayno < 10)
$section=$section+"00"+@ydayno
ELSE
IF (@ydayno < 100)
$section=$section+"0"+@ydayno
ELSE
$section=$section+@ydayno
ENDIF
ENDIF
$key=$section+"_"
$key=$key+substr(@date,3,2)+substr(@date,6,2)+substr(@date,9,2)
$key=$key+"_"
$key=$key+@time
$key=$key+" "+$domain
; - calculation of LSERVER variable -
IF (len(@ipaddress0) = 0)
$offline_mode="yes"
IF ($NT_mode = "yes")
$x=$x+"(NT - vs "+$prgrm_version+" - off-line )"
ELSE
$x=$x+"(95 - vs "+$prgrm_version+" - off-line )"
ENDIF
ELSE
$offline_mode="no"
IF (len(@lserver) = 0)
$lserver="~lserver "
ELSE
$lserver=@lserver ; - \\spln99999 -
ENDIF
IF (LCASE($domain) = LCASE($ldomain))
IF ($NT_mode = "yes")
$x=$x+"(NT - vs "+$prgrm_version+" L $domain $lserver)"
ELSE
$x=$x+"(95 - vs "+$prgrm_version+" L $domain $lserver)"
ENDIF
ELSE
IF ($NT_mode = "yes")
$x=$x+"(NT - vs "+$prgrm_version+" - $domain $lserver)"
ELSE
$x=$x+"(95 - vs "+$prgrm_version+" - $domain $lserver)"
ENDIF
ENDIF
ENDIF
; - calculation of ip/mac-address value -
IF (len(@ipaddress0) = 15)
$i=1
$ip_old=@ipaddress0
$ip_new=""
DO
IF (substr($ip_old,$i,1) <> " ")
$ip_new=$ip_new+substr($ip_old,$i,1)
ELSE
$ip_new=$ip_new+"0"
ENDIF
$i=$i+1
UNTIL ($i > 15)
ELSE
$ip_new="xxx.xxx.xxx.xxx"
ENDIF
$x=$x+" "+$ip_new
;
IF (len(@address) = 0)
$address="xxxxxxxxxxxx"
ELSE
$address=@address
ENDIF
$x=$x+" "+$address
; - calculation of USER variable -
$user=""
IF ($NT_mode = "yes")
$ikey="HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon"
IF (ExistKey($ikey) = 0)
$user=ReadValue($ikey, "DefaultUserName")
ENDIF
ELSE
$ikey="HKEY_LOCAL_MACHINE\System\CurrentControlSet\control"
IF (ExistKey($ikey) = 0)
$user=ReadValue($ikey, "Current User")
ENDIF
ENDIF
IF (len($user) = 0)
$user=@userid
IF (len($user) = 0)
$user="~user"
ENDIF
ENDIF
$x=$x+" "+$user
; - calculation of WORKSTATION value -
IF (len(@wksta) = 0)
$x=$x+" ~wksta"
ELSE
$x=$x+" "+@wksta
ENDIF
IF (len(@fullname) = 0)
IF (len(@comment) = 0)
$x=$x+" ('~fullname')"
ELSE
$x=$x+" ('~fullname'+'"+@comment+"')"
ENDIF
ELSE
IF (len(@comment) = 0)
$x=$x+" ('@fullname')"
ELSE
$x=$x+" ('"+@fullname+"'+'"+@comment+"')"
ENDIF
ENDIF
$tmp=$x
IF ($debug_mode = "yes")
; cls
IF ($NT_mode = "yes")
IF (len(@ipaddress0) = 0)
? "Kixtar "+@kix+" - NT debug mode (vs "+$prgrm_version+")"+" "+@time+" (off-line)"
ELSE
? "Kixtar "+@kix+" - NT debug mode (vs "+$prgrm_version+")"+" "+@time+" (on-line)"
ENDIF
ELSE
IF (len(@ipaddress0) = 0)
? "Kixtar "+@kix+" - 95 debug mode (vs "+$prgrm_version+")"+" "+@time+" (off-line)"
ELSE
? "Kixtar "+@kix+" - 95 debug mode (vs "+$prgrm_version+")"+" "+@time+" (on-line)"
ENDIF
ENDIF
?
? "file "+$file+".???"
? "section "+$section
? "key "+$key
IF (len(@fullname) = 0)
? "user "+$user
ELSE
IF (len(@comment) = 0)
? "user "+$user+" ('"+@fullname+"')"
ELSE
? "user "+$user+" ('"+@fullname+"'+'"+@comment+"')"
ENDIF
ENDIF
?
? "workstation "+@wksta+" ("+LCASE(@lanroot)+") C="+GetDiskSpace("c:\")+" KBytes"
? "domain "+@domain
? "ldomain "+@ldomain
? " -> = "+$domain
? " "+$ldomain+" (L)"
? "ip_adress "+$ip_new+" "+$address
?
? "debug_mode "+$debug_mode
? "offline_mode "+$offline_mode
?
ENDIF
; --------------------------------------------------------------------------
; - -
; --------------------------------------------------------------------------
; - :script_printers1
$execute_mode="yes"
IF ($execute_mode = "yes")
$x=$tmp
$ikey="HKEY_CURRENT_USER\Printers\Connections"
IF (existkey($ikey) = 0)
$first=""
$x=$x+" HKCU.printers.connections=("
$index=0
DO
$icode=ENUMKEY($ikey, $index)
IF (len($icode) <> 0)
$x=$x+$first+"'"+substr($icode, 3, len($icode) - 2)+"'"
$first=","
ENDIF
$index=$index+1
UNTIL (len($icode) = 0)
$x=$x+")"
ENDIF
; ----- printers mapping (part 2) print.printers - NT/95 -----
$ikey="HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers"
IF (existkey($ikey) = 0)
$first=""
$x=$x+" HKLM.print.printers[local_printer]=("
$index=0
DO
$icode=ENUMKEY($ikey, $index)
IF (len($icode) <> 0)
$code="["
$code=$code+"'"+$icode+"'"
$code=$code+" name='" +ReadValue($ikey+"\"+$icode, "Name")+"'"
$code=$code+" share_name='" +ReadValue($ikey+"\"+$icode, "Share Name")+"'"
$code=$code+" port='" +ReadValue($ikey+"\"+$icode, "Port")+"'"
$code=$code+" printer_driver='" +ReadValue($ikey+"\"+$icode, "Printer Driver")+"'"
; $code=$code+" spool_directory='"+ReadValue($ikey+"\"+$icode, "Spool Directory")+"'"
$code=$code+" default_spool_directory='"+ReadValue($ikey, "DefaultSpoolDirectory")+"'"
$code=$code+"]"
$x=$x+$first+$code
$first=","
ENDIF
$index=$index+1
UNTIL (len($icode) = 0)
$x=$x+")"
ENDIF
; ----- printers mapping (part 3a) devices - NT -----
$ikey="HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices"
IF (existkey($ikey) = 0)
$first=""
$index=0
$x=$x+" HKCU.CurrentVersion.Devices[NT]=("
DO
$icode=ENUMVALUE($ikey, $index)
IF (len($icode) <> 0)
$x=$x+$first+"'"+$icode+"="+ReadValue($ikey, $icode)+"'"
$first=","
ENDIF
$index=$index+1
UNTIL (len($icode) = 0)
$x=$x+")"
ENDIF
; ----- printers mapping (part 3b-1) PrinterPorts - NT -----
$ikey="HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts"
IF (existkey($ikey) = 0)
$first=""
$index=0
$x=$x+" HKCU.CurrentVersion.PrinterPorts[NT]=("
DO
$icode=ENUMVALUE($ikey, $index)
IF (len($icode) <> 0)
$x=$x+$first+"'"+$icode+"="+ReadValue($ikey, $icode)+"'"
$first=","
ENDIF
$index=$index+1
UNTIL (len($icode) = 0)
$x=$x+")"
ENDIF
; ----- printers mapping (part 3b-2) Printers + PrnPortsMRU - 95 -----
$ikey="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Printers"
IF (existkey($ikey) = 0)
$first=""
$index=0
$x=$x+" HKCU.CurrentVersion.Printers[95]=("
DO
$icode=ENUMVALUE($ikey, $index)
IF (len($icode) <> 0)
$x=$x+$first+"'"+$icode+"'"
$first=","
ENDIF
$index=$index+1
UNTIL (len($icode) = 0)
$x=$x+")"
ENDIF
$ikey="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\PrnPortsMRU"
IF (existkey($ikey) = 0)
$first=""
$index=0
$x=$x+" HKCU.CurrentVersion.PrnPortsMRU[95]=("
DO
$icode=ENUMVALUE($ikey, $index)
IF (len($icode) <> 0)
$x=$x+$first+"'"+$icode+"="+ReadValue($ikey, $icode)+"'"
$first=","
ENDIF
$index=$index+1
UNTIL (len($icode) = 0)
$x=$x+")"
ENDIF
; ----- printer mapping information (part 4a) windows - NT -----
$ikey="HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows"
IF (existkey($ikey) = 0) ; - NT -
$default_printer=ReadValue($ikey, "device")
$default_port=""
IF (INSTR(LCASE($default_printer),",lpt") <> 0)
$default_port=UCASE(substr($default_printer,INSTR(LCASE($default_printer),",lpt")+1,5))
ENDIF
;
IF (len($default_printer) = 0)
$default_printer="NONE"
ENDIF
IF (len($default_port) = 0)
$default_port="NONE"
ENDIF
;
$x=$x+" HKCU.CurrentVersion.Windows[NT:default.printer]=("
IF (len($default_port) <> 0) AND ($default_port <> "NONE")
$x=$x+$default_port+" " ; - LPT type -
ENDIF
IF (len($default_printer) <> 0)
$x=$x+"'"+$default_printer+"'"
ENDIF
$x=$x+")"
ELSE
IF ($NT_mode = "yes")
$x=$x+" HKCU.CurrentVersion.Windows[NT:default.printer]=('NONE')"
ENDIF
ENDIF
; ----- printer mapping information (part 4b) windows - 95 -----
; $ikey="HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\IDConfigDB:CurrentConfig" -> "0001"
$ikey="HKEY_LOCAL_MACHINE\Config\0001\System\CurrentControlSet\Control\Print\Printers"
IF (existkey($ikey) = 0) ; - 95 -
$default_printer=ReadValue($ikey, "default")
$default_port=""
$ikey="HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers\"+$default_printer
IF (existkey($ikey) = 0)
$default_port=ReadValue($ikey, "Port")
ENDIF
;
IF (len($default_printer) = 0)
$default_printer="NONE"
ENDIF
IF (len($default_port) = 0)
$default_port="NONE"
ENDIF
;
$x=$x+" HKLM.print.printers[95:default.printer]=("
IF (len($default_port) <> 0)
$x=$x+$default_port+" "
ENDIF
IF (len($default_printer) <> 0)
$x=$x+"'"+$default_printer+"'"
ENDIF
$x=$x+")"
ELSE
IF ($NT_mode <> "yes")
$x=$x+" HKLM.print.printers[95:default.printer]=('NONE')"
ENDIF
ENDIF
$file1=$file+".lst"
IF ($debug_mode = "yes")
?
? " file = "+UCASE($file1)
? " key = "+$key
? " x = "+$x
?
ENDIF
IF (open(9, $file1, 5) = 0)
IF writeline(9, $key+"="+$x+$eol)
ENDIF
ENDIF
IF close(9)
ENDIF
ELSE
IF ($debug_mode = "yes")
?
? " -SKIP- = HKCU.printers.connections + HKLM.print.printers[local_printer] + HKCU.CurrentVersion.Devices[NT] + HKCU.CurrentVersion.PrinterPorts[NT] + HKCU.CurrentVersion.Windows:Device[default.printer]"
?
ENDIF
ENDIF
; --------------------------------------------------------------------------
; - -
; --------------------------------------------------------------------------
; - :script_printers2 ; - default printer - NT/95 -
; - $default_printer (previously calculated) -
; - $default_port (previously calculated) -
;
IF ($NT_mode = "yes")
IF (len($default_port) <> 0) AND (INSTR(LCASE($default_port),"lpt") = 0)
$default_port="" ; - LPT type -
ENDIF
ENDIF
;
$defprt=""
IF (len($default_port) <> 0)
IF (INSTR(LCASE($default_port),"lpt") = 0)
$defprt=$defprt+"'"+$default_port+"'"
ELSE
$defprt=$defprt+UCASE($default_port)
ENDIF
$defprt=$defprt+" "
ENDIF
IF (len($default_printer) <> 0)
$defprt=$defprt+"'"
IF (INSTR($default_printer,",") <> 0)
$defprt=$defprt+substr($default_printer,1,INSTR($default_printer,',')-1)
ELSE
$defprt=$defprt+$default_printer
ENDIF
$defprt=$defprt+"'"
ELSE
$defprt=$defprt+"'NONE'"
ENDIF
; ----- additional logfiles - (part 1: Printers.USR) - NT/95 (default printer) -----
; - $default_printer (previously calculated) -
; - $default_port (previously calculated) -
; - $defprt (previously calculated) -
;
$file_y=$file+".usr"
IF ($NT_mode = "yes")
$section_x=$domain+"_NT"
ELSE
$section_x=$domain+"_95"
ENDIF
$key_x=substr(LCASE($user) +" ",1,15)+" "
$key_x=$key_x+$section_x
$xxx=""
$xxx=$xxx+substr($key,1,22)
$xxx=$xxx+substr(LCASE(@wksta)+" ",1,15)+" "
$xxx=$xxx+substr($defprt+" ",1,55)+" "
$xxx=$xxx+$tmp
;
IF ($debug_mode = "yes")
?
? " file_y = "+$file_y
? " section_x = "+$section_x
? " key_x = "+$key_x
? " xxx = "+$xxx
? " default_prt = "+$default_printer
? " port "+$default_port
? " defprt = "+$defprt
?
ENDIF
IF writeprofilestring($file_y, $section_x, $key_x, $xxx)
ENDIF
; ----- additional logfiles - (part 2: Printers.DEF) - NT/95 (default printer) -----
; - $default_printer (previously calculated) -
; - $default_port (previously calculated) -
;
$file_y=$file+".def"
IF ($NT_mode = "yes")
$section_x=$domain+"_NT"
ELSE
$section_x=$domain+"_95"
ENDIF
$key_x=substr($defprt+" ",1,55)+" "
$key_x=$key_x+substr(LCASE($user) +" ",1,15)+" "
$key_x=$key_x+$section_x
$xxx=""
$xxx=$xxx+substr($key,1,22)
$xxx=$xxx+substr(LCASE(@wksta)+" ",1,15)+" "
$xxx=$xxx+$tmp
;
IF ($debug_mode = "yes")
?
? " file_y = "+$file_y
? " section_x = "+$section_x
? " key_x = "+$key_x
? " xxx = "+$xxx
? " default_prt = "+$default_printer
? " port "+$default_port
? " defprt = "+$defprt
?
ENDIF
IF writeprofilestring($file_y, $section_x, $key_x, $xxx)
ENDIF
; --------------------------------------------------------------------------
; - -
; --------------------------------------------------------------------------
IF (RedirectOutput("con",1) = 0)
ENDIF
;
IF ($debug_mode = "yes")
IF ($NT_mode = "yes")
? "Kixtar "+@kix+" - NT debug mode (vs "+$prgrm_version+")"+" "+@time
ELSE
? "Kixtar "+@kix+" - 95 debug mode (vs "+$prgrm_version+")"+" "+@time
ENDIF
?
? " def.printer = "+$default_printer
? " port = "+$default_port
? " defprt = "+$defprt
?
ENDIF
:end_script
IF ($NT_mode = "yes")
$time_stop=@time
$log_info="Kixtart-VIC "+$prgrm_version+" script completed successfully"
$log_info=$log_info+" for '"+LCASE($user)+"' "+UCASE($domain)
$log_info=$log_info+" ("+$time_start+" - "+$time_stop+" - '"+$ip_new+"')"
IF (len(@fullname) > 0)
$log_info=$log_info+" '"+LCASE(@fullname)+"'"
ENDIF
$log_info=$log_info+" '"+LCASE($default_printer)+"'"
$log_info=$log_info+" '"+LCASE($default_port)+"'"
$log_info=$log_info+" '"+LCASE($defprt)+"'"
IF logevent(0, 1, $log_info, "", "Kixtart PRT @kix"+"c")
ENDIF
ENDIF
;
break on
flushkb
beep