HTA vbs脚本在计划任务启动时无法执行程序

HTA vbs script cannot execute program when scheduled task launched

尝试制作一个简单的信息亭 HTA,它会在用户登录时自动启动。 但是当我将 hta 添加为计划任务时,我无法让它工作。

我使用 hta 文件作为初始屏幕,同时它执行所需的脚本和程序,然后是信息亭界面 HTA 文件。

当我 运行 手动启动启动 hta 时,一切正常。但是,当我将 splash HTA 添加为计划任务时,它会破坏我的执行脚本,并且找不到我告诉它启动的任何程序和脚本。

我使用 Inno setup 来安装信息亭,如果可能的话还希望它设置计划任务。

我需要 运行 的文件已安装到:C:\Users\USER\AppData\Local\Programs\MyKiosk\data

计划的任务操作是: 程序:C:\Windows\System32\mshta.exe 参数:%localappdata%\Programs\Mykiosk\Splash.hta

这是启动 HTA 中的 vbs 脚本:

<HTA:APPLICATION
    CONTEXTMENU = "no"
    BORDER="none"
    INNERBORDER = "no"
    SINGLEINSTANCE = "yes"
    SHOWINTASKBAR = "no"
    SCROLL="no"/>

 <script type="text/vbscript">

    Sub window_onload()
        CenterWindow (screen.Width - widthX)/4, (screen.Height - heightY)/4.5

        Call Execute("program.exe")
        Call Execute("script.bat")
        Call Sleep(1)
        Call Execute("StartKiosk.bat")
        Window.Close

    End Sub

    '-----------------------------WindowsSize-----------------------------------------
    Sub CenterWindow( widthX, heightY )
        self.ResizeTo widthX, heightY 
        self.MoveTo (screen.Width - widthX)/2, (screen.Height - heightY)/2
    End Sub
        '----------------------------Execute---------------------------------------
    Sub Execute(Program)
        set shell=CreateObject("Shell.Application")
        ' shell.ShellExecute "application", "arguments", "path", "verb", window
        shell.ShellExecute ""&Program&"",,"data\", "runas", 0
        set shell=nothing
    End sub
    '-----------------------------Sleep-----------------------------------------
    Sub Sleep(seconds)
        CreateObject("WScript.Shell").Run "%COMSPEC% /c ping 127.0.0.1 -n " _
        & seconds+1, 0, True
    End Sub

    </script>

我试过将 data\ 路径替换为 %localappdata%\Programs\Mykiosk\data\ 但这并没有帮助,得到相同的Windows找不到程序错误。

我卡住了,谁能告诉我我做错了什么?

更新:

似乎缺少“开始于”参数的问题..

谁能告诉我如何使用 SCHTASKS 命令设置计划任务?

说明页面并没有说得很清楚,如何添加工作目录并与特定用户(用户 运行ning 安装程序)进行 ONLOGON..

这是我使用 Inno Setup 创建计划任务的尝试:

Filename: "schtasks"; \
    Parameters: "/Create /F /SC ONLOGON /TN ""My Kisok"" /TR ""'C:\Windows\System32\mshta.exe' {app}\Splash.hta"""; \
    Flags: runhidden

另外,如何使用特定用户(用户 运行ning 安装程序)进行 ONLOGON

我试过 addig /U {username} 但这会破坏脚本。

尝试使用 vbscript 创建任务:HTA_Tasker_Creator.vbs

Option Explicit
Dim Ws,TaskName,Repeat_Task,HTA_FILE_PATH
Set Ws = CreateObject("Wscript.Shell")
TaskName = "Open_HTA"
Repeat_Task = 30 ' in minutes
HTA_FILE_PATH = "%localappdata%\Programs\Mykiosk\data\Splash.hta"
Ws.run HTA_FILE_PATH,1,True
Call Create_Schedule_Task(TaskName,Repeat_Task)
'----------------------------------------------------------------------
Sub Create_Schedule_Task(TaskName,Repeat_Task)
Dim Ws,Task,Result
Set Ws = CreateObject("Wscript.Shell")
Task = "CMD /C Schtasks /Create /SC DAILY /ST 08:00 /F /RI "&_
Repeat_Task &" /DU 24:00 /TN "& TaskName &" /TR "& WScript.ScriptFullName &""
Result = Ws.run(Task,0,True)
End Sub
'----------------------------------------------------------------------

编辑:24/08/2020 @00:52

这是另一个 vbscript,我添加了一些功能来创建任务 ONLOGON,它也可以使用管理员权限删除!

Option Explicit
Dim Ws,TaskName,Repeat_Task,HTA_FILE_PATH
Set Ws = CreateObject("Wscript.Shell")
Call Run_as_Admin() ' We execute our script with admin rights !
TaskName = "My Kisok"
Repeat_Task = 30 ' in minutes
HTA_FILE_PATH = "%localappdata%\Programs\Mykiosk\data\Splash.hta"
Ws.run HTA_FILE_PATH,1,True
Call Create_Schedule_Task_ONLOGON(TaskName)
'Call Create_Schedule_Task(TaskName,Repeat_Task)
'Call Delete(TaskName) 'If You want to delete the Task just uncomment this line and comment the subroutine with Create_Shedule... in name
'-------------------------------------------------------------------------------------
Sub Create_Schedule_Task(TaskName,Repeat_Task)
Dim Ws,Task,Result
Set Ws = CreateObject("Wscript.Shell")
Task = "CMD /C Schtasks /Create /SC DAILY /ST 08:00 /F /RI "&_
Repeat_Task &" /DU 24:00 /TN "& DblQuote(TaskName) &" /TR "& WScript.ScriptFullName &""
Result = Ws.run(Task,0,True)
End Sub
'-------------------------------------------------------------------------------------
Sub Create_Schedule_Task_ONLOGON(TaskName)
Dim Ws,Task,Result
Set Ws = CreateObject("Wscript.Shell")
Task = "CMD /C Schtasks /Create /SC ONLOGON /F "&_
"/TN "& DblQuote(TaskName) &" /TR "& WScript.ScriptFullName &""
Result = Ws.run(Task,0,True)
End Sub
'-------------------------------------------------------------------------------------
Sub Run_as_Admin()
If Not WScript.Arguments.Named.Exists("elevate") Then
   CreateObject("Shell.Application").ShellExecute DblQuote(WScript.FullName) _
   , DblQuote(WScript.ScriptFullName) & " /elevate", "", "runas", 1
    WScript.Quit
End If
End Sub
'-------------------------------------------------------------------------------------
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'-------------------------------------------------------------------------------------
Sub Delete(TaskName)
Dim Ws,Task,Result
Set Ws = CreateObject("Wscript.Shell")
Task = "CMD /C schtasks /Delete /TN "& DblQuote(TaskName) &" /F"
Result = Ws.run(Task,0,True)
End Sub
'-------------------------------------------------------------------------------------