Admin center:Windows Scripting

From OCS Inventory NG
Jump to: navigation, search

Since the agent 4061, it's now possible to extend the inventory with .vbs scripts. The vbs script output on STDOUT is added in the final XML sent to the server.

The script need to be in a scripts directory in the current path. So if you run the agent as service it's probably:

c:\Program Files\scripts\example.vbs

To get the XML the agent generate for the server, just run:

C:\Users\admin\Documents>"c:\Program Files\OCS Inventory Agent\OCSInventory.exe" /xml /local


Last logged user

Function LastLoguedUser
    Set oShell = WScript.CreateObject("WScript.Shell")
    LastLoguedUser = " "
Set oOperatingSystems = GetObject("WinMgmts:").ExecQuery("SELECT Version FROM Win32_OperatingSystem")
    For Each oOS In oOperatingSystems
        oOSVersion = Split(oOS.Version, ".")(0) & "." & Split(oOS.Version, ".")(1)
        Select Case oOSVersion                                                                                                                                Case "4.0","5.0","5.1","5.2"
                LastLoguedUser = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName")
                Exit For
            Case "6.0","6.1","6.2"
                LastLogued = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser")
                LastLogued = Split(LastLogued,"\")
                LastLoguedUser = LastLogued(1)
                Exit For
            Case Else
                LastLoguedUser = "OPERATING SYSTEM NON PRIS EN CHARGE"
                Exit For
        End Select
    Set oShell = Nothing
    LastLoguedUser = Trim(Ucase(LastLoguedUser))
End Function

' Print the output for OCS Agent
Wscript.Echo "<HARDWARE>"
Wscript.Echo "<LASTLOGGEDUSER>" & LastLoguedUser & "</LASTLOGGEDUSER>"
Wscript.Echo "</HARDWARE>"