We help IT Professionals succeed at work.

Install Software through HTA. Need to set permission

5,084 Views
Last Modified: 2012-05-05
Hi,

below is a Software install HTA. That is done by Rob.

I have a senario. Where the shared folder where all these softwares are there does not have permissions for the user.
So as the helpdesk engineer connects to the users machine through MSTSC. Browses to this HTA file where every one has permissions.
Then there need to be a box which shall ask the username and password. After which the installer. Put in the credentials to install softwares on the restricted share with these new credentials.
Any help is of great use...
Regards
Sharath
'=============
<head>
<title>Choose Software To Install</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Choose Software To Install"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
</head>
 
<script language="VBScript">
 
Dim arrSoftware
 
Sub Window_onLoad
      intWidth = 800
      intHeight = 600
      Me.ResizeTo intWidth, intHeight
    Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
      arrSoftware = Array(_
           "Chennai;Office Products;Office 2003;\\in\FS\Office_Products\Office_2003\SETUP.EXE", _
           "Chennai;Office Products;Office Xp;\\dev\Office XP\SETUPPRO.EXE", _
            "Chennai;Utilities;WinZip;\\dev\WinZip\SETUP.EXE", _
            "Chennai;Utilities;Adobe Reader 7;\\ntfp\software\Adobe Reader\AdobeRdr709_Extracted\Adobe Reader 7.0.9.msi", _
            "Chennai;Utilities;Windows Installer 3;\\ntfp\software\Windows Installer 3.1\WindowsInstaller-KB893803-v2-x86.exe", _
            "Hyderabad;Messengers;Windows Messenger;\\server\share\WinMessenger\setup.exe", _
            "Hyderabad;Utilities;Security Test;\\server\share\temp\PS4LICENSE\setup.exe", _
            "Hyderabad;Databases;SQL Server Tools;\\server\share\SQL Server\Tools\setup.exe")
    Populate_Office
End Sub
 
Sub Populate_Office
 
      strHTML = "<select size='1' name='cbo_office' onchange='vbs:Populate_SoftwareType'>" & VbCrLf
      strHTML = strHTML & "<option selected value='cbo_office'> --- Select Office --- </option>" & vbCrLf
      
      strOffices = ";"
      For Each strProduct In arrSoftware
            strOffice = Split(strProduct, ";")(0)
            If InStr(LCase(strOffices), LCase(";" & strOffice & ";")) = 0 Then
                  strOffices = strOffices & strOffice & ";"
                  strHTML = strHTML & "<option value='" & strOffice & "'>" & strOffice & "</option>" & VbCrLf
            End If
      Next
      
      strHTML = strHTML & "</select>"
 
      span_office.InnerHTML = strHTML
 
End Sub
 
Sub Populate_SoftwareType
 
      strHTML = "<select size='1' name='cbo_softwaretype' onchange='vbs:Populate_Application'>" & VbCrLf
      strHTML = strHTML & "<option selected value='cbo_softwaretype'> --- Select Software Type --- </option>" & VbCrLf
      
      strTypes = ";"
      For Each strProduct In arrSoftware
            If LCase(Split(strProduct, ";")(0)) = LCase(cbo_office.Value) Then
                  strType = Split(strProduct, ";")(1)
                  If InStr(LCase(strTypes), LCase(";" & strType & ";")) = 0 Then
                        strTypes = strTypes & strType & ";"
                        strHTML = strHTML & "<option value='" & strType & "'>" & strType & "</option>" & VbCrLf
                  End If
            End If
      Next
      
      strHTML = strHTML & "</select>"
 
      span_softwaretype.InnerHTML = strHTML
 
End Sub
 
Sub Populate_Application
 
      strHTML = "<select size='1' name='cbo_application'>" & VbCrLf
      strHTML = strHTML & "<option selected value='cbo_application'> --- Select Application --- </option>" & VbCrLf
      
      For Each strProduct In arrSoftware
            If LCase(Split(strProduct, ";")(0)) = LCase(cbo_office.Value) And LCase(Split(strProduct, ";")(1)) = LCase(cbo_softwaretype.Value) Then
                  strApplication = Split(strProduct, ";")(2)
                  strFilePath = Split(strProduct, ";")(3)
                  strHTML = strHTML & "<option value='" & strApplication & ";" & strFilePath & "'>" & strApplication & "</option>" & VbCrLf
            End If
      Next
      
      strHTML = strHTML & "</select>"
 
      span_application.InnerHTML = strHTML
 
End Sub
 
Sub Default_Buttons
      If Window.Event.KeyCode = 13 Then
            btn_install.Click
      End If
End Sub
 
