+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 28
Scripts Thread, BGInfo: Dispaying Text: Custom Query in Coding and Web Development; Hi. I am using BGInfo to diplay details about my users. When Students logon I currently have: Username, Station Name, ...
  1. #1

    DaveP's Avatar
    Join Date
    Oct 2006
    Location
    Can't talk now: The mother-ship is calling!
    Posts
    9,381
    Thank Post
    354
    Thanked 1,350 Times in 928 Posts
    Blog Entries
    4
    Rep Power
    1203

    BGInfo: Dispaying Text: Custom Query

    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.

  2. #2

    Join Date
    Jul 2009
    Posts
    2
    Thank Post
    1
    Thanked 1 Time in 1 Post
    Rep Power
    0
    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.

    Code:
    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.

  3. Thanks to shidojin from:

    DaveP (4th June 2010)

  4. #3

    DaveP's Avatar
    Join Date
    Oct 2006
    Location
    Can't talk now: The mother-ship is calling!
    Posts
    9,381
    Thank Post
    354
    Thanked 1,350 Times in 928 Posts
    Blog Entries
    4
    Rep Power
    1203
    Thank you.

    I will give that a go on Monday.

  5. #4

    DaveP's Avatar
    Join Date
    Oct 2006
    Location
    Can't talk now: The mother-ship is calling!
    Posts
    9,381
    Thank Post
    354
    Thanked 1,350 Times in 928 Posts
    Blog Entries
    4
    Rep Power
    1203
    Quote Originally Posted by shidojin View Post
    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.

    Code:
    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.

  6. #5

    Join Date
    Jul 2009
    Posts
    2
    Thank Post
    1
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Good to hear, may try it myself eventually, might be useful.

  7. #6

    DaveP's Avatar
    Join Date
    Oct 2006
    Location
    Can't talk now: The mother-ship is calling!
    Posts
    9,381
    Thank Post
    354
    Thanked 1,350 Times in 928 Posts
    Blog Entries
    4
    Rep Power
    1203
    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.

  8. #7
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,007
    Thank Post
    124
    Thanked 286 Times in 263 Posts
    Rep Power
    109
    Try some of the tools here:
    http://www.wisesoft.co.uk/software/b...s/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

    Code:
    objUser.put "DisplayName", strFullName
    objUser.SetInfo

  9. Thanks to ChrisH from:

    DaveP (22nd June 2010)

  10. #8

    DaveP's Avatar
    Join Date
    Oct 2006
    Location
    Can't talk now: The mother-ship is calling!
    Posts
    9,381
    Thank Post
    354
    Thanked 1,350 Times in 928 Posts
    Blog Entries
    4
    Rep Power
    1203
    Quote Originally Posted by ChrisH View Post
    Try some of the tools here:
    http://www.wisesoft.co.uk/software/b...s/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

    Code:
    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.

  11. #9
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,007
    Thank Post
    124
    Thanked 286 Times in 263 Posts
    Rep Power
    109
    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.

  12. #10

    DaveP's Avatar
    Join Date
    Oct 2006
    Location
    Can't talk now: The mother-ship is calling!
    Posts
    9,381
    Thank Post
    354
    Thanked 1,350 Times in 928 Posts
    Blog Entries
    4
    Rep Power
    1203

    Resolved?

    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:

    Code:
    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
    Last edited by DaveP; 17th June 2010 at 09:07 AM. Reason: Add detail to the post. May be resolved?

  13. #11

    DaveP's Avatar
    Join Date
    Oct 2006
    Location
    Can't talk now: The mother-ship is calling!
    Posts
    9,381
    Thank Post
    354
    Thanked 1,350 Times in 928 Posts
    Blog Entries
    4
    Rep Power
    1203
    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:

    Code:
    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:

    Code:
    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:

    Code:
    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.

  14. #12

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    116
    Line 24: "Echo strIPAddresses"

    Echo is DOS! You need WScript.Echo

  15. Thanks to PiqueABoo from:

    DaveP (22nd June 2010)

  16. #13

    DaveP's Avatar
    Join Date
    Oct 2006
    Location
    Can't talk now: The mother-ship is calling!
    Posts
    9,381
    Thank Post
    354
    Thanked 1,350 Times in 928 Posts
    Blog Entries
    4
    Rep Power
    1203
    Quote Originally Posted by PiqueABoo View Post
    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]

    Code:
    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.

  17. #14
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,007
    Thank Post
    124
    Thanked 286 Times in 263 Posts
    Rep Power
    109
    You would need to set the permissions on a file using a start up script or via a GPO.

  18. #15

    DaveP's Avatar
    Join Date
    Oct 2006
    Location
    Can't talk now: The mother-ship is calling!
    Posts
    9,381
    Thank Post
    354
    Thanked 1,350 Times in 928 Posts
    Blog Entries
    4
    Rep Power
    1203
    Quote Originally Posted by ChrisH View Post
    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.
    Last edited by DaveP; 22nd June 2010 at 11:51 AM.



SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Convert Text On Image Into Editable Text
    By DaveP in forum General Chat
    Replies: 4
    Last Post: 30th May 2013, 10:10 AM
  2. Replies: 0
    Last Post: 10th January 2010, 08:05 AM
  3. BGInfo
    By OllieC in forum Windows
    Replies: 1
    Last Post: 17th August 2009, 06:10 PM
  4. SQL Query Using Full Text Engine inSQL 2005
    By Phanikumar in forum Web Development
    Replies: 0
    Last Post: 22nd September 2008, 09:47 AM
  5. Query of existing query data in PHP
    By markwilliamson2001 in forum Web Development
    Replies: 5
    Last Post: 5th October 2007, 09:43 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •