Solved

HTA\Vbscript question

Posted on 2008-06-26
9
1,675 Views
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.???

0
Comment
Question by:Freshandeasy
  • 4
  • 4
9 Comments
 
LVL 38

Expert Comment

by:Shift-3
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.
0
 

Author Comment

by:Freshandeasy
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 :-(
0
 
LVL 9

Expert Comment

by:gregcmcse
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
%>
<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">
<!--
CreateObject("Wscript.Shell").Run("notepad.exe c:\temp\temp.txt")
-->
</HEAD>

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?

0
 

Author Comment

by:Freshandeasy
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.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 9

Expert Comment

by:gregcmcse
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?
0
 
LVL 9

Expert Comment

by:gregcmcse
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!
0
 

Author Comment

by:Freshandeasy
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.
Thanks!!!
0
 
LVL 9

Accepted Solution

by:
gregcmcse earned 250 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.
0
 

Author Closing Comment

by:Freshandeasy
ID: 31470935
Perfecto!!!!!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now