vba HTA 如何获取当前用户的用户名?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10725000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:16:02  来源:igfitidea点击:

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

vbavbscripthta

提问by Cocoa Dev

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

但它在 HTA 应用程序中不受支持

回答by Ekkehard.Horner

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

正如它的前缀所示,“objNetwork”是一个对象。所以使用“Set”来分配给变量。

   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 herefor the same mistake. Seems to be a bad day for this feature of VBScript.

PS在这里寻找同样的错误。对于 VBScript 的这个特性来说,似乎是糟糕的一天。