Showing posts with label desktop. Show all posts
Showing posts with label desktop. Show all posts

Saturday, October 3, 2009

VBScript - Get Remote Asset Tag (Serial Number)

Function AssetNumber(strComputer)
    Dim objWmi, objWmiCS, obj, retval
    On Error Resume Next
    Set objWmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2")
    If err.Number <> 0 Then
        wscript.echo "error: " & err.Number & " / " & err.Description
        err.Clear
        Set objWMI = Nothing
        retval = "*** unavailable ***"
    Else
        Set objWmiCS = objWmi.ExecQuery("select * from Win32_ComputerSystemProduct")
        For Each obj in objWmiCS
            retval = obj.IdentifyingNumber
        Next
        Set objWmiCS = Nothing
        Set objWMI = Nothing
    End If
    AssetNumber = retval
End Function

wscript.echo AssetNumber("holland")

Wednesday, July 15, 2009

Packaging Gone Awry?

What's up with packaging these days? It seems every manufacturer, container shipper, and postal carrier entity is experimenting with new ways to package things. Some are borderline clever. Some are just outright dumb. This goes beyond the pack-and-ship aspects. I'm also talking about how desktop and laptop computers are assembled.

Since 2000, I've counted no less than two dozen unique assembly methods used by Dell and HP alone. Screws, thumb-screws, clips, snaps, notches, latches, folding, sliding, lifting, pulling. You name it. What's up with that? Why screws anyway? As if the little toy-like lock hasps are any deterrent to thieves and tinkerers. Just make the cases snap together and be done with it. And if you look at the insides of a computer, oh geez. One minute of gazing and you can easily spot a half-dozen fabrication head-scratchers. Things that make you ask "why do it that way?"

I'm not talking about complicated things either. This applies to simple boxes like the power supply, cd/dvd drives and backplanes. The costs being wasted by overly complicated fastening methods, attachment methods, alignment methods, and so on, is just insane.
The reason in most cases is patent blocking. Someone holds patents on the simplest methods and won't play nice with the big players anymore. So they do their own and it ends up being a clusterf**k. Given that not one single manufacturer uses a common-sense assembly approach (except for maybe Apple, in some cases, pardon the pun) I am wondering if it's the patent holder that's to blame. Demanding too high of a price for licensing. Or maybe they just don't want to play at all. Who knows. We're paying the price, both literally and indirectly (ripping our fingers on the sharp edges, contorting to plug things in). Progress and innovation have been tossed into a cell and locked up by attorneys. The 20th century was all about making new things. The 21st century is shaping up to be about protecting things, pure and simple. RIP innovation.

Saturday, July 11, 2009

KiXtart: Customize OEM Support Information


? "[OEMSupportTag].....: Configuring OEM Support applet..."
Dim $oeminfo, $oemlogo, $oemsupp, $x, $regkey
Dim $logfile, $oemlogosrc, $oemsuppsrc
Dim $wmi, $wmi_compsys, $wmi_comp, $model, $desc, $asset
$weblink = "https://intranet.company.com/helpdesk"

$regkey = "HKLM\System\CurrentControlSet\Control\Windows"
$value = ReadValue($regkey,"SystemDirectory")
$windir = ExpandEnvironmentVars($value)

If $windir <> ""
$oeminfo = $windir+"\oeminfo.ini"
$oemlogo = $windir+"\oemlogo.bmp"
$oemsupp = $windir+"\web\support.htm"
$logfile = $windir+"\custom_oem.ini"
$oemlogosrc = @lserver+"\netlogon\oemlogo.bmp"
$oemsuppsrc = @lserver+"\netlogon\support.htm"

If Exist( $oeminfo ) = 1
? "[OEMSupportTag].....: removing existing oeminfo.ini file..."
Del( $oeminfo )
Else
? "[OEMSupportTag].....: no existing oeminfo.ini file found."
EndIf

? "[OEMSupportTag].....: attempting to create new oeminfo.ini file..."
If Open(2, $oeminfo, 5) = 0
? "[OEMSupportTag].....: file created successfully, updating contents..."
$wmi = "WINMGMTS:{IMPERSONATIONLEVEL=IMPERSONATE}!//"+@wksta
$wmi_compsys = "SELECT * FROM Win32_ComputerSystemProduct"
$wmi_comp = GetObject($wmi).ExecQuery($wmi_compsys)
For Each $objsys In $wmi_comp
$model = $objsys.Name
$desc = $objsys.Description
$asset = $objsys.IdentifyingNumber
Next
$=WriteLine(2,"[General]" + @crlf)
$=WriteLine(2,"Manufacturer=MY COMPANY, INC." + @crlf)
$=WriteLine(2,"Model="+$model + @crlf)
$=WriteLine(2,"SupportURL=$weblink" + @crlf)
$=WriteLine(2,"LocalFile=%windir%\web\support.htm" + @crlf + @crlf)
$=WriteLine(2,"[OEMSpecific]" + @crlf)
$=WriteLine(2,"SubModel=" + @crlf)
$=WriteLine(2,"SerialNo=" + @crlf)
$=WriteLine(2,"OEM1="+$asset + @crlf)
$=WriteLine(2,"OEM2=" + @crlf + @crlf)
$=WriteLine(2,"[ICW]" + @crlf)
$=WriteLine(2,"Product=Computer Asset" + @crlf + @crlf)
$=WriteLine(2,"[Support Information]" + @crlf)
$=WriteLine(2,"Line1=COMPUTER HELP DESK" + @crlf)
$=WriteLine(2,"Line2= " + @crlf)
$=WriteLine(2,"Line3=Contact Technical Support by web or phone:" + @crlf)
$=WriteLine(2,"Line4= " + @crlf)
$=WriteLine(2,"Line5= $weblink" + @crlf)
$=WriteLine(2,"Line6= 1-800-555-1212" + @crlf)
$=WriteLine(2,"Line7= " + @crlf)
$=WriteLine(2,"Line8=After hours/weekends/holidays..." + @crlf)
$=WriteLine(2,"Line9=support options may be limited." + @crlf)
$=WriteLine(2,"Line10=------------------------------" + @crlf)
$=WriteLine(2,"Line11=Computer Name: " + @wksta + @crlf)
If Trim($asset) <> ""
$=WriteLine(2,"Line12=Asset Tag: " + Trim($asset) + @crlf)
$=WriteLine(2,"Line13=IPAddress: " + @ipaddress0 + @crlf)
Else
$=WriteLine(2,"Line12=IPAddress: " + @ipaddress0 + @crlf)
EndIf
Close(2)
? "[OEMSupportTag].....: oeminfo.ini file has been successfully updated!"
Else
? "[OEMSupportTag].....: Error: failed to create new oeminfo.ini file!"
EndIf

? "[OEMSupportTag].....: oeminfo logo graphic updated already?..."
If Exist( $logfile ) = 0
? "[OEMSupportTag].....: attempting to create new oeminfo update log file..."
If Exist( $oemlogosrc ) = 1
? "[OEMSupportTag].....: downloading oeminfo logo graphic file..."
Copy $oemlogosrc $oemlogo
If Open(3, $logfile, 5) = 0
WriteLine(3,"[General]"+@crlf)
WriteLine(3,"DateAdded="+@date+@crlf)
Close(3)
? "[OEMSupportTag].....: oeminfo log updated."
EndIf
Else
? "[OEMSupportTag].....: oeminfo graphic file missing: "+$oemlogosrc
EndIf
Else
? "[OEMSupportTag].....: "+$logfile+" previously recorded."
EndIf
Else
? "[OEMSupportTag].....: Error: windir variable not set, aborting process."
EndIf

KiXtart: Get Asset Number

WMI query for asset number (e.g. Dell Asset, HP Serial number, etc.)


Function AssetNumber()
Dim $objWmi, $objWmiCS, $obj, $retval, $pc
$pc = @wksta
$objWmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\$pc\root\cimv2")
$objWmiCS = $objWmi.ExecQuery("select * from Win32_ComputerSystemProduct")
For Each $obj in $objWmiCS
$retval = $obj.IdentifyingNumber
Next
$AssetNumber = Trim($retval)
EndFunction

Friday, July 10, 2009

KiXtart: Enumerate HOSTS file Entries


Break ON

$systemRoot = ExpandEnvironmentVars("%systemroot%")
$hostsFile = $systemRoot+"\system32\drivers\etc\hosts"
$fileHandle = FreeFileHandle()
$entries = 0

If Exist($hostsFile)
? "info: hosts file found at "+$hostsFile
If Open($fileHandle, $hostsFile, 1) = 0
? "info: reading file..."
$line = ReadLine($fileHandle)
While @ERROR = 0
If Left($line, 1) <> "#"
; ignore lines beginning with # as they are comments
? "line --> $line"
$entries = $entries + 1
EndIf
$line = ReadLine($fileHandle)
Loop
$=Close($fileHandle)
? "info: $entries entries found"
Else
? "fail: unable to open hosts file!"
EndIf
Else
? "fail: hosts file cannot be found!"
EndIf

VBScript: Sort Start Menu Items


Const optionType = 1
Const regBase = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder"

Set objShell = CreateObject("Wscript.Shell")

If optionType = 1 Then
' a sloppy, cheap, but effective way to do this with Wscript
cmd1 = "start /wait reg delete """ & regBase & "\Start Menu"" /f"
cmd2 = "start /wait reg delete """ & regBase & "\Start Menu2"" /f"
cmd3 = "start /wait taskkill /im explorer.exe /F"
cmd4 = "explorer.exe"
objShell.Run "cmd.exe /c " & cmd1, 1, True
objShell.Run "cmd.exe /c " & cmd2, 1, True
objShell.Run "cmd.exe /c " & cmd3, 1, True
objShell.Run "cmd.exe /c " & cmd4, 1, True
Else
' a more elegant, poofy and girly way of doing this with style and ambiance
objShell.RegDelete regBase & "\Start Menu\"
objShell.RegDelete regBase & "\Start Menu2\"
objShell.Run "cmd.exe /c start /wait taskkill /im explorer.exe /F", 1, True
objShell.Run "cmd.exe /c explorer.exe", 1, True
End If

