2

I'm fairly new to javascript and HTAs but here's what I have so far:

  <HTML> 
  <HEAD> 
  <title>Create Drive</title>
    <HTA:APPLICATION
     APPLICATIONNAME="CreateDrive"
     VERSION="1.0"
     SINGLEINSTANCE="yes"/>
    <SCRIPT language="JavaScript">
    window.resizeTo(400,300)
      function WriteFile() {
        var fso  = new ActiveXObject("Scripting.FileSystemObject"); 
        var fh = fso.CreateTextFile("output.txt", true); 
        fh.WriteLine(userinfo.UN.value + ' ' + userinfo.FN.value + ' ' + userinfo.LN.value);
        fh.Close(); 
      }
    </SCRIPT>
  </HEAD>
  <BODY>
    <FORM name="userinfo">
      <P>User Name: <INPUT name="UN" type="text"></P>
      <P>First Name: <INPUT name="FN" type="text"></P>
      <P>Last Name: <INPUT name="LN" type="text"></P>
      <P><INPUT type="button" value="Create Drive" onclick="WriteFile();"></P>
    </FORM>
    </BODY>
</HTML>

My goal is to use this HTA to create network drives for new user accounts. Previously, to accomplish this, a .bat was used that referenced a VBScript and the user entered three values (user, first, and last name) which were passed along to the .vbs and created the drive:

cscript /nologo newdrive.vbs q:\users\%1 /DFS:yes /server:server1 /server2:server2 /userfirstname:%2 /userlastname:%3 /quiet:no

I would like to access this VBScript directly from my HTA and pass the values of UN, FN, and LN. I'm currently saving the values entered into a text file, but I appreciate any info on completing this a better way.

Thanks for your assistance.

1 Answer 1

1

I'm using VBScript for this example. You could just as easily do this in JavaScript, however.

Sub WriteFile()

    ' Retrieve the form values to be passed as args...
    a1 = userinfo.UN.value
    a2 = userinfo.FN.value
    a3 = userinfo.LN.value

    With CreateObject("WScript.Shell")

        ' Run the script, passing along the form values...
        .Run "wscript.exe newdrive.vbs " & a1 & " " & a2 & " " & a3

    End With

End Sub

In your newdrive.vbs script, you would retrieve these values using the WScript.Arguments collection:

strUser  = WScript.Arguments(0)
strFirst = WScript.Arguments(1)
strLast  = WScript.Arguments(2)
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the response, but I thought the CommandLine property was to be used for variables when the HTA is initially opened from a command line? My workflow will be that a user opens the HTA, enters in the values of UN, FN, & LN, submits and (hopefully) passes these entered values along to the vbs. As it stands now, I will not have any variables when the HTA is launched. Sorry if I'm confusing the function of this property though.
Ahh, okay. So do you just plan on using WshShell.Run to launch your VBScript and pass the arguments to it?
Correct, that's what I was thinking. Currently I'm saving the values entered to "output.txt" and was going to try to find a way to then reference these from the file when the VBScript is launched... but perhaps there's a way to do this without the need for a separate text file?
Yeah, you should be able to just launch your VBScript from your HTA and pass those values as arguments. I'll update my answer.
You're missing some &'s and you forgot to replace %2 with a2. Try this: .Run "wscript.exe newdrive.vbs e:\users\" & a1 & " /DFS:yes /server:server /server2:server /userfirstname:" & a2 & " /userlastname:" & a3 & " /quiet:no"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.