2013-04-30 2 views
0

Я не уверен, почему, но моя вспомогательная функция не работает. Я думал, что слежу за тем, как он должен работать, но он просто вызывает ошибку, заявляющую, что моя функция не определена.функция sub не работает в HTA

<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="x-ua-compatible" content="IE=edge"> 
<title>Remote Registry</title> 
<HTA:APPLICATION 
    APPLICATIONNAME="Remote Registry" 
    ID="RemReg" 
    VERSION="1.0.0.0" 
    SCROLL="no" 
    SINGLEINSTANCE="yes" 
    CONTEXTMENU="no" 
    NAVIGABLE="yes" 
SELECTION="no" 
/> 
<style type="text/css"> 
body 
{ 
    margin: 0; 
    width: 130px; 
    height: 180px; 
    overflow: hidden; 
     font-family: arial; 
    font-weight: bold; 
    font-size: 12px; 
} 
</style> 
</head> 
<SCRIPT LANGUAGE="VBScript"> 
Sub CheckService 
    strComputer = txtBox.value 
    Set objWMIService = GetObject("winmgmts:" _ 
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
    Set colRunningServices = objWMIService.ExecQuery _ 
     ("Select * from Win32_Service Where Name=""RemoteRegistry""") 
    For Each objService in colRunningServices 
    Output = objService.DisplayName & " is " & objService.State 
    Next 
End Sub 
</script> 
<body> 
    <input type="text" name="TxTbox" size="30" value=DTP-> Computer to check<br /> 
    <input id=checkservice type="button" value="Add Button" onClick="CheckService"> 
    <div id="strComputer"></div> 
</body> 
</html> 

Что мне не хватает? Что-то действительно простое? Я пробовал альтернативные имена для функции, перемещаясь там, где находится VBScript. Ничего не работает: sRem

+0

ли другие компьютеры в том же домене? ваше имя пользователя/пароль действительны в других компьютерах? REF: http://msdn.microsoft.com/en-us/library/windows/desktop/aa389290(v=vs.85).aspx – Zeddy

+0

Да, в том же домене у меня есть полный доступ администратора ко всем другим ПК с помощью моего пользователь и пароль - я работал в VBScript, но хочу, чтобы что-то более динамичное, чтобы автоматически проверять его при запуске. – Hyperjase

+0

Ссылка, приведенная в моем комментарии, должна дать вам несколько примеров и хорошее описание того, как это сделать. Я думаю, что у вас отсутствует имя пользователя/пароль, но я не уверен. – Zeddy

ответ

0

Измените свой код на нижеследующий и используйте ссылку ссылки выше для вашего вызова WMI, и все должно быть в порядке.

<!DOCTYPE html> 

<html> 

<head> 
    <meta http-equiv="x-ua-compatible" content="IE=edge" /> 
    <title>Remote Registry</title> 
    <hta:application 
    applicationname="Remote Registry" 
    id="RemReg" 
    version="1.0.0.0" 
    scroll="no" 
    singleinstance="yes" 
    contextmenu="no" 
    navigable="yes" 
    selection="no" 
    /> 
    <style type="text/css"> 
    body 
    { 
     margin: 0; 
     width: 130px; 
     height: 180px; 
     overflow: hidden; 
     font-family: arial; 
     font-weight: bold; 
     font-size: 12px; 
    } 
    </style> 
</head> 

<script type="text/vbscript" id="CheckService"> 
Sub CheckService() 
' 
dim strComputer 
    ' 
    strComputer = window.document.getElementById("txtComputer").value 
    ' PLACE YOUR CALL TO WMI HERE - (I'm not sure mine is correct!) 
    'Set objServices = GetObject(_ 
    "winmgmts:{impersonationLevel=impersonate," _ 
    & "authenticationLevel=pktPrivacy}!\\" _ 
    & strcomputer & "/root/cimv2") 
    ' 
    Set colRunningServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name=" & chr(34) & "RemoteRegistry" & chr(34)) 
    if colRunningServices.items.count - 1 > 0 Then 
     For Each objService in colRunningServices 
     window.document.getElementById("Results").innerText = window.document.getElementById("Results").innerText & objService.DisplayName & " is " & objService.State & chr(13) 
     Next 
    else 
     window.document.getElementById("Results").innerText = "No running services found at this time!" 
    end if 
    ' 
End Sub 
</script> 

<body> 
    <input type="text" id="txtComputer" name="txtComputer" size="30" value="Dtp-"/> Computer to check<br /> 
    <input id="btnCheckService" name="btnCheckService" type="button" value="Add Button" onclick="CheckService" /> 
    <div id="Results"></div> 
</body> 
</html> 

UPDATE

