Help with an HTA/DSQUERY

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 14 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
mattw
Posts: 6
Last visit: Mon Dec 04, 2017 1:41 pm

Help with an HTA/DSQUERY

Post by mattw »

Hi all,

I'm trying to run a DSGet inside an HTA using a value piped from a DSQuery, and I keep getting an error that the pipe is an invalid character when I try to open the HTA. Here's the code that I'm working with. I'm sure that my issue is one of format, but I've tried adjusting " marks all around with no success. Could someone help me find my error? Thanks!

<html><head> <!-- hta section below --> <HTA:APPLICATION border="thin" borderStyle="normal" caption="yes" maximizeButton="yes" minimizeButton="yes" showInTaskbar="no" innerBorder="yes" navigable="yes" scroll="auto" scrollFlat="yes"/> <SCRIPT LANGUAGE="VBScript"> Sub btnRun_Click 'Create an instance of the Wscript.shell object: set objShell = CreateObject("Wscript.shell") 'Now create an exec object: set objWshScriptExec = objShell.Exec("dsquery user -name " & txtUsername.value & "*" | dsget user -memberof -expand) 'Now get to the output of running the dsquery by defining a variable to hold the StdOut property of the exec object: set objStdOut = objWshScriptExec.StdOut strhtml = ""Do Until objStdOut.AtEndOfStream strLine = objStdOut.ReadLine strhtml = strhtml & strLine & "<br>"Loop strhtml = strhtmlDataArea.InnerHTML = strhtml End Sub </script> <body> <h1>DSQuery</h1> <p>Please enter in a username you wish to list the group memberships for: :</p><input type="text" id="txtUsername" name="txtUsername" size='50'> <p><input type="button" id="btnRun" name="btnRun" value="Run" onclick="btnRun_Click"></button> <span id = "DataArea"></span></body></html>
mattw2009-05-21 10:14:13
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Help with an HTA/DSQUERY

Post by jvierra »

The pipe has to be inside of the quoted string command. All elements of an Exec run command have to be in one string.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Help with an HTA/DSQUERY

Post by jvierra »

You are not enclosing teh whole string inside your quotes.
This is what you are doing in string segments:

"dsquery user -name
No end quote "dsquery user -name "
& "txtUsername.value "
Should not be in quotes & txtUsername.value &
|
No & an no quotes & "|" &
dsget user -memberof -expand"
No beginning quote. "dsget user -memberof -expand"

sCmd = "dsquery user -name "
sCMd = sCmd & txtUsername.value
sCmd = sCmd & " | dsget user -memberof -expand"
MsgBox sCmd

This way you don't need to think about the quotes.

OR
sCmd = "dsquery user -name" & txtUsername.value & " | dsget user -memberof -expand"
MsgBox sCmd

Furthermore:
This is a string:

sCmd = "dsquery user -name "
This is a string plus variable:
sCmd = sCmd & txtUsername.value
Now add last string:
sCmd = sCmd & " | dsget user -memberof -expand"

and

sCmd = "dsquery user -name" & txtUsername.value & " | dsget user -memberof -expand"

Now does it make more sense?jvierra2009-05-21 12:12:27
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Help with an HTA/DSQUERY

Post by jvierra »

Diiferent problem but yo still haven't done it the way I showed you. There is a string violation - too many quotes or not enough depending on what you are trying to do.

You must get the script working as a VBS first then move it into an HTA.

Try starting here by saving the followiong to a VBS file and testing it until it works correctly.

Code: Select all

	
MsgBox GetData( "user1" )
	
Function GetData( username )
	

     set objShell = CreateObject("Wscript.shell")
     set proc= objShell.Exec("dsquery user -name " & username. & "* | dsget user -memberof -expand") 
	
     While proc.Status  0 
	
          WScript.Sleep 100
	
     Wend
     GetData = proc.StdOut.ReadAll()
	

End Function
	

Please test the format and contents of the dsquery comman at a prompt to be sure it works as you are expecting. The syntax looks wrong to me.
jvierra2009-05-22 10:21:31
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Help with an HTA/DSQUERY

Post by jvierra »

Here is the same code as an HTA

Code: Select all

