在这里,我想检查字符串中是否包含文本,但它不起作用:
WScript.Echo "Hello"
Set oShell = CreateObject ("Wscript.Shell")
Dim strAgrs,strAgrs1,value,a,variable2,variable3,txt
a= execStdOut("wmic process where (Name like '%java.exe%') get commandline")
Wscript.echo a
variable2="java -cp ATMRETINA.jar com.elitenet.np.Cam2TakingSnapsV21"
variable3="java -cp ATMRETINA.jar com.elitenet.np.Cam1TakingVideoV11"
Wscript.echo variable2
Wscript.echo variable3
Wscript.echo inStr(a,variable2)
Wscript.echo inStr(a,variable3)
txt="This is a beautiful day!"
Wscript.echo inStr(txt,"beautiful")
if (inStr(a, variable2)>0) then
WScript.Echo "Hello friend video"
else
WScript.Echo "Hello friend video not working"
strAgrs = "cmd /c run_snaps.bat"
oShell.Run strAgrs, 0, false
end if
if (inStr(a, variable3)>0) then
WScript.Echo "Hello friend video"
else
WScript.Echo "Hello friend video not working"
strAgrs1 = "cmd /c run_video.bat"
oShell.Run strAgrs1, 0, false
end if
Function execStdOut(cmd)
Dim goWSH : Set goWSH = CreateObject( "WScript.Shell" )
Dim aRet: Set aRet = goWSH.exec(cmd)
execStdOut = aRet.StdOut.ReadAll()
End Function
即使它包含变量2和变量3,它总是返回0;我不明白什么是错的。
答案 0 :(得分:0)
问题与If或InStr无关。参见
理解,为什么你应该像
中的WMI(不是WMIC)Dim WMI, Services, Service
Set WMI = GetObject("winmgmts:root/CIMV2")
Set Services = WMI.ExecQuery("select commandline from Win32_Process where Name like '%java.exe%'")
For Each Service In Services
WScript.Echo Service.commandline
If Instr(1, Service.commandline, "JAR", vbTextCompare) Then
WScript.Echo "found JAR!"
End If
Next
(比尔斯图尔特(1)被盗)
输出:
java -jar "C:\rhino1_7R5pre\js.jar"
found JAR!