backfight
(Getting the hang of it)
2010-11-03 11:40 AM
Does my script runs under Windows 2k8 and 2k8 Active Directory?

Hello all,
does the following script run under Windows 2k8 R2 Stadard Server Platform with an 2k8 Active Directory?

The Domainclients are Windows XP only.

 Code:
Break off
SetConsole("Hide")

;****************************************************************************
;Loeschen der Temp Dateien (deaktiviert)
;
; run "\\...local\Policies\{81C8A747-9992-4E6D-9BD4-93A7DB5090CB}\User\Scripts\Logon\DelTemp\DelTemp.exe"
;
;****************************************************************************



;****************************************************************************
;Set Wallpaper
;****************************************************************************

$RC=WriteValue ('HKCU\Control Panel\Desktop', 'TitelWallpaper', '1', REG_SZ)
If @ERROR = 0
	? 'Value written to the registry'
Endif
$RC=WriteValue ('HKCU\Control Panel\Desktop', 'WallpaperStyle', '2', REG_SZ)
If @ERROR = 0
	? 'Value written to the registry'
Endif
If SetWallpaper ('\\....local\Policies\{81C8A747-9992-4E6D-9BD4-93A7DB5090CB}\User\Scripts\Logon\Hintergrundbild\BSL.bmp', 1) = 0
	? 'Set current wallpaper to BSL.bmp...'
Endif


;****************************************************************************
;Set Uservariablen
;****************************************************************************

SET "temp=C:\temp"
SET "tmp=C:\temp"
SETTIME "\\SVR"


;****************************************************************************
;Set User Ansicht auf Detail
;****************************************************************************

run "\\....local\Policies\{81C8A747-9992-4E6D-9BD4-93A7DB5090CB}\User\Scripts\Logon\Ansicht-Explorer-Details.exe"


;****************************************************************************
;Definieren der Server
;****************************************************************************

$fs01="\\SRV1"
$fs02="\\SRV2"
$fs03="\\SRV3"
$fs07="\\SRV4"
$fs08="\\SRV5"
$fs09="\\SRV6"
$fs10="\\SRV7"

;****************************************************************************
;Verbinden von Netzwerklaufwerken
;****************************************************************************

use "*" /delete


;****************************************************************************
;Verbinden von Netzwerklaufwerken für die EDV
;****************************************************************************

IF InGroup("EDVGruppe")
Use Z: $fs02+"\Test"
EndIf

;****************************************************************************
;Verbinden der Netzwerkdrucker für alle Abteilungen
;**************************************************************************** 

;Script Options
If NOT @LOGONMODE
	Break On
EndIf
Dim $RC
$RC=SetOption("Explicit", "On")
$RC=SetOption("NoMacrosInStrings", "On")
$RC=SetOption("NoVarsInStrings", "On")
$RC=SetOption("WrapAtEOL", "On")

;***********
;Printserver
;***********

Dim $ERPServer	$ERPServer="SRV5"



;****************************************************************************
;Netzwerkdrucker 
;****************************************************************************
Dim $EDV		$EDV="Brother_.6"







;****************************************************************************
;Verbinden der Netzwerkdrucker für die EDV
;****************************************************************************

