我有一个HTA,我想每小时都把它作为一个提醒,以防它被最小化或重点从中消失。我遇到的问题是,Sub没有识别变量。我将发布代码,然后解释:
<HTML>
<HEAD>
<style type="text/css">
p {font-family: 'Segoe UI Light'; font-size: 12pt}
td {font-family: 'Segoe UI Light'; font-size: 12pt}
input {font-family: 'Segoe UI Light'; font-size: 12pt}
body {font-family: 'Segoe UI Light'; font-size: 12pt; color: #4D4C5C; background-color: white}
</style>
<TITLE>QT MOE Upgrade</TITLE>
<HTA:APPLICATION ID="MOEUpgrade"
APPLICATIONNAME="MOE Upgrade"
BORDER="dialog"
SCROLL="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="no">
</HEAD>
<SCRIPT LANGUAGE="VBScript">
Dim iTimerID, strProcName, strProcID
Set objShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE '%MOEUpgrade.hta%'")
For Each objProcess in colProcesses
strProcName = objProcess.Name
strProcID = objProcess.ProcessID
Next
Sub Window_OnLoad
Set colItems = objWMIService.ExecQuery("Select * From Win32_VideoController WHERE AdapterDACType='Internal'")
For Each objItem in colItems
intHorizontal = objItem.CurrentHorizontalResolution
intVertical = objItem.CurrentVerticalResolution
Next
intLeft = (intHorizontal-1024)/2
intTop = (intVertical-600)/2
self.resizeto 1024,600
self.moveTo intLeft,intTop
self.focus()
iTimerID = window.setInterval("NagWindow",5000)
End Sub
Sub NagWindow
MsgBox strProcName & VBCRLF & strProcID
End Sub
Sub StartUpgradeNow
If MsgBox ("Are you sure you want to start the upgrade now?",vbYesNo+vbExclamation,"Confirm Upgrade") = vbYes Then
self.close()
End If
End Sub
</SCRIPT>
<BODY>
<div align="justify">
<p>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</p>
</div>
<div align="center">
<br>
<span class="tooltip" title="Click OK to start the upgrade now"><input type="button" name="OKButton" value=" OK " onClick="StartUpgradeNow" style="font-family: 'Segoe UI Light'"></span>
</div>
</BODY>
</HTML>
如果您非常喜欢,可以将此代码保存为MOEUpgrade.hta,它应该会为您运行而不会出现任何问题。此代码有效并弹出一个消息框,按预期显示strProcName
和strProcID
个变量,但当我将NagWindow
Sub中的第58行更改为:
objShell.AppActivate strProcName.strProcID
它失败并且需要一个对象(&#39; strProcName&#39;)错误。有没有人知道为什么在使用objShell函数时不能识别变量但是在使用MsgBox时是什么?
答案 0 :(得分:0)
错误原因
需要的对象:'strProcName'
是因为您尝试将strProcID
作为strProcName
的对象属性调用,但从代码中可以清楚地看出strProcName
和strProcID
都是字符串变量。
如果您尝试将AppActivate
与Window Process Id一起使用,则可能需要尝试;
Call objShell.AppActivate(strProcID)