Тема: VBS: Sub
Укажите на ошибку пожалуйста.
Пытаюсь получить ss из sub
если проверяемого процесса нет он выдает пустое сообщение, если процесс есть он вообще ничего не выдает без sub работает нормально.
' окно процесса
sub a ()
Set WshShell = WScript.CreateObject("WScript.Shell")
if Instr(1, WScript.FullName, "WScript.exe", 1) > 0 Then
WshShell.Run "CScript """ & WScript.ScriptFullName & """", 0
Set WshShell = Nothing
WScript.Quit 1
End if
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Process" & " WHERE Name = 'calc.exe'")
Set Stream = CreateObject("ADODB.Stream")
For Each objProcess in colProcess
Set WshExec = WshShell.Exec("cmd")
With WshExec.StdIn
.WriteLine "tasklist /FI ""IMAGENAME eq " + objProcess.Name + """ /V /FO ""LIST"""
.WriteLine "exit"
End With
Do While Not wshExec.StdOut.AtEndOfStream
wshExecLine = wshExec.StdOut.ReadLine()
If (InStr(wshExecLine, StrConv("Заголовок","cp866","Windows-1251"))) Then
ss = Right( wshExecLine ,Len(wshExecLine)-15)
End If
Loop
' ss = WshExec.StdOut.Readall
'ss = Split(ss,":")
ss = StrConv(ss, "Windows-1251", "cp866")
ss = Len(ss)
Next
END sub
MsgBox a
'loop until ss =18
'if ss = 18 then
'msgbox "1"
'else
'msgbox "2"
'end if
'WScript.Quit 0
' конвертация из 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

