Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with a simple script hta.

Status
Not open for further replies.

knightr1701

Technical User
Jul 27, 2011
7
US
I am trying to make a HTA script to open windows functions through a button environment. Example is I want to open some control panel windows, msconfig, and command line prompts like ipconfig /release. I don't need a complex script just simple. But my problem is that I can't get certian control panel items to open or programs like system restores exe rstrui.exe but i get a error that rstrui.exe can't be found or msconfig can't be found. I am including the script. thanks for any help. Everything is working below except case line 20 and rstrui.exe wich I removed for the moment because it doesn't work.

Code:
<HTML> 
<HEAD> 
<TITLE>Kelly's Control Panel</TITLE> 

<OBJECT ID="oShell" 
CLASSID="clsid:13709620-C279-11CE-A49E-444553540000"> 
</OBJECT> 

<STYLE> 
INPUT {width: 200} 
</STYLE> 

<SCRIPT LANGUAGE="VBScript"> 
<!-- 
function fnStart(sMethod) 
select case sMethod 
case 0 
'Minimizes all windows on the desktop 
oShell.MinimizeAll 
case 1 
'Displays the Run dialog box 
oShell.FileRun
case 2 
'Displays the Programs and Features dialog box 
oShell.ControlPanelItem "appwiz.cpl" 
case 3 
'Displays the Services dialog box 
oShell.ShellExecute "services.msc" 
case 4 
'Displays the Date/Time dialog box 
oShell.SetTime 
case 5 
'Displays the Internet Properties dialog box 
oShell.ControlPanelItem "INETCPL.cpl" 
case 6 
'Displays the Device Manager dialog box 
oShell.ShellExecute "devmgmt.msc" 
case 7 
'Displays the Disk Cleanup dialog box 
oShell.ShellExecute "cleanmgr"  
case 8 
'Opens the Users Folder 
oShell.ShellExecute "c:\users"
case 9 
'Displays the Taskbar Properties dialog box 
oShell.TrayProperties
case 10
'Displays the Windows Update dialog box
oShell.ShellExecute "wuapp.exe" 
case 11
'Displays the Command Prompt dialog box
oShell.ShellExecute "cmd"
case 12
'Displays the Full Control Panel dialog box
oShell.ShellExecute "control"
case 13
'Displays the Disk Management dialog box
oShell.ShellExecute "diskmgmt.msc"
case 14
'Displays the Screen Resolution dialog box
oShell.ControlPanelItem "desk.cpl"
case 15
'Displays the Event Viewer dialog box
oShell.ShellExecute "eventvwr.msc"
case 16
'Displays the Power Configuration dialog box
oShell.ControlPanelItem "powercfg.cpl"
case 17
'Displays the Registry Editor dialog box
oShell.ShellExecute "regedit"
case 18
'Displays the System properties dialog box
oShell.ControlPanelItem "sysdm.cpl"
case 19
'Displays the Action Center dialog box
oShell.ControlPanelItem "wscui.cpl"
case 20
'Displays the Msconfig dialog box
oShell.ShellExecute "msconfig"
end select 
end function 
--> 
</SCRIPT> 

</HEAD> 

<BODY> 

<H1>Control Panel Shortcuts</H1>
<INPUT type="button" value="MsConfig" onclick="fnStart(20)">
<INPUT type="button" value="Action Center" onclick="fnStart(19)"><br>
<INPUT type="button" value="System Properties" onclick="fnStart(18)">
<INPUT type="button" value="Reg Edit" onclick="fnStart(17)">
<INPUT type="button" value="Power Configuration" onclick="fnStart(16)">
<INPUT type="button" value="Event Viewer" onclick="fnStart(15)">
<INPUT type="button" value="Screen Resolution" onclick="fnStart(14)"><br>
<INPUT type="button" value="Disk Management" onclick="fnStart(13)">
<INPUT type="button" value="Full Control Panel" onclick="fnStart(12)">
<INPUT type="button" value="Command Prompt" onclick="fnStart(11)">
<INPUT type="button" value="Windows Update" onclick="fnStart(10)"> 
<INPUT type="button" value="Edit Taskbar Properties" onclick="fnStart(9)"><br> 
<INPUT type="button" value="Users Accounts Folder" onclick="fnStart(8)"> 
<INPUT type="button" value="Disk Cleanup" onclick="fnStart(7)"> 
<INPUT type="button" value="Device Manager" onclick="fnStart(6)"> 
<INPUT type="button" value="Modify Internet Properties" onclick="fnStart(5)">
<INPUT type="button" value="Set System Time" onclick="fnStart(4)"><br> 
<INPUT type="button" value="Services" onclick="fnStart(3)"> 
<INPUT type="button" value="Programs and Features" onclick="fnStart(2)"> 
<INPUT type="button" value="Run" onclick="fnStart(1)"> 
<INPUT type="button" value="Minimize All Windows" onclick="fnStart(0)"> 
</BODY> 
</HTML>
 
Funny, msconfig opens on my XP machine using that script.

By default, msconfig.exe is found here:
C:\WINDOWS\PCHealth\HelpCtr\Binaries\MSConfig.exe

You may need to put the full path to get it to work. If you want the script to be more robust, this location is actually stored in the reg key below, so you could read the key to get the location on the given computer:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSCONFIG.EXE
 
And the path to rstrui.exe (by default) is C:\WINDOWS\system32\Restore
 
Added note. This is for Windows 7 64 bit, User Account Control is turned off. Thanks for letting me know that it works in windows XP. But this is more needed for xp, Vista 32/64, & Windows 7 32/64. The 64 bit is my problem. I need help to get arround it. Thanks.
 
OK got more info. You guys gave me a point of reference. Since my script worked on XP I went and did some research on 32 bit hta to a 64 bit hta. I haven't found a 64 bit hta solution but I did get a reference to open the hta with 64 bit internet explorer. Guess what it worked when I did it that way. So now the question comes down to is there a way to make a hta run 64 bit?
 
I have a new problem. I have tried many different ways of getting line 23. I can't get a command line instruction to work either. Could someone please help me with the scripting. I have always used autoit which works great but I have too make it in VBsripting and I don't know enough about the commands. Any help would greatly be appreciated. I am pasting the code.

Code:
<HTML> 
<HEAD> 
<TITLE>Kelly's Control Panel</TITLE> 

<OBJECT ID="Shell" 
CLASSID="clsid:13709620-C279-11CE-A49E-444553540000"> 
</OBJECT> 

<STYLE> 
INPUT {width: 200} 
</STYLE> 

<SCRIPT LANGUAGE="VBScript" type="text/vbscript"> 
<!-- 
function fnStart(sMethod) 
select case sMethod 
case 0 
'Minimizes all windows on the desktop 
Shell.MinimizeAll 
case 1 
'Displays the Run dialog box 
Shell.FileRun
case 2 
'Displays the Programs and Features dialog box 
Shell.ControlPanelItem "appwiz.cpl" 
case 3 
'Displays the Services dialog box 
Shell.ShellExecute "services.msc" 
case 4 
'Displays the Date/Time dialog box 
Shell.SetTime 
case 5 
'Displays the Internet Properties dialog box 
Shell.ControlPanelItem "INETCPL.cpl" 
case 6 
'Displays the Device Manager dialog box 
Shell.ShellExecute "devmgmt.msc" 
case 7 
'Displays the Disk Cleanup dialog box 
Shell.ShellExecute "cleanmgr"  
case 8 
'Opens the Users Folder 
Shell.ShellExecute "c:\users"
case 9 
'Displays the Taskbar Properties dialog box 
Shell.TrayProperties
case 10
'Displays the Windows Update dialog box
Shell.ShellExecute "wuapp.exe" 
case 11
'Displays the Command Prompt dialog box
Shell.ShellExecute "cmd"
case 12
'Displays the Full Control Panel dialog box
Shell.ShellExecute "control"
case 13
'Displays the Disk Management dialog box
Shell.ShellExecute "diskmgmt.msc"
case 14
'Displays the Screen Resolution dialog box
Shell.ControlPanelItem "desk.cpl"
case 15
'Displays the Event Viewer dialog box
Shell.ShellExecute "eventvwr.msc"
case 16
'Displays the Power Configuration dialog box
Shell.ControlPanelItem "powercfg.cpl"
case 17
'Displays the Registry Editor dialog box
Shell.ShellExecute "regedit"
case 18
'Displays the System properties dialog box
Shell.ControlPanelItem "sysdm.cpl"
case 19
'Displays the Action Center dialog box
Shell.ControlPanelItem "wscui.cpl"
case 20
'Displays the Msconfig dialog box
Shell.ShellExecute "C:\Windows\System32\msconfig.exe"
case 21
'Displays the System Restore dialog box
Shell.ShellExecute "rstrui.exe"
case 22
'Displays the Task Manager dialog box
Shell.ShellExecute "c:\windows\system32\taskmgr.exe"
case 23
'Displays the User Account Control dialog box
Shell.ShellExecute "control.exe nusrmgr.cpl"
end select 
end function 
--> 
</SCRIPT> 