<html>
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">  
<title>My HTML Application</title>  
<script language="vbscript">  
      
    Sub loaddiv()  
        result = RunCmdGetOutput( "cmd.exe /c dir c:" )  
        MsgBox result  
        datarea.innerText = result  
    End Sub  
    Function RunCmdGetOutput( cmd )  
      
         set objShell = CreateObject("Wscript.shell")  
         set proc= objShell.Exec("cmd.exe /c dir c:")   
         While not proc.StdOut.AtEndOfStream  
          RunCmdGetOutput = proc.StdOut.ReadAll()  
         Wend  
    End Function
</script>  
</head>  
<body>  
    <input type="button" value="clickme" onclick="loaddiv"/><br /><br />  
    <div id="datarea" style="background-color: buttonface; color: maroon; font-weight: bolder;"></div>  
</body>  
</html>
jvierra2009-05-22 10:56:39
User avatar
mattw
Posts: 6
Last visit: Mon Dec 04, 2017 1:41 pm

Help with an HTA/DSQUERY

Post by mattw »

Thanks for the information. I've been able to get the dsget and dsquery to pipe with a DN in DOS, but can't seem to get them to work together in vbscript. I've used the ADSI scripts before, but had really liked the slimmer code possibilities. Guess we can't have it all. :)

Thanks again, for your help.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Help with an HTA/DSQUERY

Post by jvierra »

YOu majo issue was teh strings. After testing that I saw that - of course - it's a unicode application.

There is a way to get around this but I don't know it off the top of my head. Ypu could pipe to a file and load teh file.

User avatar
mattw
Posts: 6
Last visit: Mon Dec 04, 2017 1:41 pm

Help with an HTA/DSQUERY

Post by mattw »

Well, while messing around with pulling AD info into the HTA I tried the following:

<HTML> <HEAD> <TITLE>Users Group Query HTA</TITLE> <HTA:APPLICATION ID="MyApp" APPLICATIONNAME="Template" BORDER="thick" BORDERSTYLE="complex" CAPTION="yes" CONTEXTMENU="no" INNERBORDER="yes" MAXIMIZEBUTTON="yes" MINIMIZEBUTTON="yes" NAVIGABLE="no" SCROLL="no" SHOWINTASKBAR="yes" SINGLEINSTANCE="yes" SYSMENU="yes" VERSION="1.0" WINDOWSTATE="maximized"/> </HEAD> <SCRIPT Language="VBScript">
Sub btnRun_Click
sDomain = objNetwork.UserDomainsUser = InputBox.valueSet objNetwork = CreateObject("WScript.Network")set objUser = GetObject("WinNT://" & sDomain & "/" & sUser)
for each oGroup in objUser.Groups sGroups = sGroups & oGroup.Name & vbcrlfNextDataArea.InnerHTML = sGroupsEnd Sub </SCRIPT> <body> <input type="text" name="InputBox" size=40 value="Enter User Name"><p> <input type="button" value="Run" name="btnRun" onClick="btnRun_Click"> <input id=runbutton type="button" value="clear" onClick="clear"> <p><Span ID = "DataArea"></Span></body></html>

But I keep getting an Object Required error on objNetwork when I click on Run. I understand that some WScript objects don't work in HTA because it's not running WScript or CScript, but I thought that WScript.Network was an exception if you used the CreateObject method?
User avatar
mattw
Posts: 6
Last visit: Mon Dec 04, 2017 1:41 pm

Help with an HTA/DSQUERY

Post by mattw »

This code works in VBS:
dim objNetworkdim sDomain, sGroup, sUserdim objGroup, objUserdim bMember
sUser = InputBox("Enter logon ID")Set objNetwork = CreateObject("WScript.Network")sDomain = objNetwork.UserDomain' MsgBox "sDomain: " & sDomain' sUser = objNetwork.UserName' MsgBox "sUser: " & sUser
set objUser = GetObject("WinNT://" & sDomain & "/" & sUser)
for each oGroup in objUser.Groups sGroups = sGroups & oGroup.Name & vbcrlfNext
msgbox sGroups

So testing that code by transplanting into the HTA didn't really help me much with the error that I'm getting.
This topic is 14 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked