can you get the pc user name in vbs?

前端 未结 2 1710
耶瑟儿~
耶瑟儿~ 2020-12-12 07:21

Is there way to find the PC user in visual basic (C:\\User\\\"here\"). After we get it, just save it as a string.

I know the answer might be a bit obvious, but I ca

相关标签:
2条回答
  • 2020-12-12 08:06

    The simplest way might be to query the environment.

    There are USERDOMAIN, USERNAME, USERPROFILE and COMPUTERNAME environment variables containing the obvious values.

    Querying those would depend solely on WScript.Shell instead of on WScript.Network as in the accepted (and correct) answer. If you already have a reference to the shell, this might be a slightly more comfortable way.

    0 讨论(0)
  • 2020-12-12 08:08

    Fairly simple, from here ( http://blogs.msdn.com/b/alejacma/archive/2008/03/11/how-to-get-the-user-running-a-vbscript.aspx )

    Dim networkInfo
    Set networkInfo = CreateObject("WScript.NetWork") 
    
    Dim infoStr
    infoStr = "User name is     " & networkInfo.UserName & vbCRLF & _
              "Computer name is " & networkInfo.ComputerName & vbCRLF & _
              "Domain Name is   " & networkInfo.UserDomain
    
    MsgBox infoStr
    
    0 讨论(0)
提交回复
热议问题