I'm looking for a simple vb script that I can place on our W2K domain
controller that will capture the following from each end station during
logon and write the output to a text file:

<sample>
Computer Name: 0D1C41673BB
Type: X86-based PC
Manufacturer: Dell Inc.
Model: OptiPlex GX620
Serial Number: HLW1K91
User Name: domain\username
</sample>

Thanks in advance for any assistance!

Re: Capture logon info by jd71

jd71
Mon Oct 16 11:34:39 CDT 2006

Below is a quick script that will create a text file on your chosen
share. You users will have to be local admins. I would suggest that
you setup a SQL database (MySQL works great) to log to instead of text
files.

Ultimately, I would suggest gathering WMI information with a script
running against your AD and using a domain admin account. Then your
login script could gather username and compname info, without needing
to be local admins.

'************************************************************************
On Error Resume Next

'*** Declarations ***
Dim Shell,FSO,Network,dbConn,locarray

'*** Objects ***
Set Shell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objWMIinfo = GetObject("winmgmts:\\" & compname & "\root\cimv2")

'*** Environment strings ***
lserver = shell.expandenvironmentstrings ("%logonserver%")
compname = shell.expandenvironmentstrings("%computername%")
user = Shell.ExpandEnvironmentStrings("%username%")
filelocation = "\\yourserver\\yourshare$\" & compname & ".txt"

Set colItems = objWMIinfo.ExecQuery("Select * from Win32_BIOS",,48)
For Each objItem in colItems
sernum = objItem.SerialNumber
manu = objitem.Manufacturer
Next

Set colitems = objWMIinfo.ExecQuery("Select * from Win32_Processor")
For Each ObjItem in colItems
proctype = objitem.description
next

Set LogFile = FSO.CreateTextFile(filelocation & compname & ".txt")
Logfile.writeline("Logon Server: " & lserver & vbcrlf & "Computer Name:
" & compname & vbcrlf & "Processor Type: " & proctype & vbcrlf &
"Manufacturer: " & manu & vbcrlf & "Serial Number: " & sernum & vbcrlf
& "Username: " & user)
Logfile.close
'************************************************************************

p.s. Watch out for word wrapped lines, as I do not use the &_.

-Jd

On Oct 15, 7:47 pm, "MandG" <gsca...@gmail.com> wrote:
> I'm looking for a simple vb script that I can place on our W2K domain
> controller that will capture the following from each end station during
> logon and write the output to a text file:
>
> <sample>
> Computer Name: 0D1C41673BB
> Type: X86-based PC
> Manufacturer: Dell Inc.
> Model: OptiPlex GX620
> Serial Number: HLW1K91
> User Name: domain\username
> </sample>
>
> Thanks in advance for any assistance!


Re: Capture logon info by jd71

jd71
Mon Oct 16 15:03:06 CDT 2006

Oops,
I called the variable "compname" before I gave it a value...Below is
the correction:

On Error Resume Next

'*** Declarations ***
Dim Shell,FSO,Network,dbConn,locarray

'*** Objects ***
Set Shell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

'*** Environment strings ***
lserver = shell.expandenvironmentstrings ("%logonserver%")
compname = shell.expandenvironmentstrings("%computername%")
user = Shell.ExpandEnvironmentStrings("%username%")
filelocation = "\\yourserver\\yourshare$\" & compname & ".txt"
Set objWMIinfo = GetObject("winmgmts:\\" & compname & "\root\cimv2")

Set colItems = objWMIinfo.ExecQuery("Select * from Win32_BIOS",,48)
For Each objItem in colItems
sernum = objItem.SerialNumber
manu = objitem.Manufacturer
Next

Set colitems = objWMIinfo.ExecQuery("Select * from Win32_Processor")
For Each ObjItem in colItems
proctype = objitem.description
next

Set LogFile = FSO.CreateTextFile(filelocation & compname & ".txt")
Logfile.writeline("Logon Server: " & lserver & vbcrlf & "Computer Name:
" & compname & vbcrlf & "Processor Type: " & proctype & vbcrlf &
"Manufacturer: " & manu & vbcrlf & "Serial Number: " & sernum & vbcrlf
& "Username: " & user)
Logfile.close

-JD

On Oct 16, 12:34 pm, "jd71" <jdavi...@gmail.com> wrote:
> Below is a quick script that will create a text file on your chosen
> share. You users will have to be local admins. I would suggest that
> you setup a SQL database (MySQL works great) to log to instead of text
> files.
>
> Ultimately, I would suggest gathering WMI information with a script
> running against your AD and using a domain admin account. Then your
> login script could gather username and compname info, without needing
> to be local admins.
>
> '************************************************************************
> On Error Resume Next
>
> '*** Declarations ***
> Dim Shell,FSO,Network,dbConn,locarray
>
> '*** Objects ***
> Set Shell = WScript.CreateObject("WScript.Shell")
> Set FSO = CreateObject("Scripting.FileSystemObject")
> Set objWMIinfo = GetObject("winmgmts:\\" & compname & "\root\cimv2")
>
> '*** Environment strings ***
> lserver = shell.expandenvironmentstrings ("%logonserver%")
> compname = shell.expandenvironmentstrings("%computername%")
> user = Shell.ExpandEnvironmentStrings("%username%")
> filelocation = "\\yourserver\\yourshare$\" & compname & ".txt"
>
> Set colItems = objWMIinfo.ExecQuery("Select * from Win32_BIOS",,48)
> For Each objItem in colItems
> sernum = objItem.SerialNumber
> manu = objitem.Manufacturer
> Next
>
> Set colitems = objWMIinfo.ExecQuery("Select * from Win32_Processor")
> For Each ObjItem in colItems
> proctype = objitem.description
> next
>
> Set LogFile = FSO.CreateTextFile(filelocation & compname & ".txt")
> Logfile.writeline("Logon Server: " & lserver & vbcrlf & "Computer Name:
> " & compname & vbcrlf & "Processor Type: " & proctype & vbcrlf &
> "Manufacturer: " & manu & vbcrlf & "Serial Number: " & sernum & vbcrlf
> & "Username: " & user)
> Logfile.close
> '************************************************************************
>
> p.s. Watch out for word wrapped lines, as I do not use the &_.
>
> -Jd
>
> On Oct 15, 7:47 pm, "MandG" <gsca...@gmail.com> wrote:
>
>
>
> > I'm looking for a simple vb script that I can place on our W2K domain
> > controller that will capture the following from each end station during
> > logon and write the output to a text file:
>
> > <sample>
> > Computer Name: 0D1C41673BB
> > Type: X86-based PC
> > Manufacturer: Dell Inc.
> > Model: OptiPlex GX620
> > Serial Number: HLW1K91
> > User Name: domain\username
> > </sample>
>
> > Thanks in advance for any assistance!- Hide quoted text -- Show quoted text -


Re: Capture logon info by MandG

MandG
Tue Oct 17 21:55:53 CDT 2006

That is awesome - I am extremely grateful for this and for users like
yourself who take the time to share you knowledge and skills. I have
one small question however -

I would like to direct this output to a network share and simply name
it "serial.txt" and place it within the folder that's named after the
computer (in most cases this already exists). So, my command would look
like this:

call \\10.1.16.2\netlogon\thiscoolscript.vbs
->t:\accesslog\%computername%\serial.txt

So what (if any) changes would I have to make to your script so that my
command guides the output and not your script? I don't think I can
safely remove your "filelocation =" line.

And then of course I'd have to remove the part where your script names
the txt file after the compname (which is actually pretty cool - sorry
I'm easily impressed with you scripting wizards-)


Re: Capture logon info by jd71

jd71
Wed Oct 18 12:59:16 CDT 2006

I am not sure how to pipe the output to a text file from your call to
the vb script, but I have reworked the original. This script will now
create the text file "serial.txt" in the already created folder on the
share that is named for the computer (ex: \\yourserver\yourshare$\" &
compname & "\serial.txt").

'*******************************************************
On Error Resume Next

'*** Declarations ***
Dim Shell,FSO,Network,dbConn,locarray

'*** Objects ***
Set Shell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

'*** Environment strings ***
lserver = shell.expandenvironmentstrings ("%logonserver%")
compname = shell.expandenvironmentstrings("%computername%")
user = Shell.ExpandEnvironmentStrings("%username%")
filelocation = "\\yourserver\yourshare$\" & compname & "\serial.txt"
Set objWMIinfo = GetObject("winmgmts:\\" & compname & "\root\cimv2")

Set colItems = objWMIinfo.ExecQuery("Select * from Win32_BIOS",,48)
For Each objItem in colItems
sernum = objItem.SerialNumber
manu = objitem.Manufacturer
Next

Set colitems = objWMIinfo.ExecQuery("Select * from Win32_Processor")
For Each ObjItem in colItems
proctype = objitem.description
next

Set LogFile = FSO.CreateTextFile(filelocation)
Logfile.writeline("Logon Server: " & lserver & vbcrlf & "Computer Name:
" & compname & vbcrlf & "Processor Type: " & proctype & vbcrlf &
"Manufacturer: " & manu & vbcrlf & "Serial Number: " & sernum & vbcrlf
& "Username: " & user)
Logfile.close
'*******************************************************

You might also think about having all of your computers write to a
single csv file that you could easily import into Excel, Access, or
some other database. I have created a working example below. The
example has to Functions, you just need to choose which one suits your
needs. Choose either "Searchappend" or "Appendonly" and comment out
one and uncomment out the one you wish to use. I still highly
recommend using MySql (it is free after all!). Good Luck!!

'*******************************************************
On Error Resume Next

'*** Declarations ***
Dim Shell,FSO,Network,dbConn,locarray
Const ForAppending = 8
Const ForReading = 1

'*** Objects ***
Set Shell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

'*** Environment strings ***
lserver = shell.expandenvironmentstrings ("%logonserver%")
compname = shell.expandenvironmentstrings("%computername%")
user = Shell.ExpandEnvironmentStrings("%username%")
filelocation = "\\yourserver\yourshare$\serials.txt"
Set objWMIinfo = GetObject("winmgmts:\\" & compname & "\root\cimv2")

Set colItems = objWMIinfo.ExecQuery("Select * from Win32_BIOS",,48)
For Each objItem in colItems
sernum = objItem.SerialNumber
manu = objitem.Manufacturer
Next

Set colitems = objWMIinfo.ExecQuery("Select * from Win32_Processor")
For Each ObjItem in colItems
proctype = objitem.description
next

'searchappend
appendonly

Function searchappend()
'*** If the computer's name is found in the text file, do not append
'*** Caution: If you have a high volume logins, this function will be
'*** very slow as it has to open the text file and read each line for
each login
if FSO.FileExists(filelocation & ".txt") then
Set LogFile = FSO.OpenTextFile(filelocation, ForReading, True)
Do While LogFile.AtEndOfStream <> True
If inStr(LogFile.Readline, compname) then
LogFile.close
wscript.quit
end if
loop
LogFile.close
Set LogFile = FSO.OpenTextFile(filelocation, ForAppending, True)
Logfile.writeline(lserver & "," & compname & "," & proctype &
"," & manu & "," & sernum & "," & user)

else
Set LogFile = FSO.CreateTextFile(filelocation)
Logfile.writeline(lserver & "," & compname & "," & proctype &
"," & manu & "," & sernum & "," & user)
end if
End Function

Function appendonly()
'*** Appends the text file only. Much more efficient, but you will
have duplicates.
if FSO.FileExists(filelocation) then
Set LogFile = FSO.OpenTextFile(filelocation, ForAppending, True)
Logfile.writeline(lserver & "," & compname & "," & proctype & ","
& manu & "," & sernum & "," & user)
else
Set LogFile = FSO.CreateTextFile(filelocation)
Logfile.writeline(lserver & "," & compname & "," & proctype & ","
& manu & "," & sernum & "," & user)
end if
End Function

Logfile.close
wscript.quit
'*******************************************************



-Jason


On Oct 17, 10:55 pm, "MandG" <gsca...@gmail.com> wrote:
> That is awesome - I am extremely grateful for this and for users like
> yourself who take the time to share you knowledge and skills. I have
> one small question however -
>
> I would like to direct this output to a network share and simply name
> it "serial.txt" and place it within the folder that's named after the
> computer (in most cases this already exists). So, my command would look
> like this:
>
> call \\10.1.16.2\netlogon\thiscoolscript.vbs
> ->t:\accesslog\%computername%\serial.txt
>
> So what (if any) changes would I have to make to your script so that my
> command guides the output and not your script? I don't think I can
> safely remove your "filelocation =" line.
>
> And then of course I'd have to remove the part where your script names
> the txt file after the compname (which is actually pretty cool - sorry
> I'm easily impressed with you scripting wizards-)


Re: Capture logon info by MandG

MandG
Wed Oct 18 23:21:09 CDT 2006

This is awesome Jason- I got it working fine.

I used the 1st of your 2 scripts and only have one last (hopefully
simple) request- is there a way to capture model as well? That would be
great to have model info write beneath the manufacturer.

If you can get this - my goal will be complete - then you'll just to
tell me how to pay you :-)

Seriously, I really appreciate all your help with this.


Re: Capture logon info by jd71

jd71
Thu Oct 19 07:18:47 CDT 2006

That is easily added on. Try this:

'Add this section to set the model variable:

Set ColItems = objWMIinfo.ExecQuery("Select * from
Win32_ComputerSystem")
For Each ObjItem in ColItems
model = ObjItem.model
next


'Then replace the "LogFile.writeline" section with this:

Logfile.writeline("Logon Server: " & lserver & vbcrlf & "Computer Name:
" & compname & vbcrlf & "Processor Type: " & proctype & vbcrlf &
"Manufacturer: " & manu & vbcrlf & "Model: " & model & vbcrlf & "Serial
Number: " & sernum & vbcrlf & "Username: " & user)


BTW, If all of your machines are 2k and up, you could transition your
login batch files to VBScript and have better control and more options
available for automation (IMHO). A good place to start is Microsoft's
Script Center examples:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&familyid=b4cb2678-dafb-4e30-b2da-b8814fe2da5a

-Jason


On Oct 19, 12:21 am, "MandG" <gsca...@gmail.com> wrote:
> This is awesome Jason- I got it working fine.
>
> I used the 1st of your 2 scripts and only have one last (hopefully
> simple) request- is there a way to capture model as well? That would be
> great to have model info write beneath the manufacturer.
>
> If you can get this - my goal will be complete - then you'll just to
> tell me how to pay you :-)
>
> Seriously, I really appreciate all your help with this.