HTA how do I get the username for the current user?

大城市里の小女人 提交于 2019-12-24 03:29:39

问题


I want to get the username for the current user and then create a link in my application name

the link would look like

http://localhost/?id=username

I tried

Dim objNetworkSet 
objNetwork = CreateObject("WScript.Network")

But it's not supported in HTA applications


回答1:


As it's prefix indicates, "objNetwork" is an object. So use "Set" to assign to the variable.

   Dim objNetwork : Set objNetwork = CreateObject("WScript.Network")
   MsgBox objNetwork.UserName

Assuming you want to set the link at runtime/on the fly:

<html>
 <head>
  <title>SetLink HTA</title>
  <HTA:APPLICATION
    APPLICATIONNAME="SetLink HTA"
  >
  <SCRIPT Language="VBScript">
   Sub SetLink()
     Dim oWNet : Set oWNet = CreateObject("WScript.Network")
     MsgBox oWNet.UserName
     LinkToBeDone.href = "http://gent/~" & oWNet.UserName
   End Sub
  </SCRIPT>
 </head>
  <body onLoad="SetLink">
   <a id="LinkToBeDone" href="!somewhere!">To your home at a real computer</a>
 </body>
</html>

P.S. Look here for the same mistake. Seems to be a bad day for this feature of VBScript.



来源:https://stackoverflow.com/questions/10725000/hta-how-do-i-get-the-username-for-the-current-user

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