Jump to content

Recommended Posts

Posted

Hi.

 

I am using BGInfo to diplay details about my users. When Students logon I currently have:

 

Username, Station Name, IP Address, Logon Time and Screen Resolution [i have required some or all of these values at least once in the past so now I have them in view all of the time]

 

I have now been asked to display the full name of the Student users [i suppose so that Supply Staff can differentiate James from John when 08SmithJ and 08SmithJT are both logged on in the same computer room]

 

I have this script:

 

Set objSysInfo = CreateObject("ADSystemInfo")

strUser = objSysInfo.UserName

Set objUser = GetObject("LDAP://" & strUser)

strFullName = objUser.Get("displayName")

MsgBox strFullName

 

which will echo the full name as a string to the screen so I know it works [got it from Edugeek]

 

What I would like it to do now is write the string to a text file [with a nominated file file name in a nominated place: eg: %TEMP%\UserFullName.TXT] so that BGInfo can pick it up and display it along with all of the other information already on screen.

 

Can anyone help with this? I am not very good with coding [as you might have guessed: I just adapt what I see elsewhere but I can't seem to make this work]

 

Thanks.

Posted

Just did a quick Google on doing this and from what I can tell creating a custom WMI query in BGInfo with the following as the path will do what you want.

 

SELECT FullName FROM Win32_NetworkLoginProfile WHERE FullName is not  NULL

Someone on the SysInternals forum had a problem with it displaying the names of previously logged on users as well but the issue seemed to be isolated to that person. I've tested it on my home laptop and it seems to work ok, couldn't test it on a domain as I'm not at work.

Posted
Just did a quick Google on doing this and from what I can tell creating a custom WMI query in BGInfo with the following as the path will do what you want.

 

SELECT FullName FROM Win32_NetworkLoginProfile WHERE FullName is not  NULL

Someone on the SysInternals forum had a problem with it displaying the names of previously logged on users as well but the issue seemed to be isolated to that person. I've tested it on my home laptop and it seems to work ok, couldn't test it on a domain as I'm not at work.

 

To follow up I have just tried it and it works a treat!

 

Thanks again.

Posted

Now I have BGInfo working I would like to mop up the users where it does not currently work.

 

This is where there is no entry in Active Directory for the user in the 'Display Name' field.

 

I have this script:

 

Set objSysInfo = CreateObject("ADSystemInfo")

strUser = objSysInfo.UserName

Set objUser = GetObject("LDAP://" & strUser)

strFullName = objUser.Get("displayName")

MsgBox strFullName

 

which works for all of my users. Is there a way of adapting this so that it takes the string found:

 

strFullName

 

and stuffs it into the 'Display Name' field for that user, replacing whatever might already be there in the process [The users' full name, white spaces, nothing (blank)]

 

I would do this by hand but I have searched Active Directory and found tht there are more than 1000 student users falling into this category.

 

Many thanks.

Posted
Try some of the tools here:

http://www.wisesoft.co.uk/software/bulkadusers/default.aspx

 

These may do what you want else the VB script to do what you want is fairly easy and would only involve about 3 lines extra to what you have got.

 

Off the top of my head the code is things like

 

objUser.put "DisplayName", strFullName
objUser.SetInfo

 

I have tried the suggested website and I cannot access it. Also I have been thinking about the script. It occurred to me that the adapted script would only work to add 'administrator' into the 'Display Name' field for the administrator. Can anyone suggest the syntax I would need to use in a VBS script to apply the change to all users where the username starts with 0 [zero] as all of my student users start with a leading zero at the moment.

 

Many thanks.

Posted

You need to iterate through the users using some kind of loop and then if left(strName) = "0" then objUser.put "DisplayName", strFullName

objUser.SetInfo

 

.

 

Something like that I would have the loop start in an OU you have defined. You could cobble this code together with the help of google and cut and paste.

Posted (edited)

Ok. Now all of my students have their full name in the 'Display Name' field in Active Directory.

 

What I am seeing now is that some users have two names displayed beside Full Name on the desktop.

 

For example if David Cameron [A Year 7 pupil] BGInfo might display

 

09CameronD

09BrownG

 

for his username on the desktop. I have checked Active Directory and for the affected users [those users' desktops I have been able to observe and who show this issue] they have their own Display Name information and no other.

 

Is this the same issue as:

 

Someone on the SysInternals forum had a problem with it displaying the names of previously logged on users as well but the issue seemed to be isolated to that person.

 

Does anyone else use BGInfo in this way or can anyone shed any light on why this might be happening?

 

Thanks.

 

Edit: I have made a change to the query. It is now:

 

SELECT FullName FROM Win32_NetworkLoginProfile WHERE LastLogon=(select max(LastLogon) FROM Win32_NetworkLoginProfile)

 

 

This seems to be working. Time will tell though...

 

URL: BgInfo: Display Name

Edited by 6Foot2
Add detail to the post. May be resolved?
Posted

Sorry to revisit this topic again but now I would like to eliminate the displayed IP address 0.0.0.0 where a station has tow network cards and one is disconnected or where a laptop has not yet been logged on by a member of staff. I have tried a logon script:

 

setlocal
for /f "delims=: tokens=1-2" %%c in ('ipconfig /all ^| find "Ip-address"') do set GetIP=%%d
endlocal & set GetIP=%GetIP:~1%
echo %GetIP% > "%TEMP%\ip.txt"

 

[and a companion setting in BGINFO.BGI to get the contents of ip.txt]

 

however the script does not work. It just echoes '~1' to ip.txt.

 

I have also tried:

 

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True",,48)

strIPAddresses = ""

For Each objItem In colItems
   For Each address In objItem.IPAddress
       blnValidIP = (InStr (address, ".") > 0) _
               And (InStr (objItem.Caption, "VMware Virtual") = 0) _
               And address <> "0.0.0.0"
       If blnValidIP Then
           strIPAddresses = strIPAddresses & address & "|"
       End If
   Next
Next

If Len (strIPAddresses) > 0 Then
   strIPAddresses = Left (strIPAddresses,Len(strIPAddresses)-1)
   strIPAddresses = Replace (strIPAddresses, "|", ", ")
Else
   strIPAddresses = "(disconnected)"
End If

Echo strIPAddresses

 

That gives an error part way through the file [line 24 I think]

 

I have also tried telling BGINFO only to display IPs from network cards if they are enabled [connected to a network] I can't remember what I put in for that but it was something like:

 

SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True

 

but BGINFO displays an error like this:

 

Query not in from 'SELECT xxx FROM...'

 

Does anyone know how I can get rid of these 'dead' IPs from my desktops?

 

Thanks.

Posted
Line 24: "Echo strIPAddresses"

 

Echo is DOS! You need WScript.Echo

 

Thanks for that. I was able to use this to confirm that the script was working [eventually]

 

However now what I am finding is that the IP address is written two or more times to the screen [actually to a text file: Code shown below]

 

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True",,48)

strIPAddresses = ""

For Each objItem In colItems
   For Each address In objItem.IPAddress
       blnValidIP = (InStr (address, ".") > 0) _
               And (InStr (objItem.Caption, "VMware Virtual") = 0) _
               And address <> "0.0.0.0"
       If blnValidIP Then
           strIPAddresses = strIPAddresses & address & "|"
       End If
   Next
Next

If Len (strIPAddresses) > 0 Then
   strIPAddresses = Left (strIPAddresses,Len(strIPAddresses)-1)
   strIPAddresses = Replace (strIPAddresses, "|", ", ")
Else
   strIPAddresses = "(disconnected)"
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Windows\TEMP\IP.TXT", 2, 1)
objFile.Write(strIPAddresses)
objFile.Close

 

Looking at the contents of IP.TXT it typically shows:

 

192.168.3.200,192.168.3.200

 

or

 

192.168.3.200,192.168.3.200,192.168.3.200

 

etc.

 

Or what ever the station IP happens to be even if there is ONE network card in the computer.

 

Is the problem in my code?

 

Also my Students cannot display the contents of the file IP.TXT. Changing the permissions on IP.TXT manually and logging a Students on shows the contents. Is there a way of including a CACLs command to add NTFS read permissions for All Students to IP.TXT [and also preserve the existing permissions?

 

Thanks.

Posted (edited)
You would need to set the permissions on a file using a start up script or via a GPO.

 

I have tried Group Policy and for whatever reason it does not apply. I am going back to check the settings...

 

Edit: Group Policy permissions corrected.

 

Now just the 'Ghost' multiple IPs to go.

Edited by 6Foot2
Posted (edited)

It would appear that, for some of the stations here, duplicated IP Addresses are being introduced by the 1394 Net Adapter [Firewire Card]

 

I would like to find a way of disabling this via Group Policy/Group Policy Preferences as we do not use Firewire here.

 

Has anyone successfully done this?

 

Or perhaps I could adjust the script:

 

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True",,48)

strIPAddresses = ""

For Each objItem In colItems
   For Each address In objItem.IPAddress
       blnValidIP = (InStr (address, ".") > 0) _
               And (InStr (objItem.Caption, "VMware Virtual") = 0) _
               And address <> "0.0.0.0"
       If blnValidIP Then
           strIPAddresses = strIPAddresses & address & "|"
       End If
   Next
Next

If Len (strIPAddresses) > 0 Then
   strIPAddresses = Left (strIPAddresses,Len(strIPAddresses)-1)
   strIPAddresses = Replace (strIPAddresses, "|", ", ")
Else
   strIPAddresses = "(disconnected)"
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Windows\TEMP\IP.TXT", 2, 1)
objFile.Write(strIPAddresses)
objFile.Close

 

 

to omit the installed Firewire card?

 

Many thanks.

Edited by 6Foot2
  • 2 weeks later...
Posted

Just for reference,

 

Here's the script I use to display the user's full name via BGInfo (save as a .vbs file and add as a custom field):

 

' ======================================
On Error Resume Next
Dim colWMI, objItem, colQuery, strUserID, strName
Set colWMI = GetObject("WinMgmts:root/cimv2")
Set colQuery = colWMI.ExecQuery("Select UserName FROM Win32_ComputerSystem")

For Each objItem In colQuery
   strUserID = UCase(objItem.UserName)
   strName = Split(strUserID, "\")
   If strName(0) = strName(1) Then
strUserID = strName(1) & "\" & strName(2)
   End If
Next

Set colQuery = colWMI.ExecQuery("Select * FROM Win32_NetworkLoginProfile")

For Each objItem In colQuery
   If UCase(objItem.Name) = strUserID Then
       Echo objItem.Fullname
   End If
Next
' ======================================

 

This gets round the multiple user names on screen issue, and also displays the name correctly in situations where users log in as domain\username rather than username@domain.

 

Your solution looks more elegant, I may give it some testing :-)

 

Chad

  • 4 weeks later...
Posted

Hi Dave

 

Did you manage to get a script working that would only display the IP addresses in BGInfo when the connection had an address. Weve got the same problem you had where multiple IPs with "None" are coming up ie when a second NIC is disconnected but cant get a script working that would omit these when needed?

 

Thanks

Paul

Posted
Hi Dave

 

Did you manage to get a script working that would only display the IP addresses in BGInfo when the connection had an address. Weve got the same problem you had where multiple IPs with "None" are coming up ie when a second NIC is disconnected but cant get a script working that would omit these when needed?

 

Thanks

Paul

 

Hi Paul,

 

Have a look at this thread:

 

Link: http://www.edugeek.net/forums/how-do-you-do/59463-select-single-paragraph-text-file-random.html

 

Starting at this post:

 

Link: http://www.edugeek.net/forums/how-do-you-do/59463-select-single-paragraph-text-file-random.html#post540869

 

With the able assistance of Edugeek member LosOjos I was able to get something I am much more happy with. Occasionally is does not display properly but that is probably down to our network rather than the solution.

 

You will need to deploy the appropriate version of the .Net framework.

 

This was very easy to set up once I got my head around it.

 

Let me [or LosOjos?] know if you still have problems.

 

Dave.

Posted

Hi Dave

 

Thanks for the info, have thread through the thread. Just a little confused as to how it all ties intogether to be used by BGInfo. I have had a go playing around with the custom fields with no joy to date. Is it possible to have a look at the scripts you are running on the custom BGInfo field removing redundant IPs then I can hopefully mod them to work at the school!

Posted (edited)
Hi Dave

 

Thanks for the info, have thread through the thread. Just a little confused as to how it all ties intogether to be used by BGInfo...

 

I have had a quick look at the other post and at Group Policy/Active Directory. Unfortunately I am in a bit of a hurry this evening and I can't find what I want in a timely fashion. I will have a look again tomorrow.

Edited by 6Foot2
Correct spelling mistake.
Posted

I think I need to reconstruct how I got to the solution I do now.

 

The steps:

 

1. use BGInfo's own IP query. [select 'IP Address' from fields available on the right of BGInfo selection box (see below)]

 

http://gyazo.com/9d747ea4efd4c52680548af72cb2e95a.png

 

I found that some workstations and all laptops [with wireless enabled] reported multiple IP addresses with the addresses reported on screen one below the other. e.g.:

 

192.168.1.200

0.0.0.0

 

I did some work and started using a script:

 

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True",,48)

strIPAddresses = ""

For Each objItem In colItems
   For Each address In objItem.IPAddress
       blnValidIP = (InStr (address, ".") > 0) _
               And (InStr (objItem.Caption, "VMware Virtual") = 0) _
               And address <> "0.0.0.0"
       If blnValidIP Then
           strIPAddresses = strIPAddresses & address & "|"
       End If
   Next
Next

If Len (strIPAddresses) > 0 Then
   strIPAddresses = Left (strIPAddresses,Len(strIPAddresses)-1)
   strIPAddresses = Replace (strIPAddresses, "|", ", ")
Else
   strIPAddresses = "(disconnected)"
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Windows\TEMP\IP.TXT", 2, 1)
objFile.Write(strIPAddresses)
objFile.Close

 

but what this script would do is report the IP address in multiples [this time on a single line: 192.168.3.200,192.168.3.200]

 

I had an idea that I could use a utility that Edugeek member LosOjos helped me to get working on another thread: Link: http://www.edugeek.net/forums/how-do-you-do/59463-select-single-paragraph-text-file-random.html#post540869

 

What GetLine does [in this instance] is looks at IP.TXT, as created above, and only takes the left-most characters before the comma that separates them so you end up with:

 

192.168.3.200

 

or whatever your station IP happens to be.

 

It works but I am sure that there is probably a neater way of doing it.

 

I think that if you want to deploy this solution and you are having problems follow the steps that led me to what I have in place.

 

Get your duplicate IP addresses displayed by querying IP.TXT using BGInfo [Confirms that IP.TXT exists and that the script to create it is working]

 

Get your single IP address displayed using GetLine.exe to query IP.TXT to create RealIP.TXT and then use BGInfo to query the contents of RealIP.TXT and display that.

 

I hope this is helpful [i am not good at explaining stuff!]

 

If you still have problems feel free to get in touch again.

  • Thanks 1
Posted

Hi Dave

 

Thanks, just tested it all and it works perfectly.

 

The only issue I have come across is on machines where there are not multiple IPs, the text in IP.txt will be something like 192.168.1.1. Then when you run getline on this it falls over and comes up with the message "This is not a comma/tab seperated file" and outputs nothing to RealIP.txt if this makes sense!

 

Perhaps I could see if LosOjos can edit Getline so that if the original input file only contains one IP it just passes this output to RealIP.txt and if it contains more than one it continues to run the code removing redundant ones?

Posted
Hi Dave

 

Thanks, just tested it all and it works perfectly.

 

The only issue I have come across is on machines where there are not multiple IPs, the text in IP.txt will be something like 192.168.1.1. Then when you run getline on this it falls over and comes up with the message "This is not a comma/tab seperated file" and outputs nothing to RealIP.txt if this makes sense!

 

Perhaps I could see if LosOjos can edit Getline so that if the original input file only contains one IP it just passes this output to RealIP.txt and if it contains more than one it continues to run the code removing redundant ones?

 

@ba9ag,

 

I have just checked this thread and LosOjos has not posted in it [so he may not be aware of this conversation]

 

However I have this from another post:

 

Always feel free to request more features, I'm an old skool geek who enjoys a little programming to break up my day :typing:

 

Link to post: http://www.edugeek.net/forums/how-do-you-do/59463-select-single-paragraph-text-file-random.html#post541021

 

Sounds like he might like to hear of another challenge!

 

If you PM him I am sure that he would be willing to help? GetLine was recompiled/rewritten for me twice!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...