If InGroup("EDVGruppe")
	$RC = AddPrinterConnection("\\"+$ERPServer+"\"+$EDV)
EndIf


;****************************************************************************
; Hardware Informationen von allen Domain PC´s auslesen 
;****************************************************************************
; Umleitung der Ausgaben auf eine Datei mit Rechnernamen im Dateinamen

break on
cls
dim $result

$result=setoption('explicit','on')
$result=setoption('novarsinstrings','on')
$result=setoption('nomacrosinstrings','on')

dim $verzeichnis, $datei, $dimm, $computer

$verzeichnis = '\\...\Anmeldungen\'
$datei = @Hostname+"_info.txt"

if not exist($verzeichnis)
  ? 'Kann Verzeichnis '+$verzeichnis+' nicht finden'
  exit 1
endif

$result=RedirectOutput ($verzeichnis+$datei ,1)
if @error
  ? 'Error '+@error+' - '+@serror
endif
? "Datum der Erfassung     = " + @date  

? "Monat                   = " + @MONTH

? "Tag                     = " + @DAY 

? "Uhrzeit                 = " + @time 

? "Letzter Login von       = " + @FULLNAME

? "User Privilegien        = " + @PRIV
 
? "PC Name		           = " + WMIQuery("CSName","Win32_OperatingSystem")[0]

? "IP Adresse              = " + @IPADDRESS0

? "MAC Adresse             = " + @ADDRESS

? "OS Name                 = " + WMIQuery("Caption","Win32_OperatingSystem")[0]

? "Service Pack            = " + WMIQuery("CSDVersion","Win32_OperatingSystem")[0]

? "Install Date            = " + WMIQuery("InstallDate","Win32_OperatingSystem")[0]

? "OS Version Number       = " + WMIQuery("Version","Win32_OperatingSystem")[0]

? "OS Build Number         = " + WMIQuery("BuildNumber","Win32_OperatingSystem")[0]

? "Sprache                 = " + @SysLang

? "Registered User         = " + WMIQuery("RegisteredUser","Win32_OperatingSystem")[0]

? "Boot Device             = " + WMIQuery("BootDevice","Win32_OperatingSystem")[0]

? "System Device           = " + WMIQuery("SystemDevice","Win32_OperatingSystem")[0]

? "Windows Directory       = " + WMIQuery("WindowsDirectory","Win32_OperatingSystem")[0]

? "System Directory        = " + WMIQuery("SystemDirectory","Win32_OperatingSystem")[0]

? "Last Boot Time          = " + WMIQuery("LastBootupTime","Win32_OperatingSystem")[0]

? "OS Serial Number        = " + WMIQuery("SerialNumber","Win32_OperatingSystem")[0]

? "System Manufacturer is  = " + WMIQuery("Manufacturer","Win32_ComputerSystem")[0]

? "System Model is         = " + WMIQuery("Model","Win32_ComputerSystem")[0]

? "System Serial Number is = " + WMIQuery("SerialNumber","Win32_BIOS")[0]

? "System BIOS Version is  = " + WMIQuery("SMBIOSBIOSVersion","Win32_BIOS")[0]

? "System BIOS Date is     = " + WMIQuery("Version","Win32_BIOS")[0]

? "CPU Modell              = " + @CPU

? "CPU Manufacturer:       = " + WMIQuery("manufacturer","Win32_Processor")[0]

? "Description:            = " + WMIQuery("description","Win32_Processor")[0]

? "CPU Speed is            = " + WMIQuery("CurrentClockSpeed","Win32_Processor")[0]+" Mhz"

? "Maximum Clock Speed     = " + WMIQuery("maxclockspeed","Win32_Processor")[0]+" Mhz"

? "L2 Cache Size:          = " + WMIQuery("l2cachesize","Win32_Processor")[0]

? "L2 Cache Speed:         = " + WMIQuery("l2cachespeed","Win32_Processor")[0]

? "Family:                 = " + WMIQuery("family","Win32_Processor")[0]

? "Level:                  = " + WMIQuery("level","Win32_Processor")[0]

? "Stepping:               = " + WMIQuery("stepping","Win32_Processor")[0]

? "Device ID:              = " + WMIQuery("deviceid","Win32_Processor")[0]

? "Unique ID:              = " + WMIQuery("uniqueid","Win32_Processor")[0]

? "System Memory           = " + cint(Val(WMIQuery("TotalPhysicalMemory","Win32_LogicalMemoryConfiguration")[0])/1024) + " MB"
For Each $dimm in WMIQuery("Capacity","Win32_PhysicalMemory")
    ? "Dimm Size               = " + cint(Val($dimm) / 1048576) + " MB"
Next

? "Disk Name/s             = " + join(WMIQuery("name","Win32_LogicalDisk"),', ')

? "Volume Name             = " + join(WMIQuery("volumename","Win32_LogicalDisk"),', ') + " MB"

? "Size                    = " + join(WMIQuery("size","Win32_LogicalDisk"),', ')+ " MB"

? "File System             = " + join(WMIQuery("filesystem","Win32_LogicalDisk"),', ')

? "Free Space              = " + join(WMIQuery("freespace","Win32_LogicalDisk"),', ')+" MB"

? "Video Card is           = " + WMIQuery("Description","Win32_VideoController")[0]

? "Video Res is            = " + WMIQuery("VideoModeDescription","Win32_VideoController")[0]

? "Modem is                = " + WMIQuery("Description","Win32_POTSModem")[0]


Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On') 
Dim $RegArray,$Value,$Product,$Key
$RegArray = SearchReg("HKLM\Software\Microsoft","DigitalProductID",2)
   If @Error
      Else 
         For Each $Value in $RegArray   
            If $Value     
               $Product = ReadValue(Join(Split($value,'<=>DigitalProductId'),''),'ProductName')
               If $Product       
                  $Key = Get_Product_Key(ReadValue(Join(Split($value,'<=>DigitalProductId'),''), 'DigitalProductID'))
                  ?  + $Product + ' = ' + $Key ?
               EndIf
            EndIf 
         Next
      EndIf  




$computer = @wksta
? WMIQuery2("Services on","Win32_Service",$computer)
? WMIQuery2("Processes on","Win32_Process",$computer)

$result=redirectoutput('')

exit 0

   Function SearchReg($Key,$Str,$SrcIn)
   Dim $Idx,$vName,$Value,$num,$SubKey,$fArr,$mbr
   $SearchReg = ''
   $num = 0
   $Idx = 0
   $vName = EnumValue($Key,$Idx)
   Do
      $mbr = ''   
      If $SrcIn & 1
         $Value = ReadValue($Key,$vName)
         If InStr($Value,$Str)
            $mbr = $Key + "<=>" + IIf($vName,$vName,'<Default>')
         EndIf
      EndIf
      If ($SrcIn & 2) And InStr($vName,$Str)
         $mbr = $Key + "<=>" + $vName
      EndIf
      If $mbr
         ReDim Preserve $SearchReg[$num]
         $SearchReg[$num] = $mbr
         $num = $num + 1
      EndIf
      $Idx = $Idx + 1
      $vName = EnumValue($Key,$Idx)
   Until @Error
   $Idx = 0
   $SubKey = EnumKey($Key,$Idx)
   While $SubKey
      If ($SrcIn & 4) And InStr($SubKey,$Str)
         ReDim Preserve $SearchReg[$num]
         $SearchReg[$num] = $Key + '\' + $SubKey + "<=><KeyName>"
         $num = $num + 1
      EndIf
      $fArr = SearchReg($Key + "\" + $SubKey,$Str,$SrcIn)
      If @Error = 0
         For Each $mbr in $fArr
            ReDim Preserve $SearchReg[$num]
            $SearchReg[$num] = $mbr
            $num = $num + 1
         Next
      EndIf
      $Idx = $Idx + 1
      $SubKey = EnumKey($Key,$Idx)
   Loop
   Exit VarType($SearchReg) = 8
EndFunction

Function Get_Product_Key($sProductID)
Dim $aiKeyChars[24],$bProductKey[15],$ilByte,$i,$sCDKey,$nCur
$aiKeyChars = Split('B,C,D,F,G,H,J,K,M,P,Q,R,T,V,W,X,Y,2,3,4,6,7,8,9',',')
For $i = 0 to 14
   $bProductKey[$i] = Val("&"+SubStr($sProductID,$i*2+105,2))
Next
$sCDKey = "" 
For $ilByte = 24 to 0 Step -1
   $nCur = 0
   For $i=14 to 0 Step -1
      $nCur = $nCur * 256 | $bProductKey[$i]
      $bProductKey[$i] = Int($nCur / 24)
      $nCur = $nCur Mod 24
   Next
   $sCDKey = $aiKeyChars[$nCur] + $sCDKey
   If $ilByte Mod 5 = 0 And $ilByte <> 0
      $sCDKey = "-" + $sCDKey
   EndIf
Next
$Get_Product_Key = $sCDKey
EndFunction

FUNCTION WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x, Optional $root)
Dim $sQuery, $objEnum, $sValue, $sItem, $TMP, $SystemSet, $, $objInstance
If Not $sComputer $sComputer="." EndIf
if instr($sComputer,'\') $sComputer=right($sComputer,instrrev($sComputer,'\')) Endif
if not $root $root="\root\cimv2" Endif
$sQuery = "Select " + $sWhat + " From "+ $sFrom
If $sWhere AND $x $sQuery = $sQuery+" Where "+$sWhere+" = '"+$x+"'" EndIf
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$sComputer+$root)
If @ERROR Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf
$objEnum = $SystemSet.ExecQuery($sQuery)
If @ERROR Exit VAL("&"+Right(DecToHex(@ERROR),4)) EndIf
   For Each $objInstance in $objEnum
      If $objInstance
         $=Execute("$"+"sValue = $"+"objInstance."+$sWhat)
         if VarType($sValue) & 8192
            For Each $sItem in $sValue $tmp=$tmp+'|'+Trim($sItem) Next
         else
            $tmp=$tmp+'|'+Trim($svalue)
            Endif
         EndIf
      Next
   $WMIQuery = split(substr($tmp,2),'|')
   Exit VAL("&"+Right(DecToHex(@ERROR),4))
ENDFUNCTION 

Function WMIQuery2($what,$where,$computer)
    dim $wmi, $list, $objs, $obj
    $wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!//" + $computer + "/root/cimv2")
    $list = "" $objs = $wmi.instancesof($where)
    For Each $obj in $objs
        $list = $list + $obj.description  + Chr(13) + Chr(10)
    Next
    $list=Left($list, Len($list))
    ? $what +" "+ $computer + Chr(13) + Chr(10) + $list
EndFunction




Mart
(KiX Supporter)
2010-11-03 12:02 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

I browsed through your script roughly and do not see any obvious reasons why it should not work on Win2K8 but there are some things that are a bit questionable in my opinion. There might be more but this is what I noticed at first sight.

1 - I would place all the SetOption lines at the top of my script and use them only once. Same for the If not @logonmode Break on part.
2 - Settime is unneeded in a properly configured AD environment.
3 - A personal opinion. Redirectoutput is not my favorite function to write data to a text file. I would use WriteLine but like said this is personal opinion.
4 - It would be wise to check if the path to the network drive is correct before mapping and if not delete it and recreate it. If it is ok leave it as it is. This can save some time if you have a lot of drive mapping.
5 - You set the wallpaper to an image stored on the server. I always prefer to copy it to a local drive and use a check and update routine to be sure everyone has the latest up to date wallpaper.
6 - the PC name, OS name and type, service pack level can be retrieved using the build in macros. No need for a WMI query to get this info.


backfight
(Getting the hang of it)
2010-11-04 09:18 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Hi Mart,
can you show me how the script looks like after your changes? I´m a little bit out of theme. Long time ago i wrote this script and only with help of this forum.

Greetz backfight


Mart
(KiX Supporter)
2010-11-04 10:22 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

See the script below for some of the changes. I did not make all changes I suggested but this should get you going. I would also DIM all variables at the top of the script. You have Explicit set to on so all vars must be DIMmed. If you DIM them at the top instead of when you need them you can easily move parts of the scrip up or down without getting any error about undeclared variables.

 Code:
If Not @LOGONMODE
	Break On
EndIf

SetConsole("Hide")
$RC=SetOption("Explicit", "On")
$RC=SetOption("NoMacrosInStrings", "On")
$RC=SetOption("NoVarsInStrings", "On")
$RC=SetOption("WrapAtEOL", "On")

;****************************************************************************
;Loeschen der Temp Dateien (deaktiviert)
;
; run "\\...local\Policies\{81C8A747-9992-4E6D-9BD4-93A7DB5090CB}\User\Scripts\Logon\DelTemp\DelTemp.exe"
;
;****************************************************************************
;****************************************************************************
;Set Wallpaper
;****************************************************************************
$RC=WriteValue ('HKCU\Control Panel\Desktop', 'TitelWallpaper', '1', REG_SZ)
If @ERROR = 0
	? 'Value written to the registry'
EndIf
$RC=WriteValue ('HKCU\Control Panel\Desktop', 'WallpaperStyle', '2', REG_SZ)
If @ERROR = 0
	? 'Value written to the registry'
EndIf
If SetWallpaper ('\\....local\Policies\{81C8A747-9992-4E6D-9BD4-93A7DB5090CB}\User\Scripts\Logon\Hintergrundbild\BSL.bmp', 1) = 0
	? 'Set current wallpaper to BSL.bmp...'
EndIf

;****************************************************************************
;Set Uservariablen
;****************************************************************************
Set "temp=C:\temp"
Set "tmp=C:\temp"

;****************************************************************************
;Set User Ansicht auf Detail
;****************************************************************************
Run "\\....local\Policies\{81C8A747-9992-4E6D-9BD4-93A7DB5090CB}\User\Scripts\Logon\Ansicht-Explorer-Details.exe"

;****************************************************************************
;Definieren der Server
;****************************************************************************
$fs01="\\SRV1"
$fs02="\\SRV2"
$fs03="\\SRV3"
$fs07="\\SRV4"
$fs08="\\SRV5"
$fs09="\\SRV6"
$fs10="\\SRV7"

;****************************************************************************
;Verbinden von Netzwerklaufwerken
;****************************************************************************
Use "*" /delete

;****************************************************************************
;Verbinden von Netzwerklaufwerken für die EDV
;****************************************************************************
If InGroup("EDVGruppe")
	Use Z: /delete /persistent
	Use Z: $fs02+"\Test"
EndIf

;****************************************************************************
;Verbinden der Netzwerkdrucker für alle Abteilungen
;**************************************************************************** 
;Script Options
Dim $RC

;***********
;Printserver
;***********
Dim $ERPServer
$ERPServer="SRV5"

;****************************************************************************
;Netzwerkdrucker 
;****************************************************************************
Dim $EDV
$EDV="Brother_.6"

;****************************************************************************
;Verbinden der Netzwerkdrucker für die EDV
;****************************************************************************
If InGroup("EDVGruppe")
	$rc = DelPrinterConnection("\\"+$ERPServer+"\"+$EDV)
	$RC = AddPrinterConnection("\\"+$ERPServer+"\"+$EDV)
EndIf

;****************************************************************************
; Hardware Informationen von allen Domain PC´s auslesen 
;****************************************************************************
; Umleitung der Ausgaben auf eine Datei mit Rechnernamen im Dateinamen
CLS
Dim $result
Dim $verzeichnis, $datei, $dimm, $computer

$verzeichnis = '\\...\Anmeldungen\'
$datei = @Hostname+"_info.txt"

If Not Exist($verzeichnis)
  ? 'Kann Verzeichnis '+$verzeichnis+' nicht finden'
  Exit 1
EndIf

$rc = Open(1,$verzeichnis+$datei, 5)

If @error
  ? 'Error '+@error+' - '+@serror
EndIf
$rc = WriteLine(1 "Datum der Erfassung     = " + @date + @CRLF)
$rc = WriteLine(1 "Monat                   = " + @MONTH + @CRLF)
$rc = WriteLine(1 "Tag                     = " + @DAY + @CRLF)
$rc = WriteLine(1 "Uhrzeit                 = " + @time + @CRLF)
$rc = WriteLine(1 "Letzter Login von       = " + @FULLNAME + @CRLF)
$rc = WriteLine(1 "User Privilegien        = " + @PRIV + @CRLF)
$rc = WriteLine(1 "PC Name		           = " + @WKSTA + @CRLF)
$rc = WriteLine(1 "IP Adresse              = " + @IPADDRESS0 + @CRLF)
$rc = WriteLine(1 "MAC Adresse             = " + @ADDRESS + @CRLF)
$rc = WriteLine(1 "OS Name                 = " + @PRODUCTTYPE + @CRLF)
$rc = WriteLine(1 "Service Pack            = " + @CSD + @CRLF)
$rc = WriteLine(1 "Install Date            = " + WMIQuery("InstallDate","Win32_OperatingSystem")[0] + @CRLF)
$rc = WriteLine(1 "OS Version Number       = " + WMIQuery("Version","Win32_OperatingSystem")[0] + @CRLF)
$rc = WriteLine(1 "OS Build Number         = " + WMIQuery("BuildNumber","Win32_OperatingSystem")[0] + @CRLF)
$rc = WriteLine(1 "Sprache                 = " + @SYSLANG + @CRLF)
$rc = WriteLine(1 "Registered User         = " + WMIQuery("RegisteredUser","Win32_OperatingSystem")[0] + @CRLF)
$rc = WriteLine(1 "Boot Device             = " + WMIQuery("BootDevice","Win32_OperatingSystem")[0] + @CRLF)
$rc = WriteLine(1 "System Device           = " + WMIQuery("SystemDevice","Win32_OperatingSystem")[0] + @CRLF)
$rc = WriteLine(1 "Windows Directory       = " + WMIQuery("WindowsDirectory","Win32_OperatingSystem")[0] + @CRLF)
$rc = WriteLine(1 "System Directory        = " + WMIQuery("SystemDirectory","Win32_OperatingSystem")[0] + @CRLF)
$rc = WriteLine(1 "Last Boot Time          = " + WMIQuery("LastBootupTime","Win32_OperatingSystem")[0] + @CRLF)
$rc = WriteLine(1 "OS Serial Number        = " + WMIQuery("SerialNumber","Win32_OperatingSystem")[0] + @CRLF)
$rc = WriteLine(1 "System Manufacturer is  = " + WMIQuery("Manufacturer","Win32_ComputerSystem")[0] + @CRLF)
$rc = WriteLine(1 "System Model is         = " + WMIQuery("Model","Win32_ComputerSystem")[0] + @CRLF)
$rc = WriteLine(1 "System Serial Number is = " + WMIQuery("SerialNumber","Win32_BIOS")[0] + @CRLF)
$rc = WriteLine(1 "System BIOS Version is  = " + WMIQuery("SMBIOSBIOSVersion","Win32_BIOS")[0] + @CRLF)
$rc = WriteLine(1 "System BIOS Date is     = " + WMIQuery("Version","Win32_BIOS")[0]
$rc = WriteLine(1 "CPU Modell              = " + @CPU + @CRLF)
$rc = WriteLine(1 "CPU Manufacturer:       = " + WMIQuery("manufacturer","Win32_Processor")[0] + @CRLF)
$rc = WriteLine(1 "Description:            = " + WMIQuery("description","Win32_Processor")[0] + @CRLF)
$rc = WriteLine(1 "CPU Speed is            = " + @MHZ + " Mhz" + @CRLF)
$rc = WriteLine(1 "Maximum Clock Speed     = " + WMIQuery("maxclockspeed","Win32_Processor")[0]+" Mhz" + @CRLF)
$rc = WriteLine(1 "L2 Cache Size:          = " + WMIQuery("l2cachesize","Win32_Processor")[0] + @CRLF)
$rc = WriteLine(1 "L2 Cache Speed:         = " + WMIQuery("l2cachespeed","Win32_Processor")[0] + @CRLF)
$rc = WriteLine(1 "Family:                 = " + WMIQuery("family","Win32_Processor")[0] + @CRLF)
$rc = WriteLine(1 "Level:                  = " + WMIQuery("level","Win32_Processor")[0] + @CRLF)
$rc = WriteLine(1 "Stepping:               = " + WMIQuery("stepping","Win32_Processor")[0] + @CRLF)
$rc = WriteLine(1 "Device ID:              = " + WMIQuery("deviceid","Win32_Processor")[0] + @CRLF)
$rc = WriteLine(1 "Unique ID:              = " + WMIQuery("uniqueid","Win32_Processor")[0] + @CRLF)
$rc = WriteLine(1 "System Memory           = " + CInt(Val(WMIQuery("TotalPhysicalMemory","Win32_LogicalMemoryConfiguration")[0])/1024) + " MB" + @CRLF)
For Each $dimm in WMIQuery("Capacity","Win32_PhysicalMemory")
    $rc = WriteLine(1 "Dimm Size               = " + CInt(Val($dimm) / 1048576) + " MB" + @CRLF)
Next
$rc = WriteLine(1 "Disk Name/s             = " + Join(WMIQuery("name","Win32_LogicalDisk"),', ') + @CRLF)
$rc = WriteLine(1 "Volume Name             = " + Join(WMIQuery("volumename","Win32_LogicalDisk"),', ') + " MB" + @CRLF)
$rc = WriteLine(1 "Size                    = " + Join(WMIQuery("size","Win32_LogicalDisk"),', ')+ " MB" + @CRLF)
$rc = WriteLine(1 "File System             = " + Join(WMIQuery("filesystem","Win32_LogicalDisk"),', ') + @CRLF)
$rc = WriteLine(1 "Free Space              = " + Join(WMIQuery("freespace","Win32_LogicalDisk"),', ')+" MB" + @CRLF)
$rc = WriteLine(1 "Video Card is           = " + WMIQuery("Description","Win32_VideoController")[0] + @CRLF)
$rc = WriteLine(1 "Video Res is            = " + WMIQuery("VideoModeDescription","Win32_VideoController")[0] + @CRLF)
$rc = WriteLine(1 "Modem is                = " + WMIQuery("Description","Win32_POTSModem")[0] + @CRLF)

$rc = Close(1)

Dim $SO
Dim $RegArray,$Value,$Product,$Key
$RegArray = SearchReg("HKLM\Software\Microsoft","DigitalProductID",2)
If Not @Error
	For Each $Value in $RegArray   
		If $Value     
			$Product = ReadValue(Join(Split($value,'<=>DigitalProductId'),''),'ProductName')
			If $Product       
				$Key = Get_Product_Key(ReadValue(Join(Split($value,'<=>DigitalProductId'),''), 'DigitalProductID'))
				? + $Product + ' = ' + $Key ?
			EndIf
		EndIf 
	Next
EndIf  

$computer = @WKSTA
? WMIQuery2("Services on","Win32_Service",$computer)
? WMIQuery2("Processes on","Win32_Process",$computer)

$result=RedirectOutput('')

Exit 0

   Function SearchReg($Key,$Str,$SrcIn)
   Dim $Idx,$vName,$Value,$num,$SubKey,$fArr,$mbr
   $SearchReg = ''
   $num = 0
   $Idx = 0
   $vName = EnumValue($Key,$Idx)
   Do
      $mbr = ''   
      If $SrcIn & 1
         $Value = ReadValue($Key,$vName)
         If InStr($Value,$Str)
            $mbr = $Key + "<=>" + IIf($vName,$vName,'<Default>')
         EndIf
      EndIf
      If ($SrcIn & 2) And InStr($vName,$Str)
         $mbr = $Key + "<=>" + $vName
      EndIf
      If $mbr
         ReDim Preserve $SearchReg[$num]
         $SearchReg[$num] = $mbr
         $num = $num + 1
      EndIf
      $Idx = $Idx + 1
      $vName = EnumValue($Key,$Idx)
   Until @Error
   $Idx = 0
   $SubKey = EnumKey($Key,$Idx)
   While $SubKey
      If ($SrcIn & 4) And InStr($SubKey,$Str)
         ReDim Preserve $SearchReg[$num]
         $SearchReg[$num] = $Key + '\' + $SubKey + "<=><KeyName>"
         $num = $num + 1
      EndIf
      $fArr = SearchReg($Key + "\" + $SubKey,$Str,$SrcIn)
      If @Error = 0
         For Each $mbr in $fArr
            ReDim Preserve $SearchReg[$num]
            $SearchReg[$num] = $mbr
            $num = $num + 1
         Next
      EndIf
      $Idx = $Idx + 1
      $SubKey = EnumKey($Key,$Idx)
   Loop
   Exit VarType($SearchReg) = 8
EndFunction

Function Get_Product_Key($sProductID)
Dim $aiKeyChars[24],$bProductKey[15],$ilByte,$i,$sCDKey,$nCur
$aiKeyChars = Split('B,C,D,F,G,H,J,K,M,P,Q,R,T,V,W,X,Y,2,3,4,6,7,8,9',',')
For $i = 0 to 14
   $bProductKey[$i] = Val("&"+SubStr($sProductID,$i*2+105,2))
Next
$sCDKey = "" 
For $ilByte = 24 to 0 Step -1
   $nCur = 0
   For $i=14 to 0 Step -1
      $nCur = $nCur * 256 | $bProductKey[$i]
      $bProductKey[$i] = Int($nCur / 24)
      $nCur = $nCur Mod 24
   Next
   $sCDKey = $aiKeyChars[$nCur] + $sCDKey
   If $ilByte Mod 5 = 0 And $ilByte <> 0
      $sCDKey = "-" + $sCDKey
   EndIf
Next
$Get_Product_Key = $sCDKey
EndFunction

Function WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x, Optional $root)
Dim $sQuery, $objEnum, $sValue, $sItem, $TMP, $SystemSet, $, $objInstance
If Not $sComputer $sComputer="." EndIf
If InStr($sComputer,'\') $sComputer=Right($sComputer,InStrRev($sComputer,'\')) EndIf
If Not $root $root="\root\cimv2" EndIf
$sQuery = "Select " + $sWhat + " From "+ $sFrom
If $sWhere And $x $sQuery = $sQuery+" Where "+$sWhere+" = '"+$x+"'" EndIf
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$sComputer+$root)
If @ERROR Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
$objEnum = $SystemSet.ExecQuery($sQuery)
If @ERROR Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
   For Each $objInstance in $objEnum
      If $objInstance
         $=Execute("$"+"sValue = $"+"objInstance."+$sWhat)
         If VarType($sValue) & 8192
            For Each $sItem in $sValue $tmp=$tmp+'|'+Trim($sItem) Next
         Else
            $tmp=$tmp+'|'+Trim($svalue)
            EndIf
         EndIf
      Next
   $WMIQuery = Split(SubStr($tmp,2),'|')
   Exit Val("&"+Right(DecToHex(@ERROR),4))
EndFunction 

Function WMIQuery2($what,$where,$computer)
    Dim $wmi, $list, $objs, $obj
    $wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!//" + $computer + "/root/cimv2")
    $list = "" $objs = $wmi.instancesof($where)
    For Each $obj in $objs
        $list = $list + $obj.description  + Chr(13) + Chr(10)
    Next
    $list=Left($list, Len($list))
    ? $what +" "+ $computer + Chr(13) + Chr(10) + $list
EndFunction


backfight
(Getting the hang of it)
2010-11-04 12:53 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Can you explain to me what has changed with this codechanges?

do i get more performance runing this script?Is there a bug in my script?


Mart
(KiX Supporter)
2010-11-04 02:08 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

If you place your original code and the code with my changes next to each other you will see the changes. I'm not going to list them one by one. All I did was implement some of my suggestions I posted earlier.

Your original code does not seem to have any bugs at first sight but I cannot guarantee that it will work immediately. You should always test your scripts in a small controlled environment before deploying them.


backfight
(Getting the hang of it)
2010-11-11 07:52 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Ok,
can u help me to code the option with the background? At the moment all clients load the background from a fileserver.

how does the code look like when they download the picture local and after that only load lacaly?

hope u understand what i mean


Mart
(KiX Supporter)
2010-11-11 09:21 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

This is based on what we use in our production environment.
It retrieves the resolution, checks if matching wallpaper exists on the server. If it does it checks if it exists locally, if not copy it. If it exists locally it checks the file time of the local file and the one on the server if they are different copy it and after all check and copying is done it sets it as the wallpaper. The last four lines set the display mode of the wallpaper.

 Code:
;Get the current screen resolution using WMI.
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
For Each $wmiObj in $wmiColl
	;Check if the found resolution is for the primary monitor.
	If $wmiObj.DeviceID = "DesktopMonitor1"
		;Combine width and height.
		$screenres = CStr($wmiObj.ScreenWidth) + "x" + CStr($wmiObj.ScreenHeight)
	EndIf
Next

;Set wallpaper for regular computers and users.
If Exist(@LDRIVE + "wallpaper\Wallpaper" + $screenres + ".bmp")
	;Copy wallpaper from the server when a local copy does not exist.
	If Not Exist("C:\localfolder\Wallpaper\Wallpaper" + $screenres + ".bmp")
		Copy @LDRIVE + "wallpaper\Wallpaper" + $screenres + ".bmp" "C:\localfolder\Wallpaper\*.*"
	Else
		;Get the timestamp of the local and remote wallpaper.
		$local = GetFileTime("C:\localfolder\Wallpaper\Wallpaper" + $screenres + ".bmp")
		$logon = GetFileTime(@LDRIVE + "wallpaper\Wallpaper" + $screenres + ".bmp")
		;If the timestamps do not match copy the wallpaper from the server. The server is leading.
		If $local <> $logon
			Copy @LDRIVE + "wallpaper\Wallpaper" + $screenres + ".bmp" "c:\localfolder\wallpaper\*.*"
		EndIf
	EndIf
	;Set the wallpaper.
	$rc = SetWallpaper ("C:\localfolder\Wallpaper\Wallpaper" + $screenres + ".bmp", 1)
	;Set the way the wallpaper is displayed.
	;Stretched: WallpaperStyle = 2, TileWallpaper = 0.
	;Centered: WallpaperStyle = 0, TileWallpaper = 0.
	;Tiled: WallpaperStyle = 0, TileWallpaper = 1.
	$rc = WriteValue("HKU\" + @SID + "\Control Panel\Desktop", "TileWallpaper", "0", "REG_SZ")
	$rc = WriteValue("HKU\" + @SID + "\Control Panel\Desktop", "WallpaperStyle", "2", "REG_SZ")
	$rc = WriteValue("HKU\" + @SID + "\Software\Microsoft\Internet Explorer\Desktop\General", "TileWallpaper", "0", "REG_SZ")
	$rc = WriteValue("HKU\" + @SID + "\Software\Microsoft\Internet Explorer\Desktop\General", "WallpaperStyle", "2", "REG_SZ")
EndIf


Arend_
(MM club member)
2010-11-11 09:31 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Mart:
 Code:
$rc = WriteValue("HKCU\" + @SID + "\Software\Microsoft\Internet Explorer\Desktop\General", "TileWallpaper", "0", "REG_SZ")
$rc = WriteValue("HKCU\" + @SID + "\Software\Microsoft\Internet Explorer\Desktop\General", "WallpaperStyle", "2", "REG_SZ")

Should be:
 Code:
$rc = WriteValue("HKU\" + @SID + "\Software\Microsoft\Internet Explorer\Desktop\General", "TileWallpaper", "0", "REG_SZ")
$rc = WriteValue("HKU\" + @SID + "\Software\Microsoft\Internet Explorer\Desktop\General", "WallpaperStyle", "2", "REG_SZ")


Mart
(KiX Supporter)
2010-11-11 10:02 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

LOL Never even noticed that. I’ve been using it in production for several months now. Fixed the code above and fixed the production code.

backfight
(Getting the hang of it)
2010-11-11 11:16 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

thanks a lot! I will try this in my testing vmware area

Arend_
(MM club member)
2010-11-11 11:38 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

\:D

backfight
(Getting the hang of it)
2010-11-11 12:37 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

is there a problem with the kix.exe in win2k8 standard r2 x64???

or does the exe run under the client?


Mart
(KiX Supporter)
2010-11-11 12:44 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

As far as I know it runs ok on x64 systems but you might want to take a look at the setoption functions and the x64 options that are there (page 98 and 99 of the 4.61 manual).

 Quote:

Wow64FileRedirection - Enables/disables file redirection on 64-bit editions of Windows. See this MSDN article for details of this feature. The default is ON. This option has no effect on 32-bit editions of Windows.

WOW64AlternateRegView - Enables access to the alternate view of the registry. See this MSDN article for details of this feature. The default is OFF. This option has no effect on 32-bit editions of Windows.


backfight
(Getting the hang of it)
2010-11-11 12:55 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

 Originally Posted By: Mart
As far as I know it runs ok on x64 systems but you might want to take a look at the setoption functions and the x64 options that are there (page 98 and 99 of the 4.61 manual).

 Quote:

Wow64FileRedirection - Enables/disables file redirection on 64-bit editions of Windows. See this MSDN article for details of this feature. The default is ON. This option has no effect on 32-bit editions of Windows.

WOW64AlternateRegView - Enables access to the alternate view of the registry. See this MSDN article for details of this feature. The default is OFF. This option has no effect on 32-bit editions of Windows.


Ok but i think i mean a different thing:

Does my script with KIX32.exe starts or transmittet on my server or on the client directly?

My Clients are only 32 Bit
And the Servers are after update all on 64 bit.



EDIT: So the question is: Does my Script run under the Client or under the server?

I hardly remember that it runs under the client right?
Run Kix32.exe logon.kix



Mart
(KiX Supporter)
2010-11-11 02:42 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Aaaah ok.
It is started on the client OS so that is WinXP-32, Win7-32 or whatever OS. It starts on the OS that is on the system that the client is running. In your case that would be a 32bit OS when a users logs on to a client and 64bit when they logon to the server in a terminal server environment for example.


backfight
(Getting the hang of it)
2010-11-13 09:40 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Can you help me to integrade 64bit clients?

I need a query that ask if it is a 32bit or 64bit client

and if it is a 64bit client then the client gets the 64bit driver from the 64bit printserver with the 64bit drivers for the printer

can i implement that in my script?

greetz
Backfight


AllenAdministrator
(KiX Supporter)
2010-11-13 02:33 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Two things...

32bit Servers can host 64bit printer drivers and vice versa. The trick is making sure the drivers are named the same. I've found that when sites like HP release their drivers, they release the 32/64bit drivers in tandem. So I always download both and install both at the same time.

More recent versions of kix support the @onwow64 macro to determine 32 or 64bit OS.


AllenAdministrator
(KiX Supporter)
2010-11-13 02:39 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

and this is two pieces of code I've used in my scripts for various things when working in a mixed 32/64bit environment.

 Code:
? @producttype + " " + iif(@onwow64,"64","32") + "bit"

$programfilesx86=iif(@onwow64,"%programfiles(x86)%","%programfiles%")
? $programfilesx86


backfight
(Getting the hang of it)
2010-11-15 07:31 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

 Originally Posted By: Allen
Two things...

32bit Servers can host 64bit printer drivers and vice versa. The trick is making sure the drivers are named the same. I've found that when sites like HP release their drivers, they release the 32/64bit drivers in tandem. So I always download both and install both at the same time.

More recent versions of kix support the @onwow64 macro to determine 32 or 64bit OS.


Thx for your reply

So do i have to install 2 printers with 1.)64bit and 2.) 32bit

or 1 printer with 32 and 64bit?


backfight
(Getting the hang of it)
2010-11-16 02:43 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Hi,
i have tasted your code. it doesn´t work. No Printers no network mappings no background :-(

can u help me to debug whats going wrong?




EDIT:
first error when i run: "wkix32.exe login.kix" is:

ERROR: undefined variable [wmiColl]!
Script C:\loginscript\login.kix
Line : 46



This is line 45-47
45 ;Get the current screen resolution using WMI.
46 $wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
47 For Each $wmiObj in $wmiColl


backfight
(Getting the hang of it)
2010-11-23 10:19 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

*push*

Mart
(KiX Supporter)
2010-11-23 10:30 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

You need to declare all variables that you have in your script.

Adding Dim $wmiColl will fix this one error but there might be more undeclared variables.


backfight
(Getting the hang of it)
2010-11-23 11:52 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Hi,
after i declare all variables i get this error:

ERROR : invalid method/function call: missing comma!
Line: 879


Here is Line 879

 Code:
$rc = WriteLine(1 "Datum der Erfassung     = " + @date + @CRLF)


But what does this error mean?


Mart
(KiX Supporter)
2010-11-23 11:57 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

This means exactly what it says. You are missing a comma just after the file handle in the writeline line.

backfight
(Getting the hang of it)
2010-11-23 12:41 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Hi
but i had copied your script code. :-/

now i get this error

ERROR : invalid method/function call: missing ')'!
Line : 906

 Code:
$rc = WriteLine(1, "CPU Modell              = " + @CPU + @CRLF)

but when i use it like this:
 Code:
$rc = WriteLine(1, "CPU Modell              = " + @CPU + @CRLF')'


Nothing change. Same error.


BradV
(Seasoned Scripter)
2010-11-23 12:56 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Why do you have single quotes around the closing parenthesis? Get rid of those and try again.

backfight
(Getting the hang of it)
2010-11-23 01:09 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

 Originally Posted By: BradV
Why do you have single quotes around the closing parenthesis? Get rid of those and try again.


that doesn´t work either

and that is what the error say´s to me. Make single quotes around the closing


BradV
(Seasoned Scripter)
2010-11-23 01:32 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

The error message had single quotes around the parenthesis to show you what it said is missing. I'm assuming the problem may be before this. Look for missing ending quotes or parenthesis before this line. I think Glenn has a sanity checker on his web site you might want to run this through.

backfight
(Getting the hang of it)
2010-11-29 08:30 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Hi,
that was exactly the mistake. Now the Script is running.

But i have another question.

I wanna make a querry if the OS is Windows XP or Windows 7. When it is Windows 7 the application does not need to run. If it is Win2k or Windows XP the application has to run.

does somebody know how to code this?

thx and bye


Mart
(KiX Supporter)
2010-11-29 08:58 AM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

You could use the macros that are available in kix. A full list is available starting on page 111 in the 4.61 manual.

backfight
(Getting the hang of it)
2010-11-29 01:13 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

where do i get the manual?

BradV
(Seasoned Scripter)
2010-11-29 01:20 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

It comes with the download. It is in Word format.

backfight
(Getting the hang of it)
2010-11-29 03:58 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

sorry but i´m not a good programmer and don´t know how to start :-/
can anybody help me?

i have no solution how to get rid of it


Mart
(KiX Supporter)
2010-11-29 04:14 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

The code below checks if the string returned by @PRODUCTTYPE contains Windows 2000 or Windows XP and does stuff if this is true and does other stuff when it is not true.


 Code:
If InStr(@PRODUCTTYPE, "Windows 2000") Or InStr(@PRODUCTTYPE, "Windows XP")
	;Do stuff
Else
	;Do other stuff
EndIf 


Glenn BarnasAdministrator
(KiX Supporter)
2010-11-29 07:12 PM
Re: Does my script runs under Windows 2k8 and 2k8 Active Directory?

Click on the Kixtart.org Website link at the top of the page - an online form of the manual is there (command reference) as well as links to get the full documentation in Word or PDF format.

Glenn