Link to home
Start Free TrialLog in
Avatar of Dhiraj Mutha
Dhiraj MuthaFlag for United States of America

asked on

Easy Access Toolbar

Hi All,

I am working on a VBScript project called 'Easy Access Toolbar'. Which is a mixture of HTA and VBScript. I am althrough with it and having some problem at two of the places. First let me let u know what it is exactly.
There is a HTA file, once double clicked on it, it will ask for username and password (i will enter my domain admin credtianls). Once entered and clicked ok, it will open a another HTA, which will look like a Toolbar. I will have all the required applications on it. Once clicked on the buttons it will open a associated application.

Now what i need is:
1) Once click on one button it should open another HTA ---> How to do that?
2) Once clicked on one more button how to open MMC using my domain crediantials as we have blocked MMC in our environment and will open only with our domain crediatials.

<html>
 
<head>
    <title>Easy Access Toolbar</title>
	<HTA:APPLICATION 
     APPLICATIONNAME="Easy Access Toolbar"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
     Icon="./Images/icon.ico"
     Maximizebutton="no"
     ContextMenu="no"
>
</head>
 
<Script Language="VBScript">
    Sub Window_Onload
	  intWidth = 500
      intHeight = 100
      Me.ResizeTo intWidth, intHeight
      Me.MoveTo ((Screen.Width) - (intWidth)),((Screen.Height / 11) - (intHeight))
        DellButton.Width = 64
        DellButton.Height = 64
        DellButton.Picture = LoadPicture("c:\dell.bmp")
    End Sub
   
    Sub DellButton_Click()
		'Second HTA Code Here
		
    End Sub
</Script>
 
<body topmargin="0" rightmargin="0" leftmargin="0">
 
<table width="100%" border="1" width="100%" bordercolorlight="buttonface" 
bordercolordark="buttonface" style="border-collapse:collapse">
   <tr>
        <td width="100%" bgcolor="buttonface">
            <object classid="clsid:D7053240-CE69-11CD-A777-00DD01143C57" id="DellButton"></object>
       </td>
    </tr>
<table>
 
<p>&nbsp;<p>
<blockquote>
 
<span id=DataArea></span>
 
</blockquote>
</body>
</html>

Open in new window

Avatar of RobSampson
RobSampson
Flag of Australia image

Hi there, try this.

For point 1, we use the executable MSHTA.exe to run another HTA.

For point 2, we use PSExec to run "MMC C:\windows\system32\compmgmt.msc"

You need to change
strHTAPath = "\\server\share\OtherHTA.hta"

to point to the second HTA you want to run, and you need to change
strPSExecPath = "\\server\share\psexec.exe"

to point to where you  have PSExec.exe

Regards,

Rob.
<html>
 
<head>
    <title>Easy Access Toolbar</title>
	<HTA:APPLICATION 
     APPLICATIONNAME="Easy Access Toolbar"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
     Icon="./Images/icon.ico"
     Maximizebutton="no"
     ContextMenu="no"
>
</head>
 
