Jump to content

GUI / HTA


Country73
 Share

Recommended Posts

OK, a little background...

I've messed with AutoIT in the past, over a year ago, and never really had the time to get really involved with it.

This week I was finally able to put AutoIT to work. I had to duplicate an EXE to track who was using a particular application (along with the machine they ran it from and what time). This worked out perfectly for me.

Current:

Our company is switching everyones' regular workstations to 'Ultra-thin-clients'. We have decided on the route of the SUN Ultra-Thin DTU's (Desk-Top Unit) - http://www.sun.com/sunray/sunray2/index.xml.

One problem that we have come across is with local printers. To enable the local printer on these DTU's you have to add the printer information into the script that runs on the Sun server. The big problem with that is that it sets the 'local' printer up on every DTU connection and sets it as the default printer; no matter if they have a 'local' printer or not.

I've created an HTA to handle this problem, but I was thinking about using AutoIT (specifically the function to wrap into an EXE) but I wasn't sure if I can just wrap the HTA up with AutoIT, or if I need to recreate it solely in AutoIT.

This HTA is placed in the StartUp, so the first time someone logs into their session this HTA will launch.

It displays the current 'default' printer, which is currently the 'local' printer, and gives them the option to set a new 'default' printer.

If they decide to change the default printer:

There is a textbox for them to enter that printer. The HTA will then check to see if the printer is currently installed.

If the printer is not installed:

Attempt to install that printer (if the printer does not exist, or they typed it wrong, they are displayed a message box and asked to retype the printer name)

If the printer is installed:

Sets that printer as the default

If they decide to leave the current printer as the default:

Nothing needs to be done

Once all of that takes place a text file is created in their profile with the printer they have set as their default.

Now, whenever they log in, the HTA will locate that file and set that printer as their default.

I know this is a little clunky to take care of this, but until we can find a 'better' solution on the Sun side, this is what we are going with.

The HTA works fine, but if I was able to wrap this up as an EXE (or 'gasp' try to re-create this with AutoIT), we don't have to worry about anyone going in and messing up any of the code in the HTA (since this resides on their machine).

I'm currently searching through the forum, but appreciate anyones feedback as for the best way to go with this.

If you try to fail and succeed which have you done?AutoIt Forum Search

Link to comment
Share on other sites

I don't know anything about the Sun stuff, but i can say you have a couple of options. It seems your concern is to protect the hta script from users .

1.Rewrite the code in AutoIt.....assuming you know vbscript, autoit is a rather simple transition. There is an example script somewhere on the forum for converting vbscript to autoit.

2. Use Autoit to create/run and delete the hta at runtime as required.

3. Use Autoit to Run the hta....ShellExecute is one method.

4. Google "script2exe" or "vbscript2exe" is free

Cheers

Edited by Will66
Link to comment
Share on other sites

By HTA I presume you mean a MS Internet Explorer HyperText Application file?

It's not a bad way to go as an HTA gives access to local resources and bypasses many of the browser security restrictions.

AutoIt on the other hand never has to worry about those types of security restrictions. I would expect that writing such an application in AutoIt would be much more straight forward than doing it in hta/html/javascript. You can either use the AutoIt GUI or you can even use COM to work with a browser interface (using IE.au3 UDF perhaps).

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Thank you both for the info; I kind of assumed it would come down to recreating the HTA (MS Internet Explorer HyperText Application) with AutoIT.

I just wasn't sure, since I haven't spent a whole lot of time working with AutoIT, if there was some sort of 'include' so that I could wrap my current HTA up into an EXE using AutoIT.

I'll definitely take a look into the "script2exe" & "vbscript2exe"; I believe I've come across those before, but for some reason didn't go that route... (they just ring a bell for some reason)

Anyways, I appreciate the info you provided.

Hopefully it won't take too much to convert this HTA; and I won't have to post too many questions out here on it.

Thanks,

If you try to fail and succeed which have you done?AutoIt Forum Search

Link to comment
Share on other sites

You explained what you are doing now, but you didn't really make it clear what your current solution doesn't do for you and what you are really trying to create. With that info you might get more suggestions.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

I have a functional HTA that does exactly what I want it to do.

This HTA is placed in the Startup on all of the Virtual Workstations so that it runs as soon as the individual logs in.

If it finds a file called "PrintDefault.txt" inside the users profile: C:\Docum~1\<username> then it reads the file and sets the default printer to what is in the PrintDefault.txt.

If there is no file found, then the HTA will pop-up and have the individual fill out what printer they want to set as their default. Once they 'submit' their information the HTA looks to see if that printer is currently installed (installs if need be) then sets as default. It will then create the "PrintDefault.txt" so that it will be used the next time the user logs in.

Problem: Nothing is stopping the user from editing the HTA and messing up the code.

My main reason for posting my question was to see if I could use my existing HTA and just wrap it up with AutoIT so that it is now an EXE instead of HTA.

If this IS possible, than that would be great.

Only other option would be to create an EXE to launch the HTA from a different location. This way the individual does not know where the HTA resides, and is unable to mess with the code.

Let me know if you need anything else.

If you try to fail and succeed which have you done?AutoIt Forum Search

Link to comment
Share on other sites

Ah, OK.

First questions is couldn't you store the .hta on a network share that allows only read access?

Regarding "wraping" the hta code... one simple thing to do would be to use a compiled AutoIt script to create the .hta file on the fly, execute it and have the hta file delete itself when it completes.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Problem with storing on a Network Share:

HTA's are designed to run locally; you may come across an "ADO Security Warning" whenever the HTA is launched from the network. Will have to test that portion out since the only HTA's (that I've created) connect to some sort of Database. Connection to the registry may not cause that.

So I could try looking at that route.

AutoIT script to create HTA on the fly:

I haven't figured out how to fit all of the HTA into a working AutoIT script. Consider me a NOOB right now, but plan on working with this so that I can push out AutoIT scripts as well as my VBScripts.

The current HTA is right at 191 lines; 32 lines are HTML.

So, for the time being, I'm going to look at the "network share" route, to see if I can create a reg query that the "basic" user can run.

I really want to go the AutoIT route, but I may need to get a little more familiar with the syntax and layout of AutoIT.

Any pointers to assist in my journey will be appreciated.

I've attached the HTA that I've been talking about. We currently have two print servers, so those are the ones referenced in this HTA. (Layout of my script with these code tags isn't as pretty as in my TextEditor)

<head>
<title>Printer Default</title>
<HTA:APPLICATION
    APPLICATIONNAME="Printer Default"
    BORDERSTYLE="normal"
    CAPTION="NO"
    MAXIMIZEBUTTON="no"
    MINIMIZEBUTTON="no"
    NAVIGABLE="no"
    SCROLL="NO"
    SCROLLFLAT = "yes"
    SELECTION = "no"
    SINGLEINSTANCE="yes"
    SYSMENU="yes"
    VERSION="1.0"
    WINDOWSTATE = "normal"
>
</head>

<script language="VBScript">
'===================================================================================
'TITLE:         Default Printer setup: SunRay DTU's
'DESCRIPTION:   Due to the scripts that are ran on the Sun Server, the default printer
'               is setup as the local printer (even if no local printer exists)
'               This script will give them the option, once, to setup a network printer
'               as their default. Records their information so that it will continue
'               to setup their specified printer as their default each time they login.
'
'REQUIREMENTS:  DTU - user logs into
'               Network Printer - already installed on computer
'
'CREATED BY:    Chris Hatt
'CREATED ON:    1/10/07
'====================================================================================
Dim oFS, oShell, oNet, strUser, strDefault

Sub bodyLoaded()
    '================================================================================================
=================================
    'This will first check for the PrintDefault.txt, in current users profile, to see if they have already setup their default printer
    'If they have set their default printer to the local printer, then the HTA closes without doing anything.
    'If they haven't, continue with HTA to give them the option to set their default printer.
    '================================================================================================
=================================
    window.ResizeTo 0,0

    SET oFS = CreateObject("Scripting.FileSystemObject")
    SET oNet = CreateObject("Wscript.Network")

    strUser = oNet.UserName                                         'Grabs the username of the individual logged in
    strDefault = "C:\Docume~1\" & strUser & "\PrintDefault.txt"                       'Sets the text file for default printer

    IF oFS.FileExists(strDefault)THEN                               'Checks to see if "PrintDefault.txt" exists
        SET file = oFS.GetFile(strDefault)                           'If it exists, we want to read from it
        SET fileRead = file.OpenAsTextStream(1,-2)
            DO WHILE fileRead.AtEndOfStream <> TRUE
                strPrinter = TRIM(fileRead.ReadLine)                      'Setup of Default Printer that was setup previously
                IF strPrinter <> "CURRENT DEFAULT" THEN             'Specific printer was setup as Default
                    ON ERROR RESUME NEXT
                        SET oPrinter = CreateObject("WScript.Network")
                            oPrinter.SetDefaultPrinter strPrinter
                        IF ERR.Number = 0 THEN
                            'Clear variables and close HTA
                            SET oPrinter = NOTHING
                            SET fileRead = NOTHING
                            SET file = NOTHING
                            ON ERROR GOTO 0
                            Self.Close
                        ELSE
                            CALL setPrinterDefault(strPrinter)
                        END IF
                ELSE
                    SET file = NOTHING
                    SET fileRead = NOTHING
                    Self.Close
                END IF
            LOOP
    ELSE
        startHTA
    END IF
END SUB

SUB startHTA
    window.ResizeTo 650,620 ' WIDTH, HEIGHT                                  'Visible HTA
    SET oShell = CreateObject("Wscript.Shell")
    sRegVal = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"    'Locate current Default Printer
    sDefault = ""
    ON ERROR RESUME NEXT
        sDefault = oShell.RegRead(sRegVal)
        sDefault = Left(sDefault ,InStr(sDefault, ",") - 1)
    ON ERROR GOTO 0
    DataArea.InnerHTML = sDefault
    SET oShell = NOTHING
END SUB

SUB verifyEntries
    'Check to make sure they have NOT entered a printer for both servers.
    'Only one printer can be set as the default.

    IF IcarusPrinter.Value <> "" AND MatrixPrinter.Value <> "" THEN
        MSGBOX "You can only setup one printer as your default." & VBCR & "Type in the printer name for ICARUS or MATRIX",16,"ENTRY ERROR"
        IcarusPrinter.Focus
        EXIT SUB
    END IF

    'Checks for which server/printer they set as default, or left as local printer as default.

    IF IcarusPrinter.Value <> "" THEN strPrinter = "\\Icarus\" & IcarusPrinter.Value
    IF MatrixPrinter.Value <> "" THEN strPrinter = "\\Matrix\" & MatrixPrinter.Value
    IF IcarusPrinter.Value = "" AND MatrixPrinter.Value = "" THEN strPrinter = "CURRENT DEFAULT"

    'If local printer was not set as default; set their new printer as default
    IF strPrinter <> "CURRENT DEFAULT" THEN
        setPrinterDefault strPrinter
    ELSE
        Self.Close
    END IF
END SUB

SUB setPrinterDefault(strPrinter)
    'Since they chose a MATRIX or ICARUS printer as their default; set this printer up as default and verify
    'that the printer is currently installed on their workstation.
    ON ERROR RESUME NEXT
    SET oPrinter = CreateObject("WScript.Network")
        oPrinter.SetDefaultPrinter strPrinter
    SET oPrinter = NOTHING
    'This should give us a message if the printer is not installed on workstation
    SELECT CASE ERR.Number
        CASE -2147352567
            MSGBOX "The printer " & strPrinter & " is not installed on your computer." & VBCR &_
            "Please wait while the printer is installed.",16,"PRINTER INSTALL REQUIRED"
            printerSetup = FALSE
        CASE ELSE
            MSGBOX "Printer is installed on workstation; printer is now set as default printer." & VBCR & strPrinter,64,"Successful setup"
            'Write information into their profile so that the default printer will be setup automatically on next login.
            SET printFile = oFS.OpenTextFile(strDefault,2,TRUE)
                printFile.WriteLine strPrinter
            SET printFile = NOTHING
            printerSetup = TRUE
            Self.Close
    END SELECT
    ON ERROR GOTO 0
    IF printerSetup = FALSE THEN
        SET WshNetwork = CreateObject("WScript.Network")
            ON ERROR RESUME NEXT
            WshNetwork.AddWindowsPrinterConnection strPrinter
                IF ERR.Number <> 0 THEN
                    MSGBOX "Printer was not found." & VBCR & "Please double check the spelling of the printer name and that it is on the correct Print Server.",16,"PRINTER NOT FOUND"
                    IcarusPrinter.Focus
                    ON ERROR GOTO 0
                    printerSetup = ""
                    window.ResizeTo 650,620
                    EXIT SUB
                END IF
            ON ERROR GOTO 0
            printerSetup = TRUE
        SET WshNetwork = NOTHING
        setPrinterDefault strPrinter
    END IF
END SUB
</script>
<body onload="bodyLoaded()" bgcolor="buttonface">
<center><h2>Printer Default</h2></p></center>
<p>This form is used to setup your Default Printer.<br>
If you would like to change from your <i>current</i> Default Printer, then you will need to enter the printer name for ICARUS or MATRIX.<br>
<b>If you choose to set a ICARUS or MATRIX printer as your default, then this printer should already be setup on your computer!</b><br>

</p>
<table width="100%" height="100%" border="0">
    <tr>
        <table width="100%" height="20%" border="1">
        </table>
    </tr>
    <tr><h3>TO CHANGE DEFAULT PRINTER:</h3></tr>
    <tr><td>Please supply the printer name for ICARUS <i>OR</i> MATRIX:</td></tr>
    <tr>
        <table width="100%" height="20%" border="1">
            <tr><td width="20%"><span class="style5"></span><b>New Default Printer:</b></td></tr>

            <tr><td width="20%">\\ICARUS\<input type="text" name="IcarusPrinter"></td></tr>

            <tr><td width="20%">\\MATRIX\<input type="text" name="MatrixPrinter"></td></tr>

            <tr><td width="20%">Current "Default Printer":  <b><span id="DataArea"></span></b></td></tr>
        </table>
    </tr>
    <tr>
        <table width="100%" height="20%" border="1">
            <tr><td width="20%"><input type="button" name="Submit" value="Submit" onclick="verifyEntries"></td></tr>
        </table>
    </tr>
</table>
</body>
Edited by Country73

If you try to fail and succeed which have you done?AutoIt Forum Search

Link to comment
Share on other sites

Take a look here: IEBodyReadHTML and Hta Question

Dale

Note that a regression in AutoIt 3.2.2.0 will require that you edit IE.au3 to implement a workaround to an issue with _IEAttach embedded -- see this bug report

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Good read, at least it gives me an idea on creating through AutoIT.

The reg query is able to run without any issues from a network share, at least with the individuals I was able to test this out on.

So, I was able to place my HTA out on a network share and create a very nice little EXE to launch it.

RunWait("mshta.exe \\<server>\<share>\DefaultPrinter.hta")

Was able to use a printer icon for the EXE itself (used Easy Icon Maker to extract the printer icon from Shell32.dll) so it looks pretty professional.

I still plan on writing, not sure if you would actually call it an HTA or EXE now, through AutoIT.

I'm supposed to create another HTA (basically the same as the first), but this will give the individual a chance to 'change' their default printer after they have already used the first HTA to set it up.

Reason: if their default printer is down, they move to a new location and need to use a different printer, they just get tired of using that printer.

Since I have this nice EXE ready to deploy I can spend a little more time on this next one.

I guess it's time to really dig into the AutoIT Help file to start familiarizing myself more.

Thanks for all your help; those links and ideas got me going again when I reached a stalemate ( :D ) on my scripting.

:)

Forgot to mention; best part of it residing on the network is that it will be extremely easy to update if need be. (Hate to try to update this once it's pushed out to over 2000 Virtual Workstations)

Edited by Country73

If you try to fail and succeed which have you done?AutoIt Forum Search

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...