How to get %username% in VBScript?

后端 未结 1 1635
借酒劲吻你
借酒劲吻你 2020-12-21 12:16

I am trying to hide network path of shared folders from domain users. (Windows Server 2012) I have found this script while searching for network drive labeling:



        
1条回答
  •  情歌与酒
    2020-12-21 12:21

    You can expand environment variables in your path string:

    strRemotePath = "\\servername\sharedfoldername1$\%username%"
    
    Set sh = CreateObject("WScript.Shell")
    WScript.Echo sh.ExpandEnvironmentStrings(strRemotePath)
    

    or you can build the path from the share and the UserName property of the WshNetwork that you already have:

    share = "\\servername\sharedfoldername1$"
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    WScript.Echo fso.BuildPath(share, objNetwork.UserName)
    

    0 讨论(0)
提交回复
热议问题