Sub Install_Software
      strLogFile = "\\indiasophos\Ps\HTA_Install_Log.csv"
      Const intForAppending = 8
      If cbo_office.Value = "cbo_office" Then
            MsgBox "Please select an office."
            cbo_office.Focus
      ElseIf cbo_softwaretype.Value = "cbo_softwaretype" Then
            MsgBox "Please select a software type."
            cbo_softwaretype.Focus
      ElseIf cbo_application.Value = "cbo_application" Then
            MsgBox "Please select an application."
            cbo_application.Focus
      Else
            strProduct = Split(cbo_application.Value, ";")(0)
            strExecutable = Split(cbo_application.Value, ";")(1)
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            Set objShell = CreateObject("WScript.Shell")
            Set objNetwork = CreateObject("WScript.Network")
            'Software file,Machinename,Username,Date and time
            strDetails = strExecutable & "," & objNetwork.ComputerName & "," & objNetwork.UserName & "," & Now
            If objFSO.FileExists(strExecutable) = True Then
                  'objShell.Run strExecutable
                  If LCase(Right(strExecutable, 4)) = LCase(".msi") Then
                        strCommand = "msiexec /i " & objFSO.GetFile(strExecutable).ShortPath & " /qf /norestart"
                  Else
                        strCommand = "cmd /c """ & objFSO.GetFile(strExecutable).ShortPath & """"
                  End If
                  'MsgBox "Installing: " & strProduct & VbCrLf & "From:" & VbCrLf & strExecutable & VbCrLf & "With: " & strCommand
 
                  strExitCode = objShell.Run(strCommand, 1, True)
 
 
                
                  If Left(strCommand, 7) = "msiexec" And strExitCode = 1619 Then
                        MsgBox "You do not have permission to install this application." & VbCrLf & "Please contact the Help Desk."
                  ElseIf Left(strCommand, 6) = "cmd /c" And strExitCode = 1 Then
                        MsgBox "You do not have permission to install this application." & VbCrLf & "Please contact the Help Desk."
                  End If
                  Set objOutputFile = objFSO.OpenTextFile(strLogFile, intForAppending, True)
                  objOutputFile.WriteLine strDetails
                  objOutputFile.Close
                  Set objOutputFile = Nothing
            Else
                  MsgBox "The file does not exist, or you do not have permission to access it." & VbCrLf & "Please contact the Help Desk."
            End If
            Set objShell = Nothing
            Set objFSO = Nothing
            Set objNetwork = Nothing
      End If
End Sub
 
</script>
 
<body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>
      <table width='90%' height = '100%' align='center' border='0'>
            <tr>
                  <td align="center" colspan="2">
                        <h2>Choose Software To Install</h2>
                  </td>
            </tr>
            <tr>
                  <td align='center'>
                        Choose from the options in each list:
                  </td>
            </tr>
            <tr>
                  <td>
                        Office:
                        <span id="span_office">
                              <select size="1" name="cbo_office">
                                    <option selected value="cbo_office"> --- Select Office --- </option> 
                              </select>
                        </span>
                  </td>
            </tr
            <tr>
                  <td>
                        Software Type:
                        <span id="span_softwaretype">
                              <select size="1" name="cbo_softwaretype">
                                    <option selected value="cbo_softwaretype"> --- Select Software Type --- </option> 
                              </select>
                        </span>
                  </td>
            </tr
            <tr>
                  <td>
                        Application:
                        <span id="span_application">
                              <select size="1" name="cbo_application">
                                    <option selected value="cbo_application"> --- Select Application --- </option> 
                              </select>
                        </span>
                  </td>
            </tr
            <tr>
                  <td align='center' colspan="2">
                        <input type="button" value="Install" name="btn_install"  onClick="vbs:Install_Software"><br><br>
                  </td>
            </tr>
            <tr height='20%'>
                  <td>
                  </td>
            </tr>
      </table>
 
</body>
'=============

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Sharath, the easiest way to do this would be to use a "launcher" hta, which you run first, enter your credentials, then that runs the other HTA.  So, the lines to change are:

            strPSExec = "\\server\share\psexec.exe"
            strHTA = "\\server\share\InstallSoftware.hta"

Where strPSExec points to your executable for PSExec, and strHTA points to the HTA file that you have posted above.

Regards,

Rob.
<html>
<head>
<title>Launch Installation Interface</title>
<style>
</style>
</head>
<HTA:APPLICATION 
     APPLICATIONNAME="Launch Installation Interface"
     SCROLL="No"
     SINGLEINSTANCE="Yes"
     borderstyle="Thin"
     minimizebutton="No"
     maximizebutton="No"
     icon=""
>
</head>
<body onkeypress='vbs:Default_Buttons'>
 
<center>
<br>
<h3>Credentials to Launch Installation Interface</h3>
<br><br>
<b>Domain Credentials:</b><br>
User Name: <input type="text" maxlength="50" size="70" name="txt_username">
<br><br>
Password: <input type="password" maxlength="50" size="70" name="txt_password">
<br><br>
<input type="button" value="Launch Interface" onClick="vbs:LaunchInterface" name="btn_launch">
<br><br>
</center>
 
<SCRIPT Language="VBScript">
 
Sub Window_OnLoad
	intHeight = 380
	intWidth = 600
	Me.ResizeTo intWidth, intHeight
	Me.MoveTo (screen.width / 2) - (intWidth / 2), (screen.height / 2) - (intHeight / 2)
	Set objNetwork = CreateObject("WScript.Network")
	txt_username.Value = objNetwork.UserDomain & "\"
End Sub
 
Sub LaunchInterface
	If Trim(txt_username.Value) = "" Then
		MsgBox "Please enter a username."
		txt_username.Focus
	ElseIf Trim(txt_password.value) = "" Then
		MsgBox "Please enter a password."
		txt_password.Focus
	Else
		strPSExec = "\\server\share\psexec.exe"
		strHTA = "\\server\share\InstallSoftware.hta"
		Set objFSO = CreateObject("Scripting.FileSystemObject")
		Set objNetwork = CreateObject("WScript.Network")
		Set objShell = CreateObject("WScript.Shell")
		strPSExec = objFSO.GetFile(strPSExec).ShortPath
		strHTA = objFSO.GetFile(strHTA).ShortPath
		strCommand = "cmd /c " & strPSExec & " -accepteula -i -u " & txt_username.Value & " -p " & txt_password.Value & " \\" & objNetwork.ComputerName & " mshta.exe " & strHTA
		objShell.Run strCommand, 1, False
		window.Close
	End If
End Sub
 
Sub Default_Buttons
	If Window.Event.KeyCode = 13 Then
		btn_launch.Click
	End If
End Sub
</Script>

Open in new window

Author

Commented:
Thanks Rob. How will the hta understand which credentials to take.
Is it allowed to the permissions on the folders.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
>> How will the hta understand which credentials to take.

Remember the Excel form that we made that asks for credentials?  This basically does the same thing, with the first HTA using PSExec to run the entire second HTA (and therefore any processes initiated by that HTA) under those credentials.

Rob.

Author

Commented:
So this means that.
Who ever have permissions to acess the folder where HTA is there will get the HTA opened and who ever have access to the software paths mentioned in the Software Hta will be able to install the software?

Author

Commented:
So this means that.
Who ever have permissions to acess the folder where HTA is there will get the HTA opened and who ever have access to the software paths mentioned in the Software Hta will be able to install the software?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Not quite.

Anyone will be able to run either HTA, however, because the HTA is running "as that user", then the NTFS permissions on those folders still take effect, so if the user is not allowed to view the folder, the HTA won't be able to access it either.  So, by using alternate credentials, say you use Administrator, then which ever network folders allow NTFS permissions for Administrator, will be able to be accessed by the HTA.

So, even though a normal user could run the first HTA, they still need to know the credentials of a user account with higher privileges.

Regards,

Rob.

Author

Commented:
I just did as said rob but a command windows opens and closes. I have permissions on the folder i have the hta and psexec.exe file.
But does not open the Hta

Author

Commented:
I just did as said rob but a command windows opens and closes. I have permissions on the folder i have the hta and psexec.exe file.
But does not open the Hta
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Please change this line:

strCommand = "cmd /c " & strPSExec & " -accepteula -i -u " & txt_username.Value & " -p " & txt_password.Value & " \\" & objNetwork.ComputerName & " mshta.exe " & strHTA

to this

strCommand = "cmd /k " & strPSExec & " -accepteula -i -u " & txt_username.Value & " -p " & txt_password.Value & " \\" & objNetwork.ComputerName & " mshta.exe " & strHTA

and also after that line, put

InputBox "Prompt", "Title", strCommand

so we can see whether the PSExec command is formed correctly.

Rob.

Author

Commented:
Rob i get this
 

---------------------------
Error
---------------------------
A Runtime Error has occurred.
Do you wish to Debug?
Line: 56
Error: Object doesn't support this property or method: 'objFSO.GetFile(...).ShortPathstrCommand'
---------------------------
Yes   No  
---------------------------
 

Author

Commented:
Rob i get this
 

---------------------------
Error
---------------------------
A Runtime Error has occurred.
Do you wish to Debug?
Line: 56
Error: Object doesn't support this property or method: 'objFSO.GetFile(...).ShortPathstrCommand'
---------------------------
Yes   No  
---------------------------
 
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
There should be a line feed in
ShortPathstrCommand

between
ShortPath
and
strCommand

Please separate the line there.

Regards,

Rob.

Author

Commented:
I get this
 
cmd /k \\dev-ch-m01\new folder\psexec.exe -accepteula -i -u DEVELOPMENT\sharath -p bs \\DEV-CH-M01 mshta.exe \\dev-ch-m01\new folder\SOFTWA~1.HTA

Author

Commented:
I get this
 
cmd /k \\dev-ch-m01\new folder\psexec.exe -accepteula -i -u DEVELOPMENT\sharath -p bs \\DEV-CH-M01 mshta.exe \\dev-ch-m01\new folder\SOFTWA~1.HTA

Author

Commented:
In the end the cmsd prompt shows this
The network name cannot be found.

Author

Commented:
Hi Rob,
Any hep with this and other posts... :-)
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
I am very surprised there is a space there....

This:
\\dev-ch-m01\new folder\psexec.exe

should have become
\\dev-ch-m01\newfol~1\psexec.exe

because this line exists, which must remain unchanged:
strPSExec = objFSO.GetFile(strPSExec).ShortPath

Make sure you only edit the strPSExec and strHTA values *within* this section.

      ElseIf Trim(txt_password.value) = "" Then
            MsgBox "Please enter a password."
            txt_password.Focus
      Else
            strPSExec = "\\server\share\psexec.exe"
            strHTA = "\\server\share\InstallSoftware.hta"
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            Set objNetwork = CreateObject("WScript.Network")
            Set objShell = CreateObject("WScript.Shell")


*After* the above code, you'll see

            strPSExec = objFSO.GetFile(strPSExec).ShortPath
            strHTA = objFSO.GetFile(strHTA).ShortPath

but they MUST remain the same.

Regards,

Rob.

Author

Commented:
Rob the lines are as...
Sub LaunchInterface
	If Trim(txt_username.Value) = "" Then
		MsgBox "Please enter a username."
		txt_username.Focus
	ElseIf Trim(txt_password.value) = "" Then
		MsgBox "Please enter a password."
		txt_password.Focus
	Else
		strPSExec = "\\dev-ch-m01\New Folder\psexec.exe"
		strHTA = "\\dev-ch-m01\New Folder\Softwarever3.hta"
		Set objFSO = CreateObject("Scripting.FileSystemObject")
		Set objNetwork = CreateObject("WScript.Network")
		Set objShell = CreateObject("WScript.Shell")
		strPSExec = objFSO.GetFile(strPSExec).ShortPath
		strHTA = objFSO.GetFile(strHTA).ShortPath
strCommand = "cmd /k " & strPSExec & " -accepteula -i -u " & txt_username.Value & " -p " & txt_password.Value & " \\" & objNetwork.ComputerName & " mshta.exe " & strHTA
InputBox "Prompt", "Title", strCommand
		objShell.Run strCommand, 1, False
		window.Close

Open in new window

Author

Commented:
Rob the lines are as...
Sub LaunchInterface
	If Trim(txt_username.Value) = "" Then
		MsgBox "Please enter a username."
		txt_username.Focus
	ElseIf Trim(txt_password.value) = "" Then
		MsgBox "Please enter a password."
		txt_password.Focus
	Else
		strPSExec = "\\dev-ch-m01\New Folder\psexec.exe"
		strHTA = "\\dev-ch-m01\New Folder\Softwarever3.hta"
		Set objFSO = CreateObject("Scripting.FileSystemObject")
		Set objNetwork = CreateObject("WScript.Network")
		Set objShell = CreateObject("WScript.Shell")
		strPSExec = objFSO.GetFile(strPSExec).ShortPath
		strHTA = objFSO.GetFile(strHTA).ShortPath
strCommand = "cmd /k " & strPSExec & " -accepteula -i -u " & txt_username.Value & " -p " & txt_password.Value & " \\" & objNetwork.ComputerName & " mshta.exe " & strHTA
InputBox "Prompt", "Title", strCommand
		objShell.Run strCommand, 1, False
		window.Close

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
That's odd....can you rename the "New Folder" share to a name with no spaces, and try again?

Author

Commented:
Ha thanks Rob now i get this working.
Now what all shall i remove to not get the popup's
Can i have the compant name in the right corner.
 

Author

Commented:
Ha thanks Rob now i get this working.
Now what all shall i remove to not get the popup's
Can i have the compant name in the right corner.
 
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks Rob worked perfect.Any help with the 2 posts with the small changes

Author

Commented:
Thanks Rob worked perfect.Any help with the 2 posts with the small changes

Author

Commented:
Hi Rob here is a related post please have a look
https://www.experts-exchange.com/Programming/Languages/Q_26239093.html

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.