HTA\Vbscript question

Posted on 2008-06-26
Medium Priority
Last Modified: 2012-05-05
I have this code as a part of a larger script in a HTA:
CreateObject("Wscript.Shell").Run("cscript notepad.exe c:\temp\temp.txt")

The problem is, this works fine on the local machine. But if I launch this HTA from another remote machine (the HTA is hosted on a central server), the remote machine tries to open temp.txt on it's own C: drive, doesn't find it and the script bombs. Is there a way I can make the client computers look for temp.txt on the server's C: drive and not on their own.???

Question by:Freshandeasy
  • 4
  • 4
LVL 38

Expert Comment

ID: 21875379
Sure, just use the UNC path of the desired file, e.g. \\server\c$\temp\temp.txt.  Keep in mind that this file must be accessible to the user running the HTA, so you might have to create a new share and adjust permissions accordingly.

It would be simpler to locate the temp file in the same folder as the .hta.  That way you could just reference it by name without including the folder path.

Author Comment

ID: 21881301
I had already tried with the UNC path, but in that case an error pops up - "safety settings on this computer prohibit accessing a data source on another domain". I had googled this error and none of the recommendations seemed to have worked.
Actually I am invoking as "runas" which is only applicable to executables. Hence I am forced to use the path  like so:

runas blahblah "mshta d:\blahblah\blah.hta" . This doesn't wotk without the absolute path :-(

Expert Comment

ID: 21900900
If you're willing to limit yourself to IE browsers, just move the code to client side.  Also, you don't need the "cscript".

' Server side code goes inside open and close percent tags
CreateObject("Wscript.Shell").Run("notepad.exe c:\temp\temp.txt")

If you want to support other browsers (obviously still on MS systems), you can alter it to JavaScript.

If all you need to do is display the text, there are much easier ways to do so.  What's the end need?

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.


Author Comment

ID: 21906042
Here's what I am trying to achieve:
1. The user fires an hta placed on a server from his machine.
2. This hta prompts for his username\passowrd, authenticates him, goes through a set of security checks (group memberships, etc.) and if satisfied, calls another HTA placed on the same server (d:\MMBX\MoveMBX.HTA).
3. The issue is, I have to call the second hta with alternate credentials, so this is what I do at the end of first HTA:
runas.vbs username password "mshta d:\MMBX\MoveMBX.HTA"
4. This works fine when I run from the server itself. But fails when a user fires the first hta from his computer. The first hta when trying to start the second hta, looks for d:\MMBX\MoveMBX.HTA in the user's d: drive rather than on the server.

I have tried putting the second hta in the same directory as the first one and not specify the path, no go.
UNC names don't work either.

Hope that clarifies things.

Expert Comment

ID: 21907462
OK... so the user is accessing the first HTA with their own credentials and then you want to run the second HTA under a different (administrative?) set of credentials?  Can I safely deduce from the name that it has something to do with changing a location for an Exchange (or other mail server) mailbox?

It seems to me that you may be going the long way around.  Care to explain what your high-level purpose with the login script and HTAs is?  Do you have an available IIS server?

Expert Comment

ID: 21907509
Oh, and also, if you could mention the versions of the products involved -- like if it is Exchange, is it 2003, if it's part of an upgrade or migration, what are you going from and what are you going to.  If Exchange, the AD version is also important and the OS of the server in question may be also.  Thanks!

Author Comment

ID: 21923204
The purpose of this HTA is to move mailboxes across Exchange 2003 servers (running on windows 2003) when a user physically moves to another location. The idea is to pass this HTA to L1 support teams and take away all their Exchange permissions.Hence the need to run the second HTA under alternate credentials. (The HTA will be encoded).
The first HTA verifies the credentials and then queries the L1 Support Group in AD to make sure the operator is a member of that group. If all is well, it then calls the second HTA under alternate credentials.

Accepted Solution

gregcmcse earned 750 total points
ID: 21925084
Got it.  I think you're definitely taking the long way around.  Here's how I'd approach it:

Your exchange server(s) probably host IIS (at least some of them, and probably all of them).  So on your intranet web server and/or on one or more of the Exchange servers, create a new IIS web site on a port of your choosing and only allow Windows integrated authentication.  (You can put this in a new virtual directory if you would rather, but that's less secure).  Restrict the access (through file permissions on the mapped folder the web page will live in) to only allow Read access to the group you want to allow and remove all inherited groups.

So then they're accessing a web form that prompts them for the user and anything else you want to prompt them with.

At that point, you can have server-side VB code that runs your HTA locally on the IIS server under the alternate credentials since you've obviously already built it that way.

Let me know if you need any additional clarification on this.

Author Closing Comment

ID: 31470935

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

By following these Magento e-commerce development tips, you can increase your website's conversion and profitability. Read this post for more details.
This article is about the challenges faced by Android app developers.
This video teaches users how to migrate an existing Wordpress website to a new domain.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question