»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 07-23-2003, 04:34 PM   #1 (permalink)
Registered User
 
Join Date: Jul 2003
Posts: 5
brimhals is on a distinguished road
Send a message via ICQ to brimhals
Kids Current User Who? How?

Using VBS how can I determine remotely who the current logged in user is? I have a script which inventories my systems remotely All I need now is to know who is currently logged into the system. Any Ideas?

brimhals is offline   Reply With Quote
Old 07-23-2003, 07:58 PM   #2 (permalink)
Registered User
 
Join Date: Oct 2001
Location: TOO close to Wash DC
Posts: 7,956
vass0922 is on a distinguished road
Dim objNetwork

Set objNetwork = CreateObject("Wscript.Network")
WScript.Echo objNetwork.UserName

Set objNetwork = Nothing

I think thats it! If not look into the network object ithas what you need
__________________
<< Insert exceedingly large and overly verbose message of how 1337 you are here including full specs of every vehicle you've ever driven and PC you've owned >>
vass0922 is offline   Reply With Quote
Old 07-24-2003, 08:02 AM   #3 (permalink)
Registered User
 
Join Date: Jul 2003
Posts: 5
brimhals is on a distinguished road
Send a message via ICQ to brimhals
Close

That will work if i run the script locally. I need to get it while running the script from a remote machine. I currently use WMI in VBS to retrieve alot of other information but cant seem to get the currently logged in user.
brimhals is offline   Reply With Quote
Old 07-24-2003, 08:05 AM   #4 (permalink)
Registered User
 
Join Date: Jul 2003
Posts: 5
brimhals is on a distinguished road
Send a message via ICQ to brimhals
Here is my current code!

Dim strStatus
Dim pstatus
Dim IE
Dim Connect
Dim objWMIService, objSystem, a
Dim ColSystem, sManufacturer, sSystemtype, sSystemName, sBiosRev
Dim sServiceTag, sAssetTag, subnet


On Error Resume Next

'===================
'| Create IE Object
'===================

Set objCDO = wscript.CreateObject("CDO.Message")
Set objExplorer = WScript.CreateObject("InternetExplorer.Application ", "IE_")
objExplorer.Navigate ""
objExplorer.Visible = 1
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width=600
objExplorer.Height = 600
objExplorer.Left = 0
objExplorer.Top = 0
Wscript.Sleep 250


subnet = inputbox("enter system To scan:" & vbCrlf & "Example: 140.171.99.")
If subnet = "" Then
subnet = "."
End If
If subnet = "." Then
Call getinfo(subnet)
Else
For n = 1 To 255
Call pingcheck(subnet & n)
Next
End If
Call updatestatus("Complete")
wscript.sleep 1000
If objExplorer.Document.Body.All.wclose.checked Then
objExplorer.quit
End If


Function Updatestatus(comments)
objExplorer.Document.Body.All.wstatus.Value = comments
'wscript.sleep 500
End Function

Function pingcheck(IPAddress)
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonat e}").ExecQuery("select * from Win32_PingStatus where address = '" & IPAddress & "'")
Call updatestatus("Pinging " & ipaddress)
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) Or objStatus.StatusCode<>0 Then
Else
Call getinfo(IPAddress)
End If
Next
End Function
'================================================= ================================================== =
Function GetInfo(IPAddress)

'On Error Resume Next
While objExplorer.busy
wscript.sleep 50
Wend
'================================================= =========================
' Declare Variables
'================================================= =========================
Set conn = WScript.CreateObject("ADODB.Connection")
Connect="Driver={SQL Server};Server=;Database=;UID=;PWD="
conn.Open connect

Call updatestatus("Searching " & ipaddress)
' Connect to remote system. If system is powered off, it may take up To
' 45 seconds for the connection attempt to time out

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonat e,AuthenticationLevel=pktprivacy}\\" & IPAddress & "\root\cimv2")

If Err.Number = 0 Then

