问题
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