0

I have designed an HTA file that shows a window and displays some text and uses VBScript to query the AD directory to get the full display name of the logged in user.

Here is the VBscript i am using to query the the name

</script>

<script language="vbscript">
    Sub GetUserName()
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objCurrentUser = GetObject("LDAP://" & objSysInfo.UserName)
    Dim GetUser
    GetUser = objCurrentUser.givenName & " " & objcurrentuser.lastname
    Set WshNetwork = Nothing
    user.innerHTML = "<font color=""black"" face=""Verdana"" size=""4"">" & "Dear " & GetUser 
    & ", Thank you" & "</font>"
    End Sub
  </script>
</head>

Everything works great, however a problem comes in when the display name being queried contains a special character such as / or #. The HTA files errors out.

How can I escape or ignore these characters and display the name without these special characters ?

Thanks all

user1111726
  • 157
  • 2
  • 8
  • 18
  • unfortunately it does not, that question assumes that I already have the string in the code and manipulation is done on it based on an array. However in my case, I am unable pull the string to apply the manipulation, it directly throws an error. – user1111726 Sep 09 '21 at 10:24
  • 1
    That is just an example, you pass whatever you want in your case you need to check against `GetUser`, that's your string. – user692942 Sep 09 '21 at 10:35
  • I understand, but the code breaks at this line "Set objCurrentUser = GetObject("LDAP://" & objSysInfo.UserName)" and therefore I am unable to manipulate the objects inside it due to the presence of a special character – user1111726 Sep 09 '21 at 10:49
  • 1
    What is the exact error you get when running the HTA? – user692942 Sep 09 '21 at 12:34
  • Can you recreate the error with a .vbs script (i.e no hta)? – LesFerch Sep 09 '21 at 13:33
  • It will be Unicode support that's the issue but not sure how you handle it in MSHTA though. If it was a plain VBScript you just use `cscript /u` for Unicode support. Have you tried saving the HTA file as unicode? – user692942 Sep 09 '21 at 14:20
  • I wasn't thinking Unicode, as the characters mentioned were / and #. I was thinking it was an LDAP issue and he might have to use the NameTranslate object as described here: http://www.rlmueller.net/CharactersEscaped.htm – LesFerch Sep 10 '21 at 01:11
  • @Les Yes I was able to reproduce the issue in the VBScript itself. I was able to resolve the problem by eliminating the LDAP and parsing thru the "systeminfo.Username" – user1111726 Sep 16 '21 at 06:16

0 Answers0