Results 1 to 5 of 5

Thread: [RESOLVED] specific user logged on?

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    3

    Resolved [RESOLVED] specific user logged on?

    Hello everyone. Please help me on this one! I'm trying to make a VBScript that checks whether or not a specific user is loggen on. If not, send smtp warning email. This should be fairly simple, but I can't get anything to work.

    The code is:

    'VBScript: Check to see, whether or not UserName is loggen on
    'If logged on, do nothing. If not logged on, send warning email
    Code:
    Dim oShell
    Dim callingUser
    Dim userName
    Set userName = "example.user"
    
    Set oShell = Wscript.CreateObject("Wscript.Shell")
    callingUser = oShell.ExpandEnvironmentStrings("%USERNAME%")
    'WScript.Echo callingUser
    
    'HELP me write a boolean function that checks to see whether or not userName is currently loggen on
    'Returns true if userName is logged on, false if not.
    
    if(loggedOn = true) then
    	Set oMsg = CreateObject("CDO.Message")
    	set iBodyPart = oMsg.BodyPart
    	iBodyPart.CharSet = "iso-8859-1"
    	oMsg.To = "[email protected]"
    	oMsg.From = "[email protected]" 
    	oMsg.Subject = "WARNING from " & callingUser & ": " & userName & " is not logged on."
    	oMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "HIDDEN" 
    	oMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
    	oMsg.Configuration.Fields.Update 
    	oMsg.Send 
    	Set oMsg = Nothing 
    end if

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: specific user logged on?

    Welcome to the forums.

    I don't see where you are comparing anything to anything to see if there is a match.

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    3

    Re: specific user logged on?

    That's the thing. I didn't know how to access a list of logged on users on the computer... I got it work anyway, because at last, I magically found an example of doing it:

    userName = "benjaminmj"
    serverName = "MYCOMPUTER"
    message0 = "WARNING from " & callingUser & ": " & userName & " is not logged on"
    message1 = "INFORMATION from " & callingUser & ": " & userName & " is logged on."
    recipiant = "[email protected]"
    sender = "[email protected]"
    smtpserver = "[SMPT OUT-server address]"
    sendusing = 2

    '***********************************
    '***********************************
    '***********************************
    Code:
    Dim oShell
    Dim callingUser
    found = 0
    set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & serverName & "\root\cimv2")
    set objEnum = objWMIService.execQuery("select __relpath from win32_process where caption = 'explorer.exe'")
    Set oShell = Wscript.CreateObject("Wscript.Shell")
    callingUser = oShell.ExpandEnvironmentStrings("%USERNAME%")
    Set oMsg = CreateObject("CDO.Message")
    set iBodyPart = oMsg.BodyPart
    iBodyPart.CharSet = "iso-8859-1"
    oMsg.To = recipiant
    oMsg.From = sender
    
    for each obj in objEnum
    	set outParams = obj.ExecMethod_("GetOwner")
    	if(outParams.User = userName) then
    		found = 1
    	end if
    next
    
    if(found = 0) then
    	oMsg.Subject = message0
    else
    	oMsg.Subject = message1
    end if
    oMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpserver 
    oMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = sendusing
    oMsg.Configuration.Fields.Update 
    oMsg.Send 
    Set oMsg = Nothing

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: specific user logged on?

    Well, I'm glad you go it going, and thank you for posting your results.

    If you consider this resolved, you could help us out by pulling down the Thread Tools menu and clicking the Mark Thread Resolved menu item. That will let everyone know that you have your answer.

    Thank you.

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    3

    Re: specific user logged on?

    No problem... And thank you for your interest!

Posting Permissions

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



Click Here to Expand Forum to Full Width