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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit registry and reboot from an HTA 1

Status
Not open for further replies.

efiftythree

IS-IT--Management
Jan 13, 2006
27
US
Im working on an HTA to aid in moving PC's from Novell to our MS domain. When completed the HTA will be burned to CD and carried around to the PC's to complete the migration.

There are six steps involved in the process and I have listed serveral of them below. One of the steps involves rebooting the PC once the Novell client has been removed. In that step I would like to include a registry write to make the HTA launch automatically upon restart. I thought I had this done but due to my lack of programming skills I wasnt aware of the restrictions on some Wscript things.

So, heres the code:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled</title>

<HTA:APPLICATION 
[stuff goes here]
/>
<SCRIPT Language="VBScript">

Sub NovellUninstall
	Set WShell = CreateObject("WScript.Shell")
		WShell.Run "c:\windows\system32\NetWare\nwmigw2k\SETUPW2K.exe /u ms_nwspx"
		WShell.Run "c:\windows\system32\NetWare\nwmigw2k\SETUPW2K.exe /u ms_nwnb"
		WShell.Run "c:\windows\system32\NetWare\nwmigw2k\SETUPW2K.exe /u ms_nwipx"
		WShell.Run "c:\windows\system32\NetWare\nwmigw2k\SETUPW2K.exe /u nw_wm"
		WShell.Run "c:\windows\system32\NetWare\nwmigw2k\SETUPW2K.exe /u nw_ndps"
		WShell.Run "c:\windows\system32\NetWare\nwmigw2k\SETUPW2K.exe /u nw_nwfs "
	
End Sub

Sub VNCUninstall
	Set WShell = CreateObject("WScript.Shell")
		WShell.Run "c:\Progra~1\TightVNC\unins000.exe"
End Sub

Sub Reboot
	DIM strPath
	path = WScript.ScriptFullName  ' script file name
	
	Set WshShell = WScript.CreateObject("WScript.Shell")
		WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\RunDomHTA", strPath ,"REG_SZ"
	
	Set WShell = CreateObject("WScript.Shell")
		WShell.Run "shutdown -r"
End Sub

</SCRIPT>
</head>

<input id=unnovell  class="button" type="button" value="Uninstall Novell" name="unnovell"  onClick="NovellUninstall">
<input id=unvnc  class="button" type="button" value="Uninstall VNC" name="unvnc"  onClick="VNCUninstall">
<input id=reboot  class="button" type="button" value="Reboot PC" name="reboot"  onClick="Reboot">

</body>
</html>

Sub Reboot is what I am concerned with. The code there dosnt work. Any ideas as to how I should solve this problem?
 
Code:
'Reboot the current PC
mname="."
Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & mname).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
		for each OpSys in OpSysSet
			OpSys.Reboot()
 		next

I hope you find this post helpful.

Regards,

Mark
 
<HTA:APPLICATION [!]ID="0HTA"[/!]
[stuff goes here]
/>
<SCRIPT Language="VBScript">
...
Sub Reboot
Dim strPath[!], WshShell
strPath = oHTA.commandLine
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\RunDomHTA", strPath, "REG_SZ"
WshShell.Run "shutdown -r", , True[/!]
End Sub
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks Mark and PH!

that last bit of code works great.
 
Yep, this should work. Be careful though and don't assume that the [tt]commandLine[/tt] property is the same as WScript's [tt]ScriptFullName[/tt] property!

[tt]oHTA.commandLine[/tt] will work in this degenerate case (no parameters) but it isn't meant for that purpose, will usually result in a quoted substring for the "scriptname" (which is great if you need it), and if there are parameters they'll be parts of the returned string value as well. Example value:

[tt]"C:\my.hta" p1 p2 p3[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top