Thursday, January 23, 2014

windows ip switcher

Where I work, I support multiple offices.  Most of the offices do not have DHCP, they use static ip addresses (not my decision).  So here is a script I made for changing the ip address settings on a windows laptop, this does have to be ran with full admin privileges.  You will have to change parts of this script for your usage (where ever you see an ip address, and probably want to change the labels for the networks also).

echo ip-switch ver 20081119

set baseoffice=hq

rem now we figure out what subnet we're on
for /f "tokens=2 delims=:" %%i in ('ipconfig ^|find "IP Address"') do set ipaddr=%%i
for /f "tokens=2,3 delims=." %%o in ('echo %ipaddr%') do set subnet=%%o.%%p


rem based on the sub-net we determine what our location is
if /i "%subnet%" == "10.10" set loc=hq
if /i "%subnet%" == "10.11" set loc=sub
if /i "%subnet%" == "11.11" set loc=b1
if /i "%subnet%" == "11.12"  set loc=b2
if "%loc%" == "hq" set comploc=acompanyoffice
if "%loc%" == "substation" set comploc=acompanyoffice
if "%loc%" == "branch1" set comploc=acompanyoffice
if "%loc%" == "branch2" set comploc=acompanyoffice
if "%comploc%" == "acompanyoffice" goto comploc
set comploc=remote
:comploc


echo off

:complocmenu
cls
if "%comploc%" == "acompanyoffiice" echo this computer is currently setup for %comploc% (%loc%) use
if "%comploc%" == "remote" echo this computer is currently setup for %comploc% use
echo where is this laptop now (so it can communicate with the internet)?
echo 1) your base office (%baseoffice%)
echo 2) remote, home/other office
echo x) exit (leave everything as it is)
echo if another office enter the two-three letter abbreviation for it,
echo (hq,sub,b1,b2,etc...), and press enter, otherwise,
set /p comploc=press 1,2 or x and then enter:
rem if we entered a correct choice go to the next menu
if "%comploc%" == "1" goto methodmenu
if "%comploc%" == "2" goto methodmenu
if "%comploc%" == "x" echo no changes will be made
if /i "%comploc%" == "x" goto endprog
if /i "%comploc%" == "hq" goto otheroffice
if /i "%comploc%" == "sub" goto otheroffice
if /i "%comploc%" == "b1" goto otheroffice
if /i "%comploc%" == "b2" goto otheroffice


cls
rem if we entered a wrong chose clear screen of distraction
rem and ask for correct input
echo "you must press 1 or 2, or just press enter"
goto complocmenu

:otheroffice
set baseoffice=%comploc%
goto methodmenu

:methodmenu
echo is the laptop plugged in or using wireless?
echo 1) plugged in
echo 2) wireless
echo x) endprog
set /p netmethod=press 1 or 2 and then press enter

if "%netmethod%" == "1" set conmethod="Local Area Connection"
if "%netmethod%" == "2" set conmethod="Wireless Network Connection"
if "%netmethod%" == "1" goto methodselected
if "%netmethod%" == "2" goto methodselected
if "%netmethod%" == "x" goto endprog
echo "incorrect method selected"
goto methodmenu
:methodselected


if "%comploc%" == "1" goto staticip
if "%comploc%" == "2" goto dhcpip

:staticip
echo we will configure the computer for jcc office use
rem goto endprog
rem remove the goto endprog when we fix these settings
rem set static ip address (needs to be edited)

for /f "tokens=1 delims=-" %%I in ('echo %baseoffice%') do set loc=%%I
for /f "tokens=2 delims=-" %%C in ('hostname') do set compip=%%C
echo computer ip is %compip%

if /i "%baseoffice%" == "h1" set netaddr=10.10.10
if /i "%baseoffice%" == "sub" set netaddr=10.10.11
if /i "%baseoffice%" == "b1" set netaddr=10.11.11
if /i "%baseoffice%" == "b2" set netaddr=10.11.12




echo network address is %netaddr%

rem netsh interface ip set address "Local Area Connection" static %netaddr%.%compip% 255.255.255.0 %netaddr%.1 1
rem netsh interface ip set dns "Local Area Connection" static 10.91.1.21
rem netsh interface ip set wins "Local Area Connection" static 204.130.253.130
netsh interface ip set address %conmethod% static %netaddr%.%compip% 255.255.255.0 %netaddr%.1 1
netsh interface ip set dns %conmethod% static 10.91.1.21
netsh interface ip set wins %conmethod% static 10.254.2.130
rem start /wait sysdm.cpl

goto endprog


:dhcpip
rem some netsh commands to set dhcp on the interface
netsh interface ip set address name=%conmethod% source=dhcp
netsh interface ip set dns name=%conmethod% source=dhcp
netsh interface ip set wins name=%conmethod% source=dhcp
goto endprog

:endprog
hostname
for /f "tokens=2 delims=:" %%i in ('ipconfig ^|find "Default Gateway"') do set gateway=%%i
ipconfig |find "Address"
ping %gateway%
echo if you got back replys your good, if any of the requests timed out that's not good.
pause

Thursday, December 12, 2013

change system SQL database connection

In windows you can create a database connection for your front end program to use.  Well as with all things in life things change, you decide to get a new database server, you messed up on the initial imaging of the workstations, you decided to expand or consolidate your database servers.  Instead of having to go around to each desktop and dig through control panel on each one to edit the database connection, here's a script to change the server.

This does not create a new database connection on each computer, for that you'll probably want to do configuration through control panel on one of the computers and then export it out the HKLM\SOFTWARE\Wow6432Node\ODBC\ODBC.INI or HKLM\SOFTWARE\ODBC\ODBC.INI keys to a file.

If your database is something other then CMS you'll need to change the key path referenced below.




@echo off
if "%1" == "" goto needarguments
for /f "tokens=2" %%W in ('date /t') do set dater=%%W
for /f "tokens=1-3 delims=/" %%d in ('echo %dater%') do set curdate=%%f%%d%%e
rem what we're changing the CMS database server to.
set dsnserver=newprod



:nextcomp
set remotecomp=%1
rem need to do some ping checks and stuff
echo updating %1 at %time%


for /f "tokens=2 skip=1 delims==" %%q in ('ping -n 1 %1') do set pingtimer=%%q
for /f "tokens=1 delims=m" %%s in ('echo %pingtimer%') do set pingtime1=%%s


if "%pingtime1%" == "1 Received " set pingtime1=down
if "%pingtime1%" == "down" echo %1 down at %date% %time% >> pc-down-dsn-%curdate%.lst
if "%pingtime1%" == "down" goto thiscompfinished



rem this works only if changing the server, if no dsn/odbc connection is
rem yet set up, you'll need to add more registry keys then just this one.
rem echo on
if exist \\%1\c$\windows\syswow64 reg add "\\%1\HKLM\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\CMS" /v Server /t reg_sz /d %dsnserver% /f
if not exist \\%1\c$\windows\syswow64 reg add "\\%1\HKLM\SOFTWARE\ODBC\ODBC.INI\CMS" /v Server /t reg_sz /d %dsnserver% /f
if errorlevel 1 echo %1 had error updating dsn on %date% %time% >> pc-error-dsn-%curdate%.lst
if errorlevel 0 echo %1 updated dsn to %dsnserver% on %date% %time% >> pc-fixed-dsn-%curdate%.lst
echo off


:thiscompfinished
shift
if not "%1" == "" goto nextcomp
echo finished at %date% %time%
goto end


:needarguments
echo usage: %0 comp1 comp2 comp3 etc...
echo make sure to not use any \\







:end

Monday, December 9, 2013

IE Tracking protection lists

Where I'm at we have a web filtering device that will display a full pdf with the employer's terms of service if you go to a website we have blocked.  Problem is one of those is facebook, and if you go to say a news site and it has a facebook like button, the news site isn't blocked, but you still get a huge pdf file come up on your screen.

Thankfully if you're running a newer version of Internet Explorer, there is a feature called "Tracking Protection Lists", while meant to improve your privacy, they can also disable the facebook "like" button that you find on many websites. Problem is digging through all of IE's settings can be a pain.  So here is a simple internal web page for users to go to load the page (just have to click a button on the page).

note: If you're using IIS to serve this you will need to go into the server's "MIME Types" and add
the .tpl extension.  I labeled it as "application/ie", IIS apparently won't serve unknown MIME types.

First file is the tracking protection list file that we want IE to load.
#------------------don't include this line in facebook-block.tpl ---------------------------
msFilterList
: Expires = 5
# blocked strings
- like.php
# domain rules
-d facebook.com
-d facebook.net
# from http://anglachelg.blogspot.com/2011/04/create-your-own-tpl-for-ie9.html
#------------------don't include this line in facebook-block.tpl ---------------------------

------index.html --- don't include this line ---------------------
<!DOCTYPE html />
<html >
<head>
<!--- from http://msdn.microsoft.com/en-us/library/hh273399%28v=vs.85%29.aspx -->
    <title>Internet Explorer 9 Tracking Protection list loader</title>
    <script type="text/javascript">
 
    function checkTP() {
    //checks whether Tracking Protection has been enabled (any list is on)
        if (window.external.msTrackingProtectionEnabled())
      {
            document.getElementById("results").innerHTML = "Tracking protection is: ON";
        } else {
            document.getElementById("results").innerHTML = "Tracking protection is: OFF";
        }
    }

    //loads a list specified by input field
    function loadTPFile() {
        var URL = document.getElementById("tplfile").value;      
        var description = 'Facebook blocking Tracking Protection List';      
        window.external.msAddTrackingProtectionList(URL, description);
    }
</script>

</head>
<body>
<!---- First check that you have tracking protection enabled by click the
"check tracking protection" button
<div>
  <button onclick="checkTP();">Check tracking protection</button>
  <span id="results">Tracking protection is: </span>
</div>
<p />
Remember that you need to have tracking protection "on" for this to work
if tracking protection is off, go to: <br>
tools, tracking protection, select "Your Personalized List" and click enable, close, <br>
then click on the "check tracking protection" button again.

--->
<p />
This is for blocking the facebook like button (and facebook's other tracking mechanisims),
that are on many websites nowdays, which cause the company's usage policy to pop up.  To stop this: <br>
click on "load TPL file"
and click on the "add list" button
<p />
<div>
  <button onclick="loadTPFile();">Load TPL file</button>
  <input id= "tplfile" type="text" value="facebook-block.tpl" size="60" />
</div>

<p />
Remember if you go to the facebook.com website itself you will still get a copy of the company's
Internet usage policy poping up.
</body>
</html>


Monday, September 23, 2013

enable basic games in windows

To enable/disable features in windows 7 you use dism (deployment image servicing and management).

The following batch file will enable the basic games (chess, minesweeper, solitaire, etc...), but not any of the internet games.
This will have to be ran with full admin privileges.

rem --------------games-enable-w7.bat--------------
rem to get a list of whats available and enabled/disabled
rem dism /online /Get-Features
echo make sure you're running this with admin privleges
dism /online /enable-feature /featurename:"InboxGames"
dism /online /disable-feature /featurename:"Internet Games"
dism /online /disable-feature /featurename:"More Games"
rem ---------end of batch script----------------


Wednesday, July 31, 2013

setting windows permissions from the command line using icacls

Why set permissions from the command line when you can just right click and check or uncheck a few boxes?

Well checking boxes is great, if you only have one computer or two, and never have to re-do it.  Once you have a few, well it's probably time to script it :)

Here are some basic ones I've used

To lock down a folder so that no one can delete what they created, a write only folder, (two liner):
icacls d:\writeonlyfolder /deny Everyone:(CI)(OI)(DE)
icacls d:\writeonlyfolder /deny Everyone:(CI)(OI)(DC)


So that people can't put any files in a folder (just subfolders)
icacls d:\parentfolder /deny "Domain Users":(WD)

This is a locked down structure, where only the creator of a folder on a share
has access to the contents, no one else can even get into the folder created, other then administrators.

rem we do want administrators and the creator of the folder though to have access
icacls d:\secured /grant:r "Domain Administrators":(OI)(CI)F
icacls d:\secured /grant:r "Creator Owner":(OI)(CI)F
allow users to create folders in the parent folder.
icacls d:\secured /grant:r users:WRXM
remove any inheritance which could cause issues.
icacls d:\secured /inheritance:r 

Background on how windows file permissions work:

Tuesday, July 9, 2013

Git revision control on windows via cygwin

With all this scripting one needs to be able to track the changes to their larger scripts.  You can do the crude append -## to the file-name where ## is some revision number, but if you have a large script that you change a lot over a long period of time, relying on this, or file system backups, just doesn't work very well.  Fortunately the programming field has revision control, and I've decided to use GIT.   Unfortunately tortoise git while it is easy to use and install, caused some issues where browsing via network neighborhood to a remote site was slowed down tremendously.

So I decide to use cygwin and the git it has, unfortunately the git gui interface (which I'm use to from tortoise git), is a little tricky to set up.

When in the cygwin setup go into the "Devel" section and select all the items that start with git, including gitk, then go to the "X11" section and select, X-Start-menu-icons, and xinit.  Once the cygwin setup program finished up, click on the start button, all programs, cygwin-x, X win server.  You should see a white terminal box pop up.  Use normal unix/linux commands to go the directory where your scripts are, and run your git commands.  The reason for using the white terminal window from the X-win-server is so that you can run gitk.  For some reason git gui gives me an error, but gitk works just fine.

The git gui that is in cygwin is just for browsing the history of your code, to actually commit changes, and do anything other then view, you will still need to use the command line:

For those new to git at the command line this is my cheetsheet
for more commands and details of the commands check http://www.vogella.com/articles/Git/article.html

first create the repository
git init

add files to the repository
git add filename

see the changes since the last commit:
git diff

commit the changes:
git commit -m "some comments"

commit a particular file:
git commit script.bat

git status

git add script.bat

git log

see the commits for a file
git log filename

see the diffs of each commit for a file
git log -p filename

see the entire history
git log --follow -p file

Thursday, May 23, 2013

Monitor Inventory script

Inventory time.  That time of the year where property control (or whatever they call it in your business), wants to know where everything is, usually for tax or insurance purposes.

There's a good chance you already have a means for easily finding a computer if you have its serial number, several products will make it so that it's at least not too hard, and you may even have your own records for the computers.  If you don't already, I have a script for that, that I'll post latter.  However property control wants to know about everything, not just the tower unit, but furniture, metal detectors, TV's, monitors, etc...

I can't help you for most of those things, but if you got property control asking you where are your different monitors, because they're hooked into the computer, or maybe you did some moving or replacing of the monitors, I have something that may help, if they have the serial numbers for the monitors.

I've only ran this on dell computers with dell monitors with admin rights to all the computers, but if you have a different setup, you can still try this script, no guarantees though.... If you still can't find your monitor, make sure the computer is on, and that it's not in a store room somewhere unplugged.


The resulting csv file looks like:
machine, monitor model, serial, mfg, date of mfg

comp1,DELL 1702FP,8G1522CGxxx1,DEL,12/2002
comp2,DELL 1907FP,DC32364Hxxx2,DEL,4/2006
comp3,DEL 1908FPBLK,D325J958xxx3,DEL,5/2009
comp4,DELL 1702FP,8G1522CGxxx4,DEL,12/2002

remember, on dell monitors at least, it only pulls approximately the last half of the monitor's serial number.

this is the batch file that has all the computers you want to check for monitors on, and runs a vbscript on each one, which saves the monitor information into a csv file.


rem monitor-inventory.bat
rem you'll probably want to change the location of the csv file
set csvfile=\\fileserver\staff\it-docs\monitors.csv
rem the first line of the csv file so you know what's in each column.
echo machine, monitor model, serial, mfg, date of mfg >> %csvfile%
rem the list of the computers are in the parenthesies for the following lines, if you have
rem a lot of computers you can add more lines, or have multiple copies of this bat file
rem with different names, and different computers listed in each
for %%C in (server reception secretary manager boss comp1 comp2 comp3 comp4 ) do cscript %progpath%mon-serial-num-v2.vbs %%C >> %csvfile% //nologo
for %%C in (comp5 comp6 video guard) do cscript %progpath%mon-serial-num.vbs %%C >> %csvfile% //nologo
rem --------------------------------------------------


The following is the core vb script that is based in large part on a script from: http://social.technet.microsoft.com/Forums/da-DK/ITCG/thread/18f72e8d-d3ee-4e51-a55d-aa5fd26db974
Some modifications were made to make it work with my batch file above.


'--------------------------------------------------------------

Option Explicit
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim strComputer, message


Dim intMonitorCount
Dim oRegistry, sBaseKey, sBaseKey2, sBaseKey3, skey, skey2, skey3
Dim sValue
dim i, iRC, iRC2, iRC3
Dim arSubKeys, arSubKeys2, arSubKeys3, arrintEDID
Dim strRawEDID
Dim ByteValue, strSerFind, strMdlFind
Dim intSerFoundAt, intMdlFoundAt, findit
Dim tmp, tmpser, tmpmdl, tmpctr
Dim batch, bHeader
batch = True
'most of this script is stolen from: http://social.technet.microsoft.com/Forums/da-DK/ITCG/thread/18f72e8d-d3ee-4e51-a55d-aa5fd26db974


If WScript.Arguments.Count = 1 Then
strComputer = WScript.Arguments(0)
'batch = True
Else
strComputer = wshShell.ExpandEnvironmentStrings("")
strComputer = InputBox("Check Monitor info for what PC","PC Name?",strComputer)
End If


If strcomputer = "" Then WScript.Quit
strComputer = UCase(strComputer)


If batch Then
Dim fso,logfile, appendout
logfile = wshShell.ExpandEnvironmentStrings("%userprofile%") & "\desktop\MonitorInfo.csv"


'setup Log
Const ForAppend = 8
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(logfile) Then bHeader = True
set appendout = fso.OpenTextFile(logfile, ForAppend, True)


If bHeader Then
appendout.writeline "Computer,Model,Serial #,Vendor ID,Manufacture Date,Messages"
End If
End If


Dim strarrRawEDID()
intMonitorCount=0
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
'get a handle to the WMI registry object
On Error Resume Next
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "/root/default:StdRegProv")


If Err <> 0 Then
If batch Then
EchoAndLog strComputer & ",,,,," & Err.Description
Else
MsgBox "Failed. " & Err.Description,vbCritical + vbOKOnly,strComputer
WScript.Quit
End If
End If




sBaseKey = "SYSTEM\CurrentControlSet\Enum\DISPLAY\"
'enumerate all the keys HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\
iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys)
For Each sKey In arSubKeys
'we are now in the registry at the level of:
'HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\<VESA_Monitor_ID\
'we need to dive in one more level and check the data of the "HardwareID" value
sBaseKey2 = sBaseKey & sKey & "\"
iRC2 = oRegistry.EnumKey(HKLM, sBaseKey2, arSubKeys2)
For Each sKey2 In arSubKeys2
'now we are at the level of:
'HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\<VESA_Monitor_ID\<PNP_ID>\
'so we can check the "HardwareID" value
oRegistry.GetMultiStringValue HKLM, sBaseKey2 & sKey2 & "\", "HardwareID", sValue
for tmpctr=0 to ubound(svalue)
If lcase(left(svalue(tmpctr),8))="monitor\" then
'If it is a monitor we will check for the existance of a control subkey
'that way we know it is an active monitor
sBaseKey3 = sBaseKey2 & sKey2 & "\"
iRC3 = oRegistry.EnumKey(HKLM, sBaseKey3, arSubKeys3)
For Each sKey3 In arSubKeys3
'Kaplan edit
strRawEDID = ""
If skey3="Control" Then
'If the Control sub-key exists then we should read the edid info
oRegistry.GetBinaryValue HKLM, sbasekey3 & "Device Parameters\", "EDID", arrintEDID
If vartype(arrintedid) <> 8204 then 'and If we don't find it...
strRawEDID="EDID Not Available" 'store an "unavailable message
else
for each bytevalue in arrintedid 'otherwise conver the byte array from the registry into a string (for easier processing later)
strRawEDID=strRawEDID & chr(bytevalue)
Next
End If
'now take the string and store it in an array, that way we can support multiple monitors
redim preserve strarrRawEDID(intMonitorCount)
strarrRawEDID(intMonitorCount)=strRawEDID
intMonitorCount=intMonitorCount+1
End If
Next
End If
Next
Next
Next
'*****************************************************************************************
'now the EDID info for each active monitor is stored in an array of strings called strarrRawEDID
'so we can process it to get the good stuff out of it which we will store in a 5 dimensional array
'called arrMonitorInfo, the dimensions are as follows:
'0=VESA Mfg ID, 1=VESA Device ID, 2=MFG Date (M/YYYY),3=Serial Num (If available),4=Model Descriptor
'5=EDID Version
'*****************************************************************************************
On Error Resume Next
dim arrMonitorInfo()
redim arrMonitorInfo(intMonitorCount-1,5)
dim location(3)
for tmpctr=0 to intMonitorCount-1
If strarrRawEDID(tmpctr) <> "EDID Not Available" then
'*********************************************************************
'first get the model and serial numbers from the vesa descriptor
'blocks in the edid. the model number is required to be present
'according to the spec. (v1.2 and beyond)but serial number is not
'required. There are 4 descriptor blocks in edid at offset locations
'&H36 &H48 &H5a and &H6c each block is 18 bytes long
'*********************************************************************
location(0)=mid(strarrRawEDID(tmpctr),&H36+1,18)
location(1)=mid(strarrRawEDID(tmpctr),&H48+1,18)
location(2)=mid(strarrRawEDID(tmpctr),&H5a+1,18)
location(3)=mid(strarrRawEDID(tmpctr),&H6c+1,18)


'you can tell If the location contains a serial number If it starts with &H00 00 00 ff
strSerFind=chr(&H00) & chr(&H00) & chr(&H00) & chr(&Hff)
'or a model description If it starts with &H00 00 00 fc
strMdlFind=chr(&H00) & chr(&H00) & chr(&H00) & chr(&Hfc)


intSerFoundAt=-1
intMdlFoundAt=-1
for findit = 0 to 3
If instr(location(findit),strSerFind)>0 then
intSerFoundAt=findit
End If
If instr(location(findit),strMdlFind)>0 then
intMdlFoundAt=findit
End If
Next


'If a location containing a serial number block was found then store it
If intSerFoundAt<>-1 then
tmp=right(location(intSerFoundAt),14)
If instr(tmp,chr(&H0a))>0 then
tmpser=trim(left(tmp,instr(tmp,chr(&H0a))-1))
Else
tmpser=trim(tmp)
End If
'although it is not part of the edid spec it seems as though the
'serial number will frequently be preceeded by &H00, this
'compensates for that
If left(tmpser,1)=chr(0) then tmpser=right(tmpser,len(tmpser)-1)
else
tmpser="Not Found"
End If


'If a location containing a model number block was found then store it
If intMdlFoundAt<>-1 then
tmp=right(location(intMdlFoundAt),14)
If instr(tmp,chr(&H0a))>0 then
tmpmdl=trim(left(tmp,instr(tmp,chr(&H0a))-1))
else
tmpmdl=trim(tmp)
End If
'although it is not part of the edid spec it seems as though the
'serial number will frequently be preceeded by &H00, this
'compensates for that
If left(tmpmdl,1)=chr(0) then tmpmdl=right(tmpmdl,len(tmpmdl)-1)
else
tmpmdl="Not Found"
End If


'**************************************************************
'Next get the mfg date
'**************************************************************
Dim tmpmfgweek,tmpmfgyear,tmpmdt
'the week of manufacture is stored at EDID offset &H10
tmpmfgweek=asc(mid(strarrRawEDID(tmpctr),&H10+1,1))


'the year of manufacture is stored at EDID offset &H11
'and is the current year -1990
tmpmfgyear=(asc(mid(strarrRawEDID(tmpctr),&H11+1,1)))+1990


'store it in month/year format
tmpmdt=month(dateadd("ww",tmpmfgweek,datevalue("1/1/" & tmpmfgyear))) & "/" & tmpmfgyear


'**************************************************************
'Next get the edid version
'**************************************************************
'the version is at EDID offset &H12
Dim tmpEDIDMajorVer, tmpEDIDRev, tmpVer
tmpEDIDMajorVer=asc(mid(strarrRawEDID(tmpctr),&H12+1,1))


'the revision level is at EDID offset &H13
tmpEDIDRev=asc(mid(strarrRawEDID(tmpctr),&H13+1,1))


'store it in month/year format
tmpver=chr(48+tmpEDIDMajorVer) & "." & chr(48+tmpEDIDRev)


'**************************************************************
'Next get the mfg id
'**************************************************************
'the mfg id is 2 bytes starting at EDID offset &H08
'the id is three characters long. using 5 bits to represent
'each character. the bits are used so that 1=A 2=B etc..
'
'get the data
Dim tmpEDIDMfg, tmpMfg
dim Char1, Char2, Char3
Dim Byte1, Byte2
tmpEDIDMfg=mid(strarrRawEDID(tmpctr),&H08+1,2)
Char1=0 : Char2=0 : Char3=0
Byte1=asc(left(tmpEDIDMfg,1)) 'get the first half of the string
Byte2=asc(right(tmpEDIDMfg,1)) 'get the first half of the string
'now shift the bits
'shift the 64 bit to the 16 bit
If (Byte1 and 64) > 0 then Char1=Char1+16
'shift the 32 bit to the 8 bit
If (Byte1 and 32) > 0 then Char1=Char1+8
'etc....
If (Byte1 and 16) > 0 then Char1=Char1+4
If (Byte1 and 8) > 0 then Char1=Char1+2
If (Byte1 and 4) > 0 then Char1=Char1+1


'the 2nd character uses the 2 bit and the 1 bit of the 1st byte
If (Byte1 and 2) > 0 then Char2=Char2+16
If (Byte1 and 1) > 0 then Char2=Char2+8
'and the 128,64 and 32 bits of the 2nd byte
If (Byte2 and 128) > 0 then Char2=Char2+4
If (Byte2 and 64) > 0 then Char2=Char2+2
If (Byte2 and 32) > 0 then Char2=Char2+1


'the bits for the 3rd character don't need shifting
'we can use them as they are
Char3=Char3+(Byte2 and 16)
Char3=Char3+(Byte2 and 8)
Char3=Char3+(Byte2 and 4)
Char3=Char3+(Byte2 and 2)
Char3=Char3+(Byte2 and 1)
tmpmfg=chr(Char1+64) & chr(Char2+64) & chr(Char3+64)


'**************************************************************
'Next get the device id
'**************************************************************
'the device id is 2bytes starting at EDID offset &H0a
'the bytes are in reverse order.
'this code is not text. it is just a 2 byte code assigned
'by the manufacturer. they should be unique to a model
Dim tmpEDIDDev1, tmpEDIDDev2, tmpDev


tmpEDIDDev1=hex(asc(mid(strarrRawEDID(tmpctr),&H0a+1,1)))
tmpEDIDDev2=hex(asc(mid(strarrRawEDID(tmpctr),&H0b+1,1)))
If len(tmpEDIDDev1)=1 then tmpEDIDDev1="0" & tmpEDIDDev1
If len(tmpEDIDDev2)=1 then tmpEDIDDev2="0" & tmpEDIDDev2
tmpdev=tmpEDIDDev2 & tmpEDIDDev1


'**************************************************************
'finally store all the values into the array
'**************************************************************
'Kaplan adds code to avoid duplication...


If Not InArray(tmpser,arrMonitorInfo,3) Then
arrMonitorInfo(tmpctr,0)=tmpmfg
arrMonitorInfo(tmpctr,1)=tmpdev
arrMonitorInfo(tmpctr,2)=tmpmdt
arrMonitorInfo(tmpctr,3)=tmpser
arrMonitorInfo(tmpctr,4)=tmpmdl
arrMonitorInfo(tmpctr,5)=tmpVer
End If
End If
Next


'For now just a simple screen print will suffice for output.
'But you could take this output and write it to a database or a file
'and in that way use it for asset management.
i = 0
for tmpctr = 0 to intMonitorCount-1
If arrMonitorInfo(tmpctr,1) <> "" And arrMonitorInfo(tmpctr,0) <> "PNP" Then
If batch Then
EchoAndLog strComputer & "," & arrMonitorInfo(tmpctr,4) & "," & _
arrMonitorInfo(tmpctr,3)& "," & arrMonitorInfo(tmpctr,0) & "," & _
arrMonitorInfo(tmpctr,2)
Else
message = message & "Monitor " & chr(i+65) & ")" & VbCrLf & _
"Model Name: " & arrMonitorInfo(tmpctr,4) & VbCrLf & _
"Serial Number: " & arrMonitorInfo(tmpctr,3)& VbCrLf & _
"VESA Manufacturer ID: " & arrMonitorInfo(tmpctr,0) & VbCrLf & _
"Manufacture Date: " & arrMonitorInfo(tmpctr,2) & VbCrLf & VbCrLf
'wscript.echo ".........." & "Device ID: " & arrMonitorInfo(tmpctr,1)
'wscript.echo ".........." & "EDID Version: " & arrMonitorInfo(tmpctr,5)
i = i + 1
End If
End If
Next


If not batch Then
MsgBox message, vbInformation + vbOKOnly,strComputer & " Monitor Info"
End If


Function InArray(strValue,List,Col)
Dim i
For i = 0 to UBound(List)
If List(i,col) = cstr(strValue) Then
InArray = True
Exit Function
End If
Next
InArray = False
End Function


Sub EchoAndLog (message)
'Echo output and write to log
Wscript.Echo message
AppendOut.WriteLine message
End Sub