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 arrSoftwareSub 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_OfficeEnd SubSub 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 = strHTMLEnd SubSub 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 = strHTMLEnd SubSub 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 = strHTMLEnd SubSub Default_Buttons If Window.Event.KeyCode = 13 Then btn_install.Click End IfEnd SubSub 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 IfEnd 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>'=============
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.
>> 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.
bsharath
ASKER
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?
RobSampson
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.
bsharath
ASKER
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
so we can see whether the PSExec command is formed correctly.
Rob.
bsharath
ASKER
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 Â
---------------------------
Â
---------------------------
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 Â
---------------------------
Â
RobSampson
There should be a line feed in
ShortPathstrCommand
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.
bsharath
ASKER
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).ShortPathstrCommand = "cmd /k " & strPSExec & " -accepteula -i -u " & txt_username.Value & " -p " & txt_password.Value & " \\" & objNetwork.ComputerName & " mshta.exe " & strHTAInputBox "Prompt", "Title", strCommand objShell.Run strCommand, 1, False window.Close
           strPSExec = "\\server\share\psexec.exe
           strHTA = "\\server\share\InstallSof
Where strPSExec points to your executable for PSExec, and strHTA points to the HTA file that you have posted above.
Regards,
Rob.
Open in new window