Я изменил код, чтобы удалить META тег и добавить некоторые примеры подпрограмм для вас.

То, что я сделал, было сохранено HTA на моем рабочем столе и выполнено оттуда, дважды щелкнув по нему.

<!DOCTYPE html> 
<html> 
<head> 
    <title>Remote Registry</title> 
    <hta:application 
    applicationname="Remote Registry" 
    id="RemReg" 
    version="1.0.0.0" 
    scroll="no" 
    singleinstance="yes" 
    contextmenu="no" 
    navigable="yes" 
    selection="no" 
    /> 
    <style type="text/css"> 
    body 
    { 
     margin: 0; 
     width: 130px; 
     height: 180px; 
     overflow: hidden; 
     font-family: arial; 
     font-weight: bold; 
     font-size: 12px; 
    } 
    </style> 
</head> 
<script type="text/vbscript" id="EnumMyServices"> 
' <!-- 
Sub EnumMyServices() 
    dim WMI, objs, obj 
    ' 
    set WMI = GetObject("WinMgmts:") 
    on error resume next 
    set objs = WMI.InstancesOf("Win32_Service") 
    if err = 0 Then 
     if objs.count > 0 then 
     window.document.getElementById("Results").innerText = "SERVICES" & chr(13) 
     for each obj in objs 
      window.document.getElementById("Results").innerText = window.document.getElementById("Results").innerText & obj.Description & chr(13) 
     next 
     else 
     window.document.getElementById("Results").innerText = "SERVICES" & chr(13) 
     window.document.getElementById("Results").innerText = "no services found!" & chr(13) 
     end if 
    else 
     window.document.getElementById("Results").innerText = "SERVICES" & chr(13) 
     window.document.getElementById("Results").innerText = "An error occurred whilst trying to enum services!" & chr(13) 
    end if 
    set WMI=nothing 
    set objs = nothing 
    set obj = nothing 
    on error goto 0 
end sub 
' --> 
</script> 

<script type="text/vbscript" id="EnumMyPrinters"> 
' <!-- 
Sub EnumMyPrinters() 
dim WMI, objs, obj 
    ' 
    set WMI = GetObject("WinMgmts:") 
    on error resume next 
    set objs = WMI.InstancesOf("Win32_Printer") 
    if err = 0 Then 
     if objs.count > 0 then 
     window.document.getElementById("Results").innerText = "PRINTERS" & chr(13) 
     for each obj in objs 
      window.document.getElementById("Results").innerText = window.document.getElementById("Results").innerText & obj.Description & chr(13) 
     next 
     else 
     window.document.getElementById("Results").innerText = "PRINTERS" & chr(13) 
     window.document.getElementById("Results").innerText = "no printers found!" & chr(13) 
     end if 
    else 
     window.document.getElementById("Results").innerText = "PRINTERS" & chr(13) 
     window.document.getElementById("Results").innerText = "An error occurred whilst trying to enum printers!" & chr(13) 
    end if 
    set WMI=nothing 
    set objs = nothing 
    set obj = nothing 
    on error goto 0 
end sub 
' --> 
</script> 

<script type="text/vbscript" id="EnumMyProcesses"> 
' <!-- 
Sub EnumMyProcesses() 
dim WMI, objs, obj 
    ' 
    set WMI = GetObject("WinMgmts:") 
    on error resume next 
    set objs = WMI.InstancesOf("Win32_Process") 
    if err = 0 Then 
     if objs.count > 0 then 
     window.document.getElementById("Results").innerText = "PROCESSES" & chr(13) 
     for each obj in objs 
      window.document.getElementById("Results").innerText = window.document.getElementById("Results").innerText & obj.Description & chr(13) 
     next 
     else 
     window.document.getElementById("Results").innerText = "PROCESSES" & chr(13) 
     window.document.getElementById("Results").innerText = "no processes found!" & chr(13) 
     end if 
    else 
     window.document.getElementById("Results").innerText = "PROCESSES" & chr(13) 
     window.document.getElementById("Results").innerText = "An error occurred whilst trying to enum processes!" & chr(13) 
    end if 
    set WMI=nothing 
    set objs = nothing 
    set obj = nothing 
    on error goto 0 
end sub 
' --> 
</script> 

<script type="text/vbscript" id="EnumMyProcessors"> 
' <!-- 
Sub EnumMyProcessors() 
dim WMI, objs, obj 
    ' 
    set WMI = GetObject("WinMgmts:") 
    on error resume next 
    set objs = WMI.InstancesOf("Win32_Processor") 
    if err = 0 Then 
     if objs.count > 0 then 
     window.document.getElementById("Results").innerText = "PROCESSORS" & chr(13) 
     for each obj in objs 
      window.document.getElementById("Results").innerText = window.document.getElementById("Results").innerText & obj.Description & chr(13) 
     next 
     else 
     window.document.getElementById("Results").innerText = "PROCESSORS" & chr(13) 
     window.document.getElementById("Results").innerText = "no processors found!" & chr(13) 
     end if 
    else 
     window.document.getElementById("Results").innerText = "PROCESSORS" & chr(13) 
     window.document.getElementById("Results").innerText = "An error occurred whilst trying to enum processors!" & chr(13) 
    end if 
    set WMI=nothing 
    set objs = nothing 
    set obj = nothing 
    on error goto 0 
end sub 
' --> 
</script> 

<body> 
    <div id="mycontainer"> 
    Results:<br /> 
    <div id="Results"></div> 
    </div><br /><br /> 
    <input id="btnServices" name="btnServices" type="button" value="Services" onclick="EnumMyServices" /> 
    <input id="btnPrinters" name="btnPrinters" type="button" value="Printers" onclick="EnumMyPrinters" /> 
    <input id="btnProcesses" name="btnProcesses" type="button" value="Processes" onclick="EnumMyProcesses" /> 
    <input id="btnProcessors" name="btnProcessors" type="button" value="Processors" onclick="EnumMyProcessors" /> 
</body> 
</html> 
+0

Большое спасибо за это, я заработаю с вашим кодом :) – Hyperjase

+0

Я пробовал множество комбинаций, но, похоже, не могу этого добиться, выводя что-нибудь в окна, когда я нажимаю кнопку. – Hyperjase

+0

Слейте весь код из SUB и замените его этими двумя линиями, чтобы проверить его. когда вы нажимаете кнопку, текст в текстовом поле должен появляться ниже в div, который покажет вам, что HTA работает, а остальная часть - до вызова WMI. Строка 1 - strComputer = window.document.getElementById («txtComputer»). Значение и строка 2 is- window.document.getElementById («Результаты»). InnerText = strComputer – Zeddy

0

Небольшое базовое форматирование HTML-списка из списка услуг облегчает чтение.

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Remote Registry</title> 
     <hta:application 
      applicationname="Remote Registry" 
      id="RemReg" 
      version="1.0.0.0" 
      scroll="YES" 
      singleinstance="yes" 
      contextmenu="no" 
      navigable="yes" 
      selection="no" 
      /> 
     <style type="text/css"> 
      body 
      { 
       margin: 0; 
       width: 100%; 
       height: 100%; 
       overflow: hidden; 
       font-family: arial; 
       font-weight: bold; 
       font-size: 12px; 
      } 
     </style> 
     <script type="text/vbscript" id="EnumMyServices"> 

      ' <!-- 
      Sub EnumMyServices() 
      dim WMI, objs, obj 
      ' 
      set WMI = GetObject("WinMgmts:") 
      on error resume next 
      set objs = WMI.InstancesOf("Win32_Service") 
      if err = 0 Then 
      if objs.count > 0 then 
      strHTML="<table border=1 align=left cellpadding=4 cellspacing=0>" 
      strHTML=strHTML & "<tr>" 
      strHTML=strHTML & "<th>DisplayName</th>" 
      strHTML=strHTML & "<th>State</th>" 
      strHTML=strHTML & "<th>StartMode</th>" 
      strHTML=strHTML & "</tr>" 
      for each obj in objs 
      ObName = obj.DisplayName 
      ObState = obj.State 
      ObStartMode = obj.StartMode 
      strHTML=strHTML & "<tr>" 
      strHTML=strHTML & "<td>" & ObName & "</td>" 
      strHTML=strHTML & "<td>" & ObState & "</td>" 
      strHTML=strHTML & "<td>" & ObStartMode & "</td>" 
      strHTML=strHTML & "</tr>" 
      next 
      else 
      strHTML="<table border=1 align=left cellpadding=4 cellspacing=0>" 
      strHTML=strHTML & "<tr>" 
      strHTML=strHTML & "<th>Attention</th>" 
      strHTML=strHTML & "</tr>" 
      strHTML=strHTML & "<tr>" 
      strHTML=strHTML & "<td>no services found!</td>" 
      strHTML=strHTML & "</tr>" 
      end if 
      else 
      strHTML="<table border=1 align=left cellpadding=4 cellspacing=0>" 
      strHTML=strHTML & "<tr>" 
      strHTML=strHTML & "<th>Error!</th>" 
      strHTML=strHTML & "</tr>" 
      strHTML=strHTML & "<tr>" 
      strHTML=strHTML & "<td>An error occurred whilst trying to enum services!</td>" 
      strHTML=strHTML & "</tr>" 
      end if 
      set WMI=nothing 
      set objs = nothing 
      set obj = nothing 
      on error goto 0 

      strHTML=strHTML & "</table>" 
      strHTML=strHTML & "<p>" 
      Results.InnerHTML=strHTML 

      end sub 
      ' --> 
     </script> 

     <script type="text/vbscript" id="EnumMyPrinters"> 
      ' <!-- 
      Sub EnumMyPrinters() 
      dim WMI, objs, obj 
      ' 
      set WMI = GetObject("WinMgmts:") 
      on error resume next 
      set objs = WMI.InstancesOf("Win32_Printer") 
      if err = 0 Then 
      if objs.count > 0 then 
      window.document.getElementById("Results").innerText = "PRINTERS" & chr(13) 
      for each obj in objs 
      window.document.getElementById("Results").innerText = window.document.getElementById("Results").innerText & obj.Description & chr(13) 
      next 
      else 
      window.document.getElementById("Results").innerText = "PRINTERS" & chr(13) 
      window.document.getElementById("Results").innerText = "no printers found!" & chr(13) 
      end if 
      else 
      window.document.getElementById("Results").innerText = "PRINTERS" & chr(13) 
      window.document.getElementById("Results").innerText = "An error occurred whilst trying to enum printers!" & chr(13) 
      end if 
      set WMI=nothing 
      set objs = nothing 
      set obj = nothing 
      on error goto 0 
      end sub 
      ' --> 
     </script> 

     <script type="text/vbscript" id="EnumMyProcesses"> 
      ' <!-- 
      Sub EnumMyProcesses() 
      dim WMI, objs, obj 
      ' 
      set WMI = GetObject("WinMgmts:") 
      on error resume next 
      set objs = WMI.InstancesOf("Win32_Process") 
      if err = 0 Then 
      if objs.count > 0 then 
      window.document.getElementById("Results").innerText = "PROCESSES" & chr(13) 
      for each obj in objs 
      window.document.getElementById("Results").innerText = window.document.getElementById("Results").innerText & obj.Description & chr(13) 
      next 
      else 
      window.document.getElementById("Results").innerText = "PROCESSES" & chr(13) 
      window.document.getElementById("Results").innerText = "no processes found!" & chr(13) 
      end if 
      else 
      window.document.getElementById("Results").innerText = "PROCESSES" & chr(13) 
      window.document.getElementById("Results").innerText = "An error occurred whilst trying to enum processes!" & chr(13) 
      end if 
      set WMI=nothing 
      set objs = nothing 
      set obj = nothing 
      on error goto 0 
      end sub 
      ' --> 
     </script> 

     <script type="text/vbscript" id="EnumMyProcessors"> 
      ' <!-- 
      Sub EnumMyProcessors() 
      dim WMI, objs, obj 
      ' 
      set WMI = GetObject("WinMgmts:") 
      on error resume next 
      set objs = WMI.InstancesOf("Win32_Processor") 
      if err = 0 Then 
      if objs.count > 0 then 
      window.document.getElementById("Results").innerText = "PROCESSORS" & chr(13) 
      for each obj in objs 
      window.document.getElementById("Results").innerText = window.document.getElementById("Results").innerText & obj.Description & chr(13) 
      next 
      else 
      window.document.getElementById("Results").innerText = "PROCESSORS" & chr(13) 
      window.document.getElementById("Results").innerText = "no processors found!" & chr(13) 
      end if 
      else 
      window.document.getElementById("Results").innerText = "PROCESSORS" & chr(13) 
      window.document.getElementById("Results").innerText = "An error occurred whilst trying to enum processors!" & chr(13) 
      end if 
      set WMI=nothing 
      set objs = nothing 
      set obj = nothing 
      on error goto 0 
      end sub 
      ' --> 
     </script> 
    </head> 

    <body> 
     <input id="btnServices" name="btnServices" type="button" value="Services" onclick="EnumMyServices" /> 
     <input id="btnPrinters" name="btnPrinters" type="button" value="Printers" onclick="EnumMyPrinters" /> 
     <input id="btnProcesses" name="btnProcesses" type="button" value="Processes" onclick="EnumMyProcesses" /> 
     <input id="btnProcessors" name="btnProcessors" type="button" value="Processors" onclick="EnumMyProcessors" /> 
     <p> 
     <Font size="3" face="Tahoma"><h3>Results:</Font><hr></h3> 
     <div id="Results">&nbsp</div> 

    </body> 
</html> 
0

Использовать определение функции круглой формы(), как показано ниже, оно решает вашу проблему.

Sub CheckService()

// Ваш код

End Sub

Смежные вопросы