Wscript and HTA

Toshiba Satellite l505d-s5965 notebook
March 12, 2010 at 02:54:43
Specs: Windows 7, 1024
i notice you cant use Wscript in HTA, what would be the best way to get around this while being about to run CMD/dos commands?

this code which invokes the UAC promt for admin rights doesnt work because of that same issue. im not sure how to get around that issues also.


If WScript.Arguments.length =0 Then
Set objShell = CreateObject("Shell.Application")
'Pass a bogus argument with leading blank space, say [ uac]
objShell.ShellExecute "wscript.exe", Chr(34) & _
WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
ELSE
Option Explicit
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /k defrag.exe C:"
WScript.Quit
End If

i get an error saying 'object req. Wscript.

thank you all


See More: Wscript and HTA

Report •

#1
March 12, 2010 at 14:25:13
i would put these at the very top of the script/code:
Dim obShell
dim obApp
Set obShell = CreateObject("WScript.Shell")
set obApp=createobject("shell.application")

instead of inside the "IF" and down in the code.
it should work, so maybe that is the problem
use a different object-reference for the shell.application instead of trying to recycle obShell for both services.


Report •

#2
March 12, 2010 at 20:34:15
would you edit the code, im having issues i was just trying a simple cmd for defrag.exe C:.


thanks


Report •

#3
March 12, 2010 at 21:34:23
here's the simplest version (i used xcopy with output to textfile in order to avoid the time-consumption of waiting for defrag to finish). apparently the wsh.run must invoke another command.com in order to function the way i wanted for testing, but without command.com (XP: read CMD.EXE) xcopy /? still worked but it would not pipe to the textfile.
i ran this on my old system. i will substitute cmd for command:
<html>
<head>
<title>Cleanup</title>
</head>
<body bgcolor="white">
<SCRIPT Language="VBScript">
dim wsh
set wsh=createobject("wscript.shell")
Sub Window_Onload
wsh.run ("cmd /c xcopy /? > \htm\def.txt"),0
'''wsh.run ("cmd /c defrag c:"),0
end sub
</script>
</body>
</html>
'-------- end
the ,0 makes it run in "stealth mode". use 1 or 3 for visible, 2 for minimized (on taskbar).
this is just a stripped-down script to use for example, but you should be able to take it from here. let me know what happens or other enhancements you want to work on.

Report •

Related Solutions

#4
March 12, 2010 at 23:06:21
Thank you for your help,

now my issues is i need admin rights this code

If WScript.Arguments.length =0 Then
Set objShell = CreateObject("Shell.Application")
'Pass a bogus argument with leading blank space, say [ uac]
objShell.ShellExecute "wscript.exe", Chr(34) & _
WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1

check if the command needs admin rights if not it does a UAC prompt to start the task as admin.

here a link for reference

http://www.winhelponline.com/articl...


Report •

#5
March 14, 2010 at 03:20:21
its really odd because in just .VBS file it works but once placed inside a HTA the code fail and states object req. Wscript.


i dont really understand why it fails.

are there any HTML people that could help maybe?

thank you for all that have helped.


Report •

Ask Question