<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS: Sub]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=9709&amp;type=atom" />
	<updated>2014-06-19T10:58:44Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=9709</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Sub]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=83986#p83986" />
			<content type="html"><![CDATA[<p>А не подскажете как мне передать функцию внутрь функции?<br />в таком варианте когда процесс запущен он вообще не открывает меседжбокс, а если не запущен выдает пустой&nbsp; меседжбокс.<br /></p><div class="codebox"><pre><code>&#039; окно процесса
msgbox a
function a()
  Set WshShell = WScript.CreateObject(&quot;WScript.Shell&quot;)

  if Instr(1, WScript.FullName, &quot;WScript.exe&quot;, 1) &gt; 0 Then
     WshShell.Run &quot;CScript &quot;&quot;&quot; &amp; WScript.ScriptFullName &amp; &quot;&quot;&quot;&quot;, 0
     Set WshShell = Nothing
     WScript.Quit 1
  End if

  strComputer = &quot;.&quot;

  Set objWMIService = GetObject(&quot;winmgmts:&quot; _
      &amp; &quot;{impersonationLevel=impersonate}!\\&quot; _ 
      &amp; strComputer &amp; &quot;\root\cimv2&quot;) 

  Set colProcess = objWMIService.ExecQuery( _
    &quot;SELECT * FROM Win32_Process&quot; &amp; &quot; WHERE Name = &#039;calc.exe&#039;&quot;)

  Set Stream   = CreateObject(&quot;ADODB.Stream&quot;)

  For Each objProcess in colProcess
      Set WshExec = WshShell.Exec(&quot;cmd&quot;)
      With WshExec.StdIn
           .WriteLine &quot;tasklist /FI &quot;&quot;IMAGENAME eq &quot; + objProcess.Name + &quot;&quot;&quot; /V /FO &quot;&quot;LIST&quot;&quot;&quot;
           .WriteLine &quot;exit&quot;
      End With

        Do While Not wshExec.StdOut.AtEndOfStream
                wshExecLine = wshExec.StdOut.ReadLine()

               If (InStr(wshExecLine, StrConv(&quot;Заголовок&quot;,&quot;cp866&quot;,&quot;Windows-1251&quot;))) Then  
                    ss = Right( wshExecLine ,Len(wshExecLine)-15)  
                
                End If
                
            Loop

    &#039;  ss = WshExec.StdOut.Readall
          &#039;ss = Split(ss,&quot;:&quot;)
         
      ss = StrConv(ss, &quot;Windows-1251&quot;, &quot;cp866&quot;)

      
      Set WshExec = Nothing
  Next

 &#039; Set Stream   = Nothing
 &#039; Set WshShell = Nothing

 &#039; WScript.Quit 0
a = ss
end function
&#039; конвертация из DOS в WINDOWS
Function StrConv(Text, SourceCharset, DestCharset)
    Stream.Type = 2
    Stream.Mode = 3
    Stream.Open
    Stream.Charset = SourceCharset
    Stream.WriteText Text
    Stream.Position = 0
    Stream.Charset = DestCharset
    StrConv = Stream.ReadText
    Stream.Close
End Function
msgbox  a
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[therb]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32361</uri>
			</author>
			<updated>2014-06-19T10:58:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=83986#p83986</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Sub]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=83982#p83982" />
			<content type="html"><![CDATA[<p><strong>Sub</strong> это подпроцедура. Она может возвращать значения только через параметры переданные по ссылке либо в результате присвоения глобально доступных переменных. <br /></p><div class="codebox"><pre><code>

MsgBox a

Sub Test(a)
   a  = 1
End Sub
</code></pre></div><p>В Вашем случае, имеет смысл использовать <strong>Function</strong> и возвращать значение штатным образом через имя функции:<br /></p><div class="codebox"><pre><code>
MsgBox Test
Function Test()
   Test = 1
End Function
</code></pre></div><br /><p>Подробнее о принципах работы процедур Visual Basic:<br /><a href="http://msdn.microsoft.com/en-us/library/tt223ahx(v=vs.84).aspx">http://msdn.microsoft.com/en-us/library … s.84).aspx</a><br />и функций<br /><a href="http://msdn.microsoft.com/en-us/library/x7hbf8fa(v=vs.84).aspx">http://msdn.microsoft.com/en-us/library … s.84).aspx</a></p><br /><p><a href="http://www.w3schools.com/vbscript/vbscript_procedures.asp">http://www.w3schools.com/vbscript/vbscr … edures.asp</a></p>]]></content>
			<author>
				<name><![CDATA[Xameleon]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=8836</uri>
			</author>
			<updated>2014-06-19T07:49:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=83982#p83982</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS: Sub]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=83973#p83973" />
			<content type="html"><![CDATA[<p>Укажите на ошибку пожалуйста.<br />Пытаюсь получить ss из sub<br />если проверяемого процесса нет он выдает пустое сообщение, если процесс есть он вообще ничего не выдает без sub работает нормально.<br /></p><div class="codebox"><pre><code>
&#039; окно процесса
sub a ()
  Set WshShell = WScript.CreateObject(&quot;WScript.Shell&quot;)

  if Instr(1, WScript.FullName, &quot;WScript.exe&quot;, 1) &gt; 0 Then
     WshShell.Run &quot;CScript &quot;&quot;&quot; &amp; WScript.ScriptFullName &amp; &quot;&quot;&quot;&quot;, 0
     Set WshShell = Nothing
     WScript.Quit 1
  End if

  strComputer = &quot;.&quot;

  Set objWMIService = GetObject(&quot;winmgmts:&quot; _
      &amp; &quot;{impersonationLevel=impersonate}!\\&quot; _ 
      &amp; strComputer &amp; &quot;\root\cimv2&quot;) 

  Set colProcess = objWMIService.ExecQuery( _
    &quot;SELECT * FROM Win32_Process&quot; &amp; &quot; WHERE Name = &#039;calc.exe&#039;&quot;)

  Set Stream   = CreateObject(&quot;ADODB.Stream&quot;)

  For Each objProcess in colProcess
      Set WshExec = WshShell.Exec(&quot;cmd&quot;)
      With WshExec.StdIn
           .WriteLine &quot;tasklist /FI &quot;&quot;IMAGENAME eq &quot; + objProcess.Name + &quot;&quot;&quot; /V /FO &quot;&quot;LIST&quot;&quot;&quot;
           .WriteLine &quot;exit&quot;
      End With

        Do While Not wshExec.StdOut.AtEndOfStream
                wshExecLine = wshExec.StdOut.ReadLine()

               If (InStr(wshExecLine, StrConv(&quot;Заголовок&quot;,&quot;cp866&quot;,&quot;Windows-1251&quot;))) Then  
                    ss = Right( wshExecLine ,Len(wshExecLine)-15)  
                
                End If
                
            Loop

    &#039;  ss = WshExec.StdOut.Readall
          &#039;ss = Split(ss,&quot;:&quot;)
         
      ss = StrConv(ss, &quot;Windows-1251&quot;, &quot;cp866&quot;)
ss = Len(ss)
        Next
        
END sub

 
MsgBox  a


    &#039;loop until ss =18
    
 
&#039;if ss = 18 then
&#039;msgbox &quot;1&quot;
&#039;else
&#039;msgbox &quot;2&quot;
&#039;end if

  &#039;WScript.Quit 0


&#039; конвертация из DOS в WINDOWS
Function StrConv(Text, SourceCharset, DestCharset)
    Stream.Type = 2
    Stream.Mode = 3
    Stream.Open
    Stream.Charset = SourceCharset
    Stream.WriteText Text
    Stream.Position = 0
    Stream.Charset = DestCharset
    StrConv = Stream.ReadText
    Stream.Close
End Function
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[therb]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32361</uri>
			</author>
			<updated>2014-06-18T12:11:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=83973#p83973</id>
		</entry>
</feed>
