How to get username with vbs

风格不统一 提交于 2019-11-30 01:45:02

问题


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 would I put to make the .vbs know their username Ex "C:\users\username\desktop"


回答1:


To get the username of the person currently logged in:

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



回答2:


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")



回答3:


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"


来源:https://stackoverflow.com/questions/22276361/how-to-get-username-with-vbs

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