</HEAD> 

<BODY> 

<H1>Control Panel Shortcuts</H1>
<INPUT type="button" value="User Account Control" onclick="fnStart(23)">
<INPUT type="button" value="Task Manager" onclick="fnStart(22)">
<INPUT type="button" value="System Restore" onclick="fnStart(21)">
<INPUT type="button" value="MsConfig" onclick="fnStart(20)">
<INPUT type="button" value="Action Center" onclick="fnStart(19)"><br>
<INPUT type="button" value="System Properties" onclick="fnStart(18)">
<INPUT type="button" value="Reg Edit" onclick="fnStart(17)">
<INPUT type="button" value="Power Configuration" onclick="fnStart(16)">
<INPUT type="button" value="Event Viewer" onclick="fnStart(15)">
<INPUT type="button" value="Screen Resolution" onclick="fnStart(14)"><br>
<INPUT type="button" value="Disk Management" onclick="fnStart(13)">
<INPUT type="button" value="Full Control Panel" onclick="fnStart(12)">
<INPUT type="button" value="Command Prompt" onclick="fnStart(11)">
<INPUT type="button" value="Windows Update" onclick="fnStart(10)"> 
<INPUT type="button" value="Edit Taskbar Properties" onclick="fnStart(9)"><br> 
<INPUT type="button" value="Users Accounts Folder" onclick="fnStart(8)"> 
<INPUT type="button" value="Disk Cleanup" onclick="fnStart(7)"> 
<INPUT type="button" value="Device Manager" onclick="fnStart(6)"> 
<INPUT type="button" value="Modify Internet Properties" onclick="fnStart(5)">
<INPUT type="button" value="Set System Time" onclick="fnStart(4)"><br> 
<INPUT type="button" value="Services" onclick="fnStart(3)"> 
<INPUT type="button" value="Programs and Features" onclick="fnStart(2)"> 
<INPUT type="button" value="Run" onclick="fnStart(1)"> 
<INPUT type="button" value="Minimize All Windows" onclick="fnStart(0)"> 
</BODY> 
</HTML>
 
Case 23 is failing because there is a space in the shell execute parameter.
Code:
Shell.ShellExecute "control.exe nusrmgr.cpl"
To get around this you need to pass a quoted string to the shell execute command. There are basically 2 ways to do this, the one you use is up to preference.
Code:
Shell.ShellExecute """control.exe nusrmgr.cpl"""
or
Code:
Shell.ShellExecute char(34) & "control.exe nusrmgr.cpl" & char(34)
 
Sorry, char(34) in the 2nd example should be chr(34).
 
Tried both of those and windows still comes up and say that windows can't find this file. But when I run this command in run the user account windows opens right up. Also I tried the Shell.ControlPanelItem and when I do that I click the button but nothing happens. No error windows open up and no new windows open.
 
You may have to provide the full path to the nusrmgr.cpl file. I did a quick search on this computer (Win XP 64 bit) and turned up 3 copies.
 
Replace this:
Code:
Shell.ShellExecute """control.exe nusrmgr.cpl"""

With this:
Code:
Shell.ControlPanelItem "nusrmgr.cpl"

Note: I only tried it in XP 32-bit
 
Tried that. See that why I need help. I can't think of what is needed next.
 
The Shell.ControlPanelItem "nusrmgr.cpl". Nothing happens. Nothing opens up.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top