' If able to connect gather data from CimV2 namespace
Set ColSystem=objWMIService.execquery ("Select * from Win32_ComputerSystem")
Call updatestatus("Searching hardware")
For each objSystem in colSystem
sManufacturer = objSystem.Manufacturer
sSystemtype = objSystem.Model
sSystemName = objSystem.Name
Next

Set ColSystem=objWMIService.execquery ("Select * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
Call updatestatus("Searching Network Card")
For Each objAdapter In ColSystem
If Not IsNull(objAdapter.IPAddress) Then
sIPAddress = objAdapter.IPAddress(0)
sMacAddress = objAdapter.MacAddress
objExplorer.Document.Body.All.wIPAddress.Value = sIPAddress
End If
Next
' Set ColSystem=objWMIService.execquery ("Select * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
' Call updatestatus("Searching hardware")
' sIPAddress = objAdapter.IPAddress
'msgbox sipaddress

sql1 = "SELECT * FROM tblinv where fldsystemname='" & sSystemName & "'"
Set rs1 = WScript.CreateObject("ADODB.Recordset")
rs1.open sql1, conn, 3, 3

Set colSystem=objWMIService.ExecQuery _
("Select * from Win32_Product")
Call updatestatus("Searching for installed software")
If rs1.recordcount > 0 Then
If datediff("d",rs1.fields("fldinvdate"),now()) > 60 Then
saction = "update"
Else
saction = "none"
End If
Else
saction = "add"
End If
Select Case saction

Case "none"

Case Else
For Each objSystem In colSystem
objExplorer.Document.Body.All.wsoftware.value = objExplorer.Document.Body.All.wsoftware.value & vbCrlf & objsystem.name
Select Case saction
Case "add"
rs1.addnew
rs1.fields("fldsystemname")= sSystemName
rs1.fields("fldsoftware")= objSystem.Name
rs1.fields("fldinvdate")=Now()
rs1.update
Case "update"
rs1.close
Call updatestatus("Removing Old Records From Database")
sql1 = "DELETE FROM tblinv where fldsystemname='" & sSystemName & "'"
rs1.open sql1, conn, 3, 3
rs1.close
sql1 = "SELECT * FROM tblinv where fldsystemname='" & sSystemName & "'"
rs1.open sql1, conn, 3, 3
rs1.addnew
rs1.fields("fldsystemname")= sSystemName
rs1.fields("fldsoftware")= objSystem.Name
rs1.fields("fldinvdate")=Now()
rs1.update
saction = "add"
Case Else
End Select
Next
End Select
rs1.close
Set colSystem=objWMIService.ExecQuery _
("Select * from Win32_BIOS")
Call updatestatus("Searching BIOS")
For each objSystem in colSystem
sBiosRev = objSystem.SMBIOSBIOSVersion
Next


Set colSystem=objWMIService.ExecQuery _
("Select * from Win32_processor")
Call updatestatus("Searching CPU SPeed")
For Each objSystem In colSystem
cp = cp + 1
sclockspeed = objSystem.currentclockspeed

Next
objExplorer.Document.Body.All.wcpucount.Value = cp
'Set colSystem=objWMIService.ExecQuery _
' ("Select * from Win32_temperatureprobe")

' For Each objSystem In colSystem
' stemperature = objSystem.CurrentReading
' Next

Set colSystem=objWMIService.ExecQuery _
("Select * from Win32_operatingsystem")
Call updatestatus("Determining Operating System")
For Each objSystem In colSystem
scaption = objSystem.caption
Next
Set colSystem=objWMIService.ExecQuery _
("Select * from Win32_physicalmemory")
Call updatestatus("Determining Memory Installed")
For Each objSystem In colSystem
scapacity = scapacity + cint((objSystem.capacity/1048576))
Next
' Set colSystem=objWMIService.ExecQuery _
' ("Select * from Win32_userAccount.domain=vssi,user=administrator")


'For Each objSystem In colSystem
' sdomain = sdomain & vbCrlf & objsystem.domain
' suser = objsystem.name
'Next
'msgbox sdomain

Set colSystem=objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
Call updatestatus("Determining Serial & Asset Tag #")

For each objSystem in colSystem
sServiceTag = objSystem.serialNumber
sAssetTag = objSystem.SmBiosAssetTag

Next

objExplorer.Document.Body.All.wIPAddress.Value = sIPAddress
objExplorer.Document.Body.All.wBiosRev.Value = sBiosrev
objExplorer.Document.Body.All.wSystemType.Value = ssystemtype
objExplorer.Document.Body.All.wSystemName.Value = ssystemname
objExplorer.Document.Body.All.wServiceTag.Value = sservicetag
objExplorer.Document.Body.All.wManufacturer.Value = smanufacturer
objExplorer.Document.Body.All.wclockspeed.Value = sclockspeed
objExplorer.Document.Body.All.wcaption.Value = scaption
objExplorer.Document.Body.All.wcapacity.Value = scapacity
objExplorer.Document.Body.All.wfullname.Value = sfullname
objExplorer.Document.Body.All.wuser.Value = suser

'============================
'| Create Database connection
'============================

Set rs = WScript.CreateObject("ADODB.Recordset")

sql = "SELECT * FROM datacollection where (flddstn='" & sservicetag & "')"
rs.Open sql, conn, 3, 3

Call updatestatus("Writing Information to database")
If rs.recordcount > 0 Then
rs.fields("fldipaddress") = sIPAddress
rs.fields("fldbiosrev") = sBiosrev
rs.fields("fldmodel") = ssystemtype
rs.fields("fldNodeName") = ssystemname
' rs.fields("flddstn") = sservicetag
rs.fields("fldmanufacturer") = smanufacturer
rs.fields("fldcpuspeed") = sclockspeed
rs.fields("fldOS") = scaption
rs.fields("fldmem") = scapacity
rs.fields("fldcpuqty") = cp
rs.fields("meetsmin") = "True"
rs.fields("macadd") = smacaddress
' rs.fields("fldfullname") = sfullname
' rs.fields("flduser") = suser
rs.update
rs.close
Else
rs.addnew
rs.fields("fldipaddress") = sIPAddress
rs.fields("fldbiosrev") = sBiosrev
rs.fields("fldmodel") = ssystemtype
rs.fields("fldNodeName") = ssystemname
rs.fields("flddstn") = sservicetag
rs.fields("fldmanufacturer") = smanufacturer
rs.fields("fldcpuspeed") = sclockspeed
rs.fields("fldOS") = scaption
rs.fields("fldmem") = scapacity
rs.fields("fldcpuqty") = cp
rs.fields("meetsmin") = "True"
' rs.fields("fldfullname") = sfullname
' rs.fields("flduser") = suser
rs.update
rs.close
End If
Else

' If errors, then return string stating could not connect to system with error description

objExplorer.Document.Body.All.werror.Value = Err.description
Err.clear

End If

End Function
brimhals is offline   Reply With Quote
Old 07-24-2003, 08:49 AM   #5 (permalink)
Registered User
 
Join Date: Jul 2003
Posts: 5
brimhals is on a distinguished road
Send a message via ICQ to brimhals
got It!
Here is how...
Set ColSystem=objWMIService.execquery ("Select * from Win32_computersystem")
For Each objSystem In colSystem
sUser = objsystem.username
Next
brimhals is offline   Reply With Quote
Old 07-24-2003, 03:57 PM   #6 (permalink)
Registered User
 
Join Date: Oct 2001
Location: TOO close to Wash DC
Posts: 7,956
vass0922 is on a distinguished road
Fabulous.. I'm actually working on a script myself where that maybe useful!

oh and sorry.. I didn't catch 'remotely' in your initial message
__________________
<< Insert exceedingly large and overly verbose message of how 1337 you are here including full specs of every vehicle you've ever driven and PC you've owned >>
vass0922 is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 05:12 AM.