Страница 1 из 1

VBS+FUNCTION или SUB

Добавлено: 2014-06-24 11:04:35
therb1
Народ помогите пожалуйста с вопросом
Как запихнуть этот код в Function что бы получить значение ss?

Код: Выделить всё

' окно процесса

  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 = 'javaw.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")

	  MsgBox ss
      Set WshExec = Nothing
  Next

  Set Stream   = Nothing
  Set WshShell = Nothing

  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