How to get username with vbs

自闭症网瘾萝莉.ら 提交于 2019-11-30 18:18:48

To get the username of the person currently logged in:

strUser = CreateObject("WScript.Network").UserName

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")
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"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!