I have the following code that writes to a hardware log from the login script. The problem is that IF the Excel file is open the user is asked if he wants to save the spreadsheet.
Anyone got any idea why?
code:
$product = @producttype + ", " + @csd + ", " + @build
$Serial = WMIQuery("SerialNumber","Win32_BIOS")[0]
if trim($Serial) = ""
$file = "@LServer\Users\" + @wksta + ".cfg"
shell "sm_info > $file"
$ = open(1,$file)
$line =""
while left($line ,12) <> "Service tag:"
$line = readline(1)
loop
$Serial = right($line,len($line)-13)
endif
$Manufacturer = WMIQuery("Manufacturer","Win32_ComputerSystem")[0]
if $Manufacturer = "Dell Computer Corporation"
$Manufacturer = "Dell"
endif
$Model = WMIQuery("Model","Win32_ComputerSystem")[0]
$BiosVer = WMIQuery("SMBIOSBIOSVersion","Win32_BIOS")[0]
$Memory = WMIQuery("TotalPhysicalMemory","Win32_LogicalMemoryConfiguration")[0]
$xlFile = "@LServer\Users\machines.xls"
$xl = createobject("excel.application")
if not @error
$ = $xl.Workbooks.Open($xlFile)
$Row = 1
$CellValue = $Xl.Cells($Row,1).Value
While $CellValue <> @wksta And $CellValue <> ''
$Row = $Row + 1
$CellValue = $Xl.Cells($Row,1).Value
Loop
If $CellValue = @wksta
$SearcStartRow = $Row + 1
EndIf
$xl.Range("A"+$row).Value = @wksta
$xl.Range("B"+$row).Value = $product
$xl.Range("C"+$row).Value = trim(@cpu)
$xl.Range("D"+$row).Value = $Serial
$xl.Range("E"+$row).Value = $Manufacturer
$xl.Range("F"+$row).Value = $Model
$xl.Range("G"+$row).Value = $BiosVer
$xl.Range("H"+$row).Value = $Memory
$xl.Range("I"+$row).Value = @fullname
$xl.Range("J"+$row).Value = @date
$xl.Range("K"+$row).Value = @time
$ = $xl.ActiveWorkbook.Save
$xl.UserControl = 1
$bye = $xl.quit
else
exit 0
endif
Color w+/n
exit
FUNCTION WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x)
Dim $sQuery, $objEnum, $sValue, $sItem, $lUbound
Dim $aTMP[0]
$sQuery = "Select " + $sWhat + " From "+ $sFrom
If Not $sComputer
$sComputer=@WKSTA
EndIf
If $sWhere AND $x
$sQuery = $sQuery + " Where " + $sWhere + " = '"+$x+"'"
EndIf
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//"+$sComputer)
If @ERROR
Exit VAL("&"+Right(DecToHex(@ERROR),4))
Return
EndIf
$objEnum = $SystemSet.ExecQuery($sQuery)
If @ERROR
Exit VAL("&"+Right(DecToHex(@ERROR),4))
Return
EndIf
For Each $objInstance in $objEnum
If $objInstance
$=Execute("$$sValue = $$objInstance.$sWhat")
Select
Case VarType($sValue) & 8192
For Each $sItem in $sValue
$lUbound = Ubound($aTMP)
If $aTMP[$lUbound] >' '
$lUbound = $lUbound +1
Redim Preserve $aTMP[$lUbound]
EndIf
$aTMP[$lUbound] = Trim($sItem)
Next
Case 1
$lUbound = Ubound($aTMP)
If $aTMP[$lUbound] >' '
$lUbound = $lUbound +1
Redim Preserve $aTMP[$lUbound]
EndIf
$aTMP[$lUbound] = Trim($sValue)
EndSelect
EndIf
Next
$WMIQuery = $aTMP
Exit VAL("&"+Right(DecToHex(@ERROR),4))
ENDFUNCTION