Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Install Software through HTA. Need to set permission

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

Avatar of RobSampson
RobSampson
Flag of Australia image

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

Avatar of bsharath

ASKER

Thanks Rob. How will the hta understand which credentials to take.
Is it allowed to the permissions on the folders.
>> 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.
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?
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?
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.
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
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
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.
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  
---------------------------
 
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  
---------------------------
 
There should be a line feed in
ShortPathstrCommand

between
ShortPath
and
strCommand

Please separate the line there.

Regards,

Rob.
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
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
In the end the cmsd prompt shows this
The network name cannot be found.
Hi Rob,
Any hep with this and other posts... :-)
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.
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

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

That's odd....can you rename the "New Folder" share to a name with no spaces, and try again?
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.
 
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.
 
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Rob worked perfect.Any help with the 2 posts with the small changes
Thanks Rob worked perfect.Any help with the 2 posts with the small changes