<Script Language="VBScript">
    Sub Window_Onload
	  intWidth = 500
      intHeight = 100
      Me.ResizeTo intWidth, intHeight
      Me.MoveTo ((Screen.Width) - (intWidth)),((Screen.Height / 11) - (intHeight))
        DellButton.Width = 64
        DellButton.Height = 64
        DellButton.Picture = LoadPicture("c:\dell.bmp")
    End Sub
   
    Sub DellButton_Click()
		'Second HTA Code Here
		
    End Sub
    
    Sub Run_HTA
		Set objShell = CreateObject("WScript.Shell")
		strHTAPath = "\\server\share\OtherHTA.hta"
		strCommand = "mshta.exe """ & strHTAPath & """"
		objShell.Run strCommand, 1, False
    End Sub
    
    Sub Run_MMC
    	Set objFSO = CreateObject("Scripting.FileSystemObject")
    	Set objNetwork = CreateObject("WScript.Network")
    	Set objShell = CreateObject("WScript.Shell")
    	strPSExecPath = "\\server\share\psexec.exe"
    	strPSExecPath = objFSO.GetFile(strPSExecPath).ShortPath
    	strUser = InputBox("Enter user name (eg. DOMAIN\User):", "Username")
    	strPass = InputBox("Enter password:", "Password")
    	strComputer = objNetwork.ComputerName
    	strCommand = "cmd /c " & strPSExecPath & " -accepteula -i -d -u " & strUser & " -p " & strPass & " \\" & strComputer & " mmc c:\windows\system32\compmgmt.msc"
    	objShell.Run strCommand, 0, False
    End Sub
</Script>
 
<body topmargin="0" rightmargin="0" leftmargin="0">
 
<table width="100%" border="1" width="100%" bordercolorlight="buttonface" 
bordercolordark="buttonface" style="border-collapse:collapse">
   <tr>
        <td width="100%" bgcolor="buttonface">
            <object classid="clsid:D7053240-CE69-11CD-A777-00DD01143C57" id="DellButton"></object>
       </td>
       <td width="100%" bgcolor="buttonface" align="center">
            <input type="button" value="Run HTA" name="btn_runhta"  onClick="vbs:Run_HTA" style="font-size: 16px;">
       </td>
       <td width="100%" bgcolor="buttonface" align="center">
            <input type="button" value="Run MMC" name="btn_runmmc"  onClick="vbs:Run_MMC" style="font-size: 16px;">
       </td>
    </tr>
<table>
 
<p>&nbsp;<p>
<blockquote>
 
<span id=DataArea></span>
 
</blockquote>
</body>
</html>

Open in new window

Avatar of Dhiraj Mutha

ASKER

You are a STAR Rob.... Thanks for the support.
The other HTA part is working super cool... even MMC is working. My only concern is that it is asking for username and password.
I am using one more HTA (this HTA only has a usrename & password field, once entered my Domain Admin Credentials it will open the Easy Access Toolbar).
Can we use the same username and password for MMC to open.
I have pasted the code of the other HTA. (This is your code Rob, what i am using)

<html>
<head>
<title>Run Program With Alternate Credentials</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Run Program With Alternate Credentials"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
 
<script language="VBScript">
 
Dim strPSExecPath
Dim strComputer
Dim strSecondHTAPath
 
Sub Window_onLoad
	intWidth = 600
	intHeight = 480
	Me.ResizeTo intWidth, intHeight
    Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If Mid(document.location, 6, 3) = "///" Then
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
    Else
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
    End If
    strPSExecPath = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "psexec.exe"
    strSecondHTAPath = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "TestHTA2.hta"
    'strSecondHTAPath = "C:\cit.hta"
    If objFSO.FileExists(strPSExecPath) Then
    	strPSExecPath = objFSO.GetFile(strPSExecPath).ShortPath
    Else
    	MsgBox "Could not find PSExec at:" & VbCrLf & strPSExecPath
    	Window.Close
    End If
    Set objNetwork = CreateObject("WScript.Network")
    strComputer = objNetwork.ComputerName
    
    txt_username.Focus
End Sub
 
Sub Default_Buttons
	If Window.Event.KeyCode = 13 Then
		btn_submit.Click
	End If
End Sub
 
Sub Run_Second_HTA
	If txt_username.Value = "" Then
		MsgBox "Please enter a user name."
		txt_username.Focus
	ElseIf txt_password.Value = "" Then
		MsgBox "Please enter a password."
		txt_password.Focus
	Else
		Set objShell = CreateObject("WScript.Shell")
		strUser = txt_username.Value
		strPass = txt_password.Value
		If Right(LCase(strSecondHTAPath), 4) = ".hta" Then
			strCommand = strPSExecPath & " -accepteula -i -d -u " & strUser & " -p " & strPass & " \\" & strComputer & " mshta.exe """ & strSecondHTAPath & """"
		Else
			strCommand = strPSExecPath & " -accepteula -i -d -u " & strUser & " -p " & strPass & " \\" & strComputer & " """ & strSecondHTAPath & """"
		End If
		' MsgBox strCommand
		' Exit Code 1326 is invalid password from PSExec 1.85
		strExitCode = objShell.Run(strCommand, 0, True)
		If strExitCode = 1326 Then
			MsgBox "Username or Password invalid. Please verify your credentials."
			txt_password.Value = ""
			txt_password.Focus
		Else
			window.close
		End If
	End If
End Sub
 
</script>
</head>
<body style="background-color:#B0C4DE" onkeypress='vbs:Default_Buttons'>
	<table width='90%' height='100%' align='center' border='0'>
		<tr>
			<td align="center" style="font-family: arial; font-size: 24px; font-weight: bold;">
				Run Program With Alternate Credentials
			</td>
		</tr>
		<tr>
			<td align='center' style="font-family: arial; font-size: 16px; font-weight: bold;">
				Enter username: <input type="text" maxlength="30" size="40" id="txt_username" name="txt_username" style="font-size: 14px;"><BR><BR>
				Enter password: <input type="password" maxlength="30" size="40" id="txt_password" name="txt_password" style="font-size: 14px;"><BR>
				<br>Note: Username must be DOMAIN\UserName
			</td>
		</tr>
		<tr>
			<td align='center'>
				<input type="button" value="Go!" name="btn_submit"  onClick="vbs:Run_Second_HTA" style="font-size: 16px;"><br><br>
			</td>
		</tr>
	</table>
</body>
</html>

Open in new window

OK sure, if you want to use the HTA you just posted, I've just added another button for the MMC.

Regards,

Rob.
<html>
<head>
<title>Run Program With Alternate Credentials</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Run Program With Alternate Credentials"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
 
<script language="VBScript">
 
Dim strPSExecPath
Dim strComputer
Dim strSecondHTAPath
 
Sub Window_onLoad
	intWidth = 600
	intHeight = 480
	Me.ResizeTo intWidth, intHeight
    Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If Mid(document.location, 6, 3) = "///" Then
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
    Else
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
    End If
    strPSExecPath = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "psexec.exe"
    strSecondHTAPath = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "TestHTA2.hta"
    'strSecondHTAPath = "C:\cit.hta"
    If objFSO.FileExists(strPSExecPath) Then
    	strPSExecPath = objFSO.GetFile(strPSExecPath).ShortPath
    Else
    	MsgBox "Could not find PSExec at:" & VbCrLf & strPSExecPath
    	Window.Close
    End If
    Set objNetwork = CreateObject("WScript.Network")
    strComputer = objNetwork.ComputerName
    
    txt_username.Focus
End Sub
 
Sub Default_Buttons
	If Window.Event.KeyCode = 13 Then
		btn_submit.Click
	End If
End Sub
 
Sub Run_Second_HTA
	If txt_username.Value = "" Then
		MsgBox "Please enter a user name."
		txt_username.Focus
	ElseIf txt_password.Value = "" Then
		MsgBox "Please enter a password."
		txt_password.Focus
	Else
		Set objShell = CreateObject("WScript.Shell")
		strUser = txt_username.Value
		strPass = txt_password.Value
		If Right(LCase(strSecondHTAPath), 4) = ".hta" Then
			strCommand = strPSExecPath & " -accepteula -i -d -u " & strUser & " -p " & strPass & " \\" & strComputer & " mshta.exe """ & strSecondHTAPath & """"
		Else
			strCommand = strPSExecPath & " -accepteula -i -d -u " & strUser & " -p " & strPass & " \\" & strComputer & " """ & strSecondHTAPath & """"
		End If
		' MsgBox strCommand
		' Exit Code 1326 is invalid password from PSExec 1.85
		strExitCode = objShell.Run(strCommand, 0, True)
		If strExitCode = 1326 Then
			MsgBox "Username or Password invalid. Please verify your credentials."
			txt_password.Value = ""
			txt_password.Focus
		Else
			window.close
		End If
	End If
 
    Sub Run_MMC
		If txt_username.Value = "" Then
			MsgBox "Please enter a user name."
			txt_username.Focus
		ElseIf txt_password.Value = "" Then
			MsgBox "Please enter a password."
			txt_password.Focus
		Else
	    	Set objFSO = CreateObject("Scripting.FileSystemObject")
	    	Set objNetwork = CreateObject("WScript.Network")
	    	Set objShell = CreateObject("WScript.Shell")
	    	strPSExecPath = "\\server\share\psexec.exe"
	    	strPSExecPath = objFSO.GetFile(strPSExecPath).ShortPath
	    	strUser = txt_username.Value
	    	strPass = txt_password.Value
	    	strComputer = objNetwork.ComputerName
	    	strCommand = "cmd /c " & strPSExecPath & " -accepteula -i -d -u " & strUser & " -p " & strPass & " \\" & strComputer & " mmc c:\windows\system32\compmgmt.msc"
	    	objShell.Run strCommand, 0, False
	    End If
    End Sub
 
End Sub
 
</script>
</head>
<body style="background-color:#B0C4DE" onkeypress='vbs:Default_Buttons'>
	<table width='90%' height='100%' align='center' border='0'>
		<tr>
			<td align="center" style="font-family: arial; font-size: 24px; font-weight: bold;">
				Run Program With Alternate Credentials
			</td>
		</tr>
		<tr>
			<td align='center' style="font-family: arial; font-size: 16px; font-weight: bold;">
				Enter username: <input type="text" maxlength="30" size="40" id="txt_username" name="txt_username" style="font-size: 14px;"><BR><BR>
				Enter password: <input type="password" maxlength="30" size="40" id="txt_password" name="txt_password" style="font-size: 14px;"><BR>
				<br>Note: Username must be DOMAIN\UserName
			</td>
		</tr>
		<tr>
			<td align='center'>
				<input type="button" value="Run HTA" name="btn_submit"  onClick="vbs:Run_Second_HTA" style="font-size: 16px;"><br><br>
				<input type="button" value="Run MMC" name="btn_runmmc"  onClick="vbs:Run_MMC" style="font-size: 16px;"><br><br>
			</td>
		</tr>
	</table>
</body>
</html>

Open in new window

No Rob... i understand what you are saying... but will require to run MMC from the other HTA. is that possible?
Also one more thing... after closing the Toolbar PSEXEC process in taskmanager is still running.
OK, try this....I added a username and password to your original HTA.

Regards,

Rob.
<html>
 
<head>
    <title>Easy Access Toolbar</title>
	<HTA:APPLICATION 
     APPLICATIONNAME="Easy Access Toolbar"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
     Icon="./Images/icon.ico"
     Maximizebutton="no"
     ContextMenu="no"
>
</head>
 
<Script Language="VBScript">
    Sub Window_Onload
	  intWidth = 700
      intHeight = 110
      Me.ResizeTo intWidth, intHeight
      'Me.MoveTo ((Screen.Width) - (intWidth)),((Screen.Height / 11) - (intHeight))
      Me.MoveTo ((Screen.Width) - (intWidth)),(0)
        DellButton.Width = 64
        DellButton.Height = 64
        DellButton.Picture = LoadPicture("c:\dell.bmp")
    End Sub
   
    Sub DellButton_Click()
		'Second HTA Code Here
		
    End Sub
    
    Sub Run_HTA
		Set objShell = CreateObject("WScript.Shell")
		strHTAPath = "\\server\share\OtherHTA.hta"
		strCommand = "mshta.exe """ & strHTAPath & """"
		objShell.Run strCommand, 1, False
    End Sub
    
    Sub Run_MMC
    	Set objFSO = CreateObject("Scripting.FileSystemObject")
    	Set objNetwork = CreateObject("WScript.Network")
    	Set objShell = CreateObject("WScript.Shell")
    	strPSExecPath = "\\server\share\psexec.exe"
    	strPSExecPath = objFSO.GetFile(strPSExecPath).ShortPath
    	strUser = txt_username.Value
    	strPass = txt_password.Value
    	strComputer = objNetwork.ComputerName
    	strCommand = strPSExecPath & " -accepteula -i -d -u " & strUser & " -p " & strPass & " \\" & strComputer & " mmc c:\windows\system32\compmgmt.msc"
    	objShell.Run strCommand, 0, False
    End Sub
</Script>
 
<body topmargin="0" rightmargin="0" leftmargin="0">
 
<table border="1" width="100%" bordercolorlight="buttonface" 
bordercolordark="buttonface" style="border-collapse:collapse">
   <tr>
        <td width="10%" bgcolor="buttonface">
            <object classid="clsid:D7053240-CE69-11CD-A777-00DD01143C57" id="DellButton"></object>
       </td>
		<td align='center' bgcolor="buttonface" width="70%">
			Enter username: <input type="text" maxlength="30" size="40" id="txt_username" name="txt_username" style="font-size: 14px;"><BR>
			Enter password: <input type="password" maxlength="30" size="40" id="txt_password" name="txt_password" style="font-size: 14px;"><BR>
			Note: Username must be DOMAIN\UserName
		</td>
 
       <td bgcolor="buttonface" align="center">
            <input type="button" value="Run HTA" name="btn_runhta"  onClick="vbs:Run_HTA" style="font-size: 16px;">
       </td>
       <td width="100%" bgcolor="buttonface" align="center">
            <input type="button" value="Run MMC" name="btn_runmmc"  onClick="vbs:Run_MMC" style="font-size: 16px;">
       </td>
    </tr>
<table>
 
<p>&nbsp;<p>
<blockquote>
 
<span id=DataArea></span>
 
</blockquote>
</body>
</html>

Open in new window

I will check and let you know. but it would have been great if you would have done something for my exact request.
Sorry I'm not sure exactly what you mean....I have added the ability to enter username and password into the original HTA that you posted.  If that was incorrect, can you please let me the post id that has the code here, that you want the MCC to run from?

Are you saying that you have your HTA (the original code) with a button to run the other HTA, then *on the other HTA* you want the button to run the MMC instead?  Sorry if I do not understand...

Regards,

Rob.
Yes you are right... I have the HTA with a option to enter user id and password with a button (my second post with the code - your code) which will open other HTA and i want the button on the that (the orginal post - the code which i posted first) to run mmc.
 
Open a HTA > That will ask username and password > Click on Run > That will close the first HTA and open other HTA (Easy Access Toolbar) > With all the buttons on it including MMC.
Any updates on this mate?
Hi, so if you use this as HTA 1 (to be able to run the second HTA with alternate credentials), is that right?

You need to change:
    strPSExecPath = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "psexec.exe"
    strSecondHTAPath = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "TestHTA2.hta"

to point to PSExec.exe, and the second HTA.

In the following post I'll post the HTA that strSecondHTAPath refers to.

Regards,

Rob.
<html>
<head>
<title>Run Program With Alternate Credentials</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Run Program With Alternate Credentials"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
 
<script language="VBScript">
 
Dim strPSExecPath
Dim strComputer
Dim strSecondHTAPath
 
Sub Window_onLoad
	intWidth = 600
	intHeight = 480
	Me.ResizeTo intWidth, intHeight
    Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If Mid(document.location, 6, 3) = "///" Then
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
    Else
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
    End If
    strPSExecPath = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "psexec.exe"
    strSecondHTAPath = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "TestHTA2.hta"
    'strSecondHTAPath = "C:\cit.hta"
    If objFSO.FileExists(strPSExecPath) Then
    	strPSExecPath = objFSO.GetFile(strPSExecPath).ShortPath
    Else
    	MsgBox "Could not find PSExec at:" & VbCrLf & strPSExecPath
    	Window.Close
    End If
    Set objNetwork = CreateObject("WScript.Network")
    strComputer = objNetwork.ComputerName
    
    txt_username.Focus
End Sub
 
Sub Default_Buttons
	If Window.Event.KeyCode = 13 Then
		btn_submit.Click
	End If
End Sub
 
Sub Run_Second_HTA
	If txt_username.Value = "" Then
		MsgBox "Please enter a user name."
		txt_username.Focus
	ElseIf txt_password.Value = "" Then
		MsgBox "Please enter a password."
		txt_password.Focus
	Else
		Set objShell = CreateObject("WScript.Shell")
		strUser = txt_username.Value
		strPass = txt_password.Value
		If Right(LCase(strSecondHTAPath), 4) = ".hta" Then
			strCommand = strPSExecPath & " -accepteula -i -d -u " & strUser & " -p " & strPass & " \\" & strComputer & " mshta.exe """ & strSecondHTAPath & """"
		Else
			strCommand = strPSExecPath & " -accepteula -i -d -u " & strUser & " -p " & strPass & " \\" & strComputer & " """ & strSecondHTAPath & """"
		End If
		' MsgBox strCommand
		' Exit Code 1326 is invalid password from PSExec 1.85
		strExitCode = objShell.Run(strCommand, 0, True)
		If strExitCode = 1326 Then
			MsgBox "Username or Password invalid. Please verify your credentials."
			txt_password.Value = ""
			txt_password.Focus
		Else
			window.close
		End If
	End If
End Sub
 
</script>
</head>
<body style="background-color:#B0C4DE" onkeypress='vbs:Default_Buttons'>
	<table width='90%' height='100%' align='center' border='0'>
		<tr>
			<td align="center" style="font-family: arial; font-size: 24px; font-weight: bold;">
				Run Program With Alternate Credentials
			</td>
		</tr>
		<tr>
			<td align='center' style="font-family: arial; font-size: 16px; font-weight: bold;">
				Enter username: <input type="text" maxlength="30" size="40" id="txt_username" name="txt_username" style="font-size: 14px;"><BR><BR>
				Enter password: <input type="password" maxlength="30" size="40" id="txt_password" name="txt_password" style="font-size: 14px;"><BR>
				<br>Note: Username must be DOMAIN\UserName
			</td>
		</tr>
		<tr>
			<td align='center'>
				<input type="button" value="Run HTA" name="btn_submit"  onClick="vbs:Run_Second_HTA" style="font-size: 16px;"><br><br>
			</td>
		</tr>
	</table>
</body>
</html>

Open in new window

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
Excellent......... this worked super fine..... you a a super star...
Great. Thanks for the grade.

Rob.