Set objShell = Nothing

Thursday, July 9, 2009

PowerShell: Update Desktop Shortcut Targets


# iterate shortcuts to find matching target paths and
# if found, replace with new target path and save link

$desktop = $home+"\desktop"
$oldPath = "\\server1\sharename1"
$newPath = "\\server2\sharename1"

$shell = New-Object -ComObject WScript.Shell

$Dir = get-childitem $desktop -recurse

foreach($file in $Dir) {
$fname = $file.Name
# write-host $fname
$lnk = $shell.CreateShortcut($desktop+"\"+$fname)
$target = $lnk.TargetPath
if ($target -eq $oldPath) {
write-host "Updating shortcut target..."
$lnk.TargetPath = $newPath
$lnk.Save()
}
}

Tuesday, July 7, 2009

KiXtart: Update Desktop Shortcuts


Break ON

$oldPath = "\\server1\shareName1"
$newPath = "\\server2\shareName2"

$shell = CreateObject("WScript.Shell")
$DesktopPath = ExpandEnvironmentVars("%userprofile%")+"\Desktop"

$FileName = Dir("$DesktopPath\*.lnk")
While $FileName <> "" And @error = 0
? $FileName
$link = $shell.CreateShortcut("$DesktopPath\$FileName")
If Ucase($link.TargetPath) = Ucase($oldPath)
$link.TargetPath = $newPath
$link.Save
EndIf
$FileName = Dir()
Loop

KiXtart: Enumerate Local Shares


Break ON

$strComputer = "."
$tab = Chr(9)

$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\$strComputer\root\cimv2")
$colShares = $objWMIService.ExecQuery("Select * from Win32_Share")
$numshares = $colShares.Count

? "shares found: $numshares"

For each $objShare in $colShares
$n = $objShare.Name
If Right($n,1) = "$$"
$shareType = "HIDDEN"
Else
$shareType = "OPEN"
EndIf
? $objShare.Name + $tab + $shareType + $tab +
$objShare.Path + $tab + $objShare.Caption + $tab +
$objShare.Type
Next

Sunday, July 5, 2009

VBScript Enumerate Shortcuts

Enumerate shortcuts under all-users profile and report in XML format...

Option Explicit
Const strComputer = "."

Const rKey = "Software\Microsoft\Windows NT\CurrentVersion\ProfileList"
Const rVal = "ProfilesDirectory"
Const HKCU = &H80000001
Const HKLM = &H80000002

Dim objShell, objFSO, oReg, objRootFolder, psub, p
Dim objFolder, objLink, objFsub, linkpath, uid, objLnk

Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

If err.Number <> 0 Then
wscript.echo "error: computer is not accessible"
wscript.Quit(1)
End If

oReg.GetExpandedStringValue HKLM, rKey, rVal, p
If VarType(p) = vbNull Then
wscript.echo "error: registry key not found"
wscript.Quit(1)
End If

Set objRootFolder = objFSO.GetFolder(p)

wscript.echo ""
wscript.echo ""
For each objFolder in objRootFolder.SubFolders
uid = objFolder.Name
psub = p & "\" & uid & "\desktop"
If objFSO.FolderExists(psub) Then
wscript.echo vbTab & ""
Set objFsub = objFSO.GetFolder(psub)
For each objLink in objFsub.Files
If InStr(1, ".lnk .url", Lcase(Right(objLink.Name,4))) <> 0 Then
wscript.echo vbTab & vbTab & ""
linkpath = psub & "\" & objLink.Name
Set objLnk = objShell.CreateShortcut(linkpath)
Select Case Lcase(Right(linkpath,4))
Case ".lnk":
ClosedTag 3, "name", objLnk.Name
ClosedTag 3, "fullname", objLnk.FullName
ClosedTag 3, "arguments", objLnk.Arguments
ClosedTag 3, "working", objLnk.WorkingDirectory
ClosedTag 3, "target", objLnk.TargetPath
ClosedTag 3, "icon", objLnk.IconLocation
ClosedTag 3, "hokey", objLnk.Hotkey
ClosedTag 3, "windowstyle", objLnk.WindowStyle
ClosedTag 3, "description", objLnk.Description
ClosedTag 3, "type", "filesystem"
Case ".url":
ClosedTag 3, "name", objLnk.Name
ClosedTag 3, "fullname", objLnk.FullName
ClosedTag 3, "target", objLnk.TargetPath
ClosedTag 3, "type", "internet"
End Select
wscript.echo vbTab & vbTab & "
"
End If
Next
wscript.echo vbTab & "
"
End If
Next
wscript.echo "
"

Sub ClosedTag(indent, label, val)
Dim i, s : s = ""
For i = 1 to indent
s = s & vbTab
Next
If Trim(val) = "" Then
s = s & "<" & label & ">_"
Else
s = s & "<" & label & ">" & val & ""
End If
wscript.echo s
End Sub

Set objFolder = Nothing
Set objFSO = Nothing
Set objShell = Nothing