How to get username with vbs

后端 未结 4 776
遥遥无期
遥遥无期 2020-12-10 13:56

So i\'m trying to move a .vbs file with .movefile line and i want to give the .vbs to me friends but in order it to work I would have to know what their username is. what wo

相关标签:
4条回答
  • 2020-12-10 14:11

    Copy and paste this code:

    Set wshShell = CreateObject( "WScript.Shell" )
    User = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
    WScript.Echo "User: " & strUserName
    
    0 讨论(0)
  • 2020-12-10 14:21

    To get the username of the person currently logged in:

    strUser = CreateObject("WScript.Network").UserName
    
    0 讨论(0)
  • 2020-12-10 14:21
    Set wshShell = CreateObject( "WScript.Shell" )
    
    strName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
    

    That would store the username in the string "strName' so it would work like this:

    x=messagebox ("Hello ") + strName ,1, strName)
    

    or in your case:

    x=messagebox ("C:\Users\" + strName + "\Desktop\name" ,1, "User name in c:\ directory below"
    
    0 讨论(0)
  • 2020-12-10 14:28

    In VBScript you can get the path to the current user's desktop folder via the SpecialFolders collection:

    WScript.Echo CreateObject("WScript.Shell").SpecialFolders("Desktop")
    
    0 讨论(0)
提交回复
热议问题