Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Convert Functions to Powershell from VBScript

$
0
0

Is there an easy way to convert these two functions to powershell functions?

Function checkProcessAndWait(strProcessName)
    Dim i

    ' Check if setup is running
    For i = 0 to 30
        If isProcessRunning(strProcessName) Then
           checkProcessAndWait = true
           wscript.Sleep 2000 ' sleep two seconds between checks
        Else
           ' setup isn't running, so continue install
           checkProcessAndWait = false
           If i <> 0 Then
              ' PropSetup process was running when the loop began, so a wait is necessary
              wscript.Sleep 10000 ' wait ten seconds to make sure registry has a chance to update
           End If
           Exit For
        End If
    Next

End Function

' Function to check if a process is running
Function isProcessRunning(strProcessName)
        strComputer = "." ' local computer
Dim objWMIService, strWMIQuery

strWMIQuery = "Select * from Win32_Process where name like '" & strProcessName & "'"

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

If objWMIService.ExecQuery(strWMIQuery).Count > 0 then
isProcessRunning = true
Else
isProcessRunning = false
End if

End Function

Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>