Run as admin get log on user name

Author Message
KnkT9

  • Total Posts : 5
  • Scores: 0
  • Reward points : 0
  • Joined: 12/19/2011
  • Status: offline
Run as admin get log on user name Thursday, December 22, 2011 7:25 AM (permalink)
0
Hello,
i run a script as admin to and i want to get the computer name,  the log on user name and the installed apps of that computer.
All fields are OK, except the log on user name, instead i get the admin user name.

   Set wshShell = WScript.CreateObject( "WScript.Shell" )computerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) userName = wshShell.ExpandEnvironmentStrings("%USERNAME%") jobDate = Date() & " " & Time() 
 '***************** Get Installed Softwares *************************** 
 Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE strComputer = "." softPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" displayName = "DisplayName" quitDisplayName = "QuietDisplayName" installDate = "InstallDate" versionMajor = "VersionMajor" versionMinor = "VersionMinor" estimatedSize = "EstimatedSize" 
 Set objFSO = CreateObject("Scripting.FileSystemObject") Dim insAppFil insAppFil = "ListInstallSoft.csv" If objFso.FileExists(insAppFil) Then objFso.deleteFile(insAppFil) Else Set objOutputFile = objFso.CreateTextFile(insAppFil) objOutputFile.Close End If Set objTextFile = objFSO.CreateTextFile(insAppFil, True) Set objReg = GetObject("winmgmts://" & strComputer & _ "/root/default:StdRegProv") objReg.EnumKey HKLM, softPath, arrSubkeys For Each strSubkey In arrSubkeys intRet1 = objReg.GetStringValue(HKLM, softPath & strSubkey, _ displayName, strValue1) If intRet1 <> 0 Then objReg.GetStringValue HKLM, softPath & strSubkey, _ quitDisplayName, strValue1 End If If strValue1 <> "" Then objReg.GetStringValue HKLM, softPath & strSubkey, _ installDate, strValue2 objTextFile.WriteLine computerName & "," & userName & "," & strValue1 & "," &  strValue2 & "," & intValue3 &_ "," & jobDate End If Next objTextFile.Close 


Can any one help.
Thank you
<message edited by KnkT9 on Thursday, December 22, 2011 7:30 AM>
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: online
    Re:Run as admin get log on user name Thursday, December 22, 2011 7:36 AM (permalink)
    0
    Well the script would get the name based on the context that it is running in. If the user is logged on at the time that the script runs, use WMI to get the running processes, look at the owners of the explorer.exe processes. If the user is not logged on when you run the script, it gets much much more difficult.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      KnkT9

      • Total Posts : 5
      • Scores: 0
      • Reward points : 0
      • Joined: 12/19/2011
      • Status: offline
      Re:Run as admin get log on user name Thursday, December 22, 2011 8:22 AM (permalink)
      0
      i'm running the script only on logged on users.
      but how to get the running process.exe
      Thanks
      <message edited by KnkT9 on Thursday, December 22, 2011 8:25 AM>
       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: online
        Re:Run as admin get log on user name Thursday, December 22, 2011 8:27 AM (permalink)
        0
        So is the script running as the logged in user or as an admin? Or is the logged on user an admin that is running the script (in which case you should be able to get the name)? Regardless, to get the running processes:
         
        http://bit.ly/tGYjge
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4
          KnkT9

          • Total Posts : 5
          • Scores: 0
          • Reward points : 0
          • Joined: 12/19/2011
          • Status: offline
          Re:Run as admin get log on user name Thursday, December 22, 2011 8:42 AM (permalink)
          0
          its an admin user who is gonna run the vbscript remotly on a local user.
          i managed to get the process name but did not find the function to get the process owner
          for example -> the explorer.exe owner
           
          #5
            ebgreen

            • Total Posts : 8227
            • Scores: 98
            • Reward points : 0
            • Joined: 7/12/2005
            • Status: online
            Re:Run as admin get log on user name Thursday, December 22, 2011 8:47 AM (permalink)
            0
            To get the process owner:
             
            http://bit.ly/rWrZ1Z
            "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
            Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
            http://www.visualbasicscript.com/m_47117/tm.htm
             
            #6
              KnkT9

              • Total Posts : 5
              • Scores: 0
              • Reward points : 0
              • Joined: 12/19/2011
              • Status: offline
              Re:Run as admin get log on user name Thursday, December 22, 2011 9:35 AM (permalink)
              0
              thanks for you help but i know how search in google.
              if you have a some line to begin with, u welcomed
               
              THanks
               
              #7
                ebgreen

                • Total Posts : 8227
                • Scores: 98
                • Reward points : 0
                • Joined: 7/12/2005
                • Status: online
                Re:Run as admin get log on user name Tuesday, December 27, 2011 3:47 AM (permalink)
                0
                Apparently you don't know how to search on google all that well. There are examples within the first 3 results of each of those searches that answer the questions that you asked. If you have tried the code that those searches showed you and you can not get it to work, then post what you have written and we can help you. I generally do not write code for people and I especially do not write code that can very easily be found online already.
                "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
                Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
                http://www.visualbasicscript.com/m_47117/tm.htm
                 
                #8

                  Online Bookmarks Sharing: Share/Bookmark

                  Jump to:

                  Current active users

                  There are 0 members and 1 guests.

                  Icon Legend and Permission

                  • New Messages
                  • No New Messages
                  • Hot Topic w/ New Messages
                  • Hot Topic w/o New Messages
                  • Locked w/ New Messages
                  • Locked w/o New Messages
                  • Read Message
                  • Post New Thread
                  • Reply to message
                  • Post New Poll
                  • Submit Vote
                  • Post reward post
                  • Delete my own posts
                  • Delete my own threads
                  • Rate post

                  2000-2012 ASPPlayground.NET Forum Version 3.9