none
VBscript and Process Responding to flag a script exit? RRS feed

  • Question

  • Hey All

    I work for a small game company called The Good Mood Creators and I am trying to build a software kit that can be handed to someone, and with minimal effort on their part. Copy the folder to their PC, plug in an xbox controller, click the BEGIN.*** and play while our testing tools and streaming software have a chance to successfully start.

    FYI I do not program for our game..

    The tool I am including with this kit is a controller emulator (XBCE) that allows us to print controller input directly to the screen.

    I am using Open Broadcasting Software to stream gameplay to a private twitch channel via a simple batch called in this vb.

    My problem is that XBCE often hangs, and with some computers requires reinstalling .NET frameworks as well as the full directx distribution before updating again to get it to start. When it works however, XBCE will hang once started 1/10 times or so, then randomly a few times in a row. I don't want the remote playtester to start recording video before the tools are started. So I wrote a script that checks to see if the program is running a short time after its been started.

    <job>

    <script language="VBScript">

    Option Explicit

    On Error GoTo 0

    Dim os
    Dim wmi
    Dim procs

    set os=CreateObject("WScript.Shell")
    set wmi = GetObject ("winmgmts:")

    os.CurrentDirectory = "C:\Users\Public\TESTPC-remote\"
    os.run "XBCE.exe"

    While True
        Set procs = wmi.ExecQuery("select * from Win32_Process Where Name = 'XBCE.exe'")
        If procs.Count > 0 Then
            Wscript.echo "Initiate Good Mood?"        
            os.run "DATA\Mekazoo.exe"
            WScript.Sleep 1000
            os.run "DATA\obsSTART.bat"
            WScript.Sleep 1000
            WScript.Quit

        Else
            WScript.Echo "Good Mood Initialization Had Failed! Please Close All Running Applications And Try Again"
            WScript.Quit
        End If
    Wend
    </script>

    </job>


    But when its hung and not responding to the task manager, the process XBCE.exe is still getting listed in Win32 Processes. The script believes all is good and initializes the stream, but XBCE wont show up on the recording because it has crashed and windows is waiting for me to wait or close.

    I have searched but to no avail have I found a way to check if the task manager thinks if XBCE is hung, then proceed to quit the script. That's all I really need. If its not hung proceed, if it's hung quit. Can someone please help?

    Edit

    I have updated the code above to reflect my current progress with this question and so you dont have to dig through my terrible formatting.




    • Edited by GMC_Bruce Thursday, January 15, 2015 2:18 AM
    Wednesday, January 14, 2015 5:08 AM

Answers

  • I was referring to the Process.Responding property in the System.Diagnostics namespace

    Net is not available to VBScript in or out of a WSF wrapper.

    Though I have this resource I dont have the ability to understand how to use this boolean..

    See above!

    I found this which I have failed to integrate with my script http://vb.mvps.org/articles/ap200009.asp

    Not applicable to your issue.

    Also I have a pretty limited knowledge on most scripting.

         You also have a limited knowledge of Windows technology and the question is really about how Windows proesses work – not about scripting.

    I already have to walk them through installing XBCE which can be a huge pain when it throws the xinput.dll is missing error. I need a script that can be run using a mostly fresh windows installing... java? Something that doesnt add a set of dev tools to the PC.

         You need to create a real installer using MSI to do what you want.  Search for many free tools that let you build installer packages.

    it sound like I'm on the right page here? Or am I overthinking this?

        Use PowerShell if you need to learn a language.  VBScript is limited and nearly obsolete.  You still cannot detect a hung app that isn’t instrumented to show that.


    ¯\_(ツ)_/¯


    • Edited by jrv Saturday, January 17, 2015 4:09 PM
    • Marked as answer by GMC_Bruce Thursday, January 22, 2015 12:17 AM
    Saturday, January 17, 2015 4:09 PM

All replies

  • That cannot be determined if the program has not been designed to support a heart beat of somem kind.

    You need to define what "crashed" or "hung" equate to. Normally "crashed" indicates that the process has terminated unexpectedly.

    If you use WMI to runt he process then WMI will have the PID which can be used t poll for the procees and detect when it has terminated.

    We can do many more things with PowerShell and even more with a C# program.  VBScript is very limited.


    ¯\_(ツ)_/¯



    • Edited by jrv Saturday, January 17, 2015 3:02 AM
    Wednesday, January 14, 2015 6:46 AM
  • Forget WSF for many reasons

    I can see you are not a WIndows programmer so the VBScript is a bit odd.  This will show you how to yse WMI and how to structure a simple test loop.

    set os=CreateObject("WScript.Shell")
    set wmi = GetObject ("winmgmts:")
    os.CurrentDirectory = "C:\Users\Public\TESTPC-remote\"
    os.run "XBCE.exe"
    
    While True
    	Set procs = wmi.ExecQuery("select * from Win32_Process Where Name = 'XBCE.exe'")
    	If prcs.Count > 0 Then
    		wscript.echo "Initiate Good Mood?"
    		os.run "DATA\Mekazoo.exe"
    		WScript.Sleep 1000
    		os.run "DATA\obsSTART.bat"
    		WScript.Sleep 1000
    		WScript.Quit
    	Else
    		WScript.Echo "Good Mood Initialization Has Failed! Please Close All Running Applications And Try Again"
    		WScript.Quit
    	End If
    Wend
    This has nothing to do with .Net proceses.  It is just WMI checking for the existence of a process.  You can do it in a loop or in a fall through.


    ¯\_(ツ)_/¯


    • Edited by jrv Wednesday, January 14, 2015 6:56 AM
    Wednesday, January 14, 2015 6:56 AM
  • I was referring to the Process.Responding property in the System.Diagnostics namespace

    http://msdn.microsoft.com/en-us/library/system.diagnostics.process.responding.aspx

    [MonitoringDescriptionAttribute("ProcessResponding")]
    public bool Responding { get; }

    Though I have this resource I dont have the ability to understand how to use this boolean..

    I found this which I have failed to integrate with my script

    http://vb.mvps.org/articles/ap200009.asp

    I also found this post on the forums

    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/5529600b-24ab-4571-894d-cb88dccc8985/vbscript-process-ready

    ..where Bill Stewart hints at integrating the process responding but convinced the OP it wasn't necessary for his problem. But I believe that it would help me for mine as I dont need to kill the process if it detects that its hung just the active script..

    Also I have a pretty limited knowledge on most scripting. Ive worked with action script and python a bit but little of that is helping now as it was for games on as and 3d rigging with python. I would drop wsf, frankly the only reason I'm using it is because it's more advanced than a batch file. I'm pretty clueless when it comes to programming but after looking up powershell it sounds like I would need to install powershell to get the function of running the ps1 scripts. Am I right? If so I dont think this is a good idea because I would like the process of installing this folder to be as quick as possible and as noninvasive as possible. 

    I already have to walk them through installing XBCE which can be a huge pain when it throws the xinput.dll is missing error. I need a script that can be run using a mostly fresh windows installing... java? Something that doesnt add a set of dev tools to the PC.

    For the code I thank you, it is much cleaner than mine that's for sure. I will be using this until I figure out how to query for the not responding information i need.

    Thank you for your help so far I appreciate it.

    Edit:

    Hey I found some documentation on powershell in the technet library, I dont have much time today but Ill see if I can handle it. Ill edit again soon.

    Edit_2:

    So far the additional things I'll have to add to the kit that Im seeing are:

    .NET Framework 4.5 Installer

    PS C:\>Set-ExecutionPolicy RemoteSigned -- as thats the safest for the person who has no idea what powershell is.. unlike you or I for instance. xD

    And to complete the kit I need to digitally sign the script that will be starting the playtest so that it can be ran on the remote PC. Does it sound like I'm on the right page here? Or am I overthinking this?

    I have updated my original post with my current progress with the script.

    • Edited by GMC_Bruce Thursday, January 15, 2015 2:19 AM
    Wednesday, January 14, 2015 10:27 PM
  • vbscript cannot acces that namespace.  In any case the process has to be designed to support that diagnostic.  It Xbox is then yuo would either need a compiled program to access that namespace or, you could possible use PowerShell.


    ¯\_(ツ)_/¯

    Thursday, January 15, 2015 2:31 AM
  • In powershell:

    PS >$p=[System.Diagnostics.Process]::Start('notepad')
    PS >$p.Responding
    True
    # now kill notepad
    PS >$p.Responding
    False

    Not available to VBScript.


    ¯\_(ツ)_/¯

    Thursday, January 15, 2015 2:37 AM
  • I have a few questions that I haven't got the vocabulary to figure out I guess.

    -Is there anyway to automate changing the execution policy?

    I tried sending powershell two commands from a ps1. Set-ExecutionPolicy Restricted and Set-ExecutionPolicy Unrestricted. Obviously it blocks the script from running to change from restricted. So I either needed a way through the problem or around it. I could ask the person playtesting to Win+R powershell.exe and type Set-ExecutionPolicy to Unrestricted and then include a line in the script to change it back once everything has started. The problem with this is the user having to change the executionpolicy every time they try to play, and the biggest reason I dont like this is that the user has to mess with powershell at all. That was my way around the problem.

    My way through the problem was to find a way to bypass the execution policy. I tried running a few lines of code I picked up here in cmd as a batch file and a javascript file. The line I ran was:

    http://stackoverflow.com/questions/9271681/how-to-run-powershell-script-even-if-set-executionpolicy-is-banned

    powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File <C:\Users\Public\TESTPC-remote\switchrun.ps1>

    Batch through cmd gave me bad syntax, JS basically said the same thing and suggested adding semicolons to fix the problems.

    -What is the script syntax to start a diagnostic process and then check to see if its true?

    I can not figure out how to write the script to both start XBCE as a diagnostic process and then immediately after see if its responding. I can send the command to start but powershell doesnt move to the next line.

    #
    $p=[System.Diagnostics.Process]::Start('C:\Users\Public\TESTPC-remote\XBCE.exe')
    While $p.Responding = True

    Invoke and start both cause powershell to stop..

    -Can I use this command and chain the start commands together?

    After playing with '$p=[System.Diagnostics.Process]::Start' and $p.Responding it seems like the shell just checks the last program started. Is this correct?

    While writing the script I thought about the possibility of running a program, checking to see if responding equals true as a case to start the next program, or else stop the previous process and close the session. Here's my gibberish with that:

    $p=[System.Diagnostics.Process]::Start('C:\Users\Public\TESTPC-remote\XBCE.exe')
    
    While $p.Responding = True
        $p=[System.Diagnostics.Process]::Start('C:\Users\Public\TESTPC-remote\Mekazoo.exe')
    
        Else Stop-Process ('XBCE.exe')
            Exit-PSSession
    
    While $p.Responding = True
        $p=[System.Diagnostics.Process]::Start('C:\Users\Public\TESTPC-remote\OBS.exe')
    
        Else Stop-Process ('Mekazoo.exe', 'XBCE.exe')
            Exit-PSSession

    I have more questions but honestly with how many people have viewed my question vs answered it's clear I'm just an idiot and need to read more.. but Ill keep posting.

    Just.. someone please tell me if this code is even close to working? Can anyone think of something more simple for my application? My first script starts the game, but cant detect if everything has started. This script starts the controller emulator and gets stuck.

    • Edited by GMC_Bruce Saturday, January 17, 2015 1:15 AM
    Saturday, January 17, 2015 1:00 AM
  • I have a few questions that I haven't got the vocabulary to figure out I guess.

    -Is there anyway to automate changing the execution policy?

    I tried sending powershell two commands from a ps1. Set-ExecutionPolicy Restricted and Set-ExecutionPolicy Unrestricted. Obviously it blocks the script from running to change from restricted. So I either needed a way through the problem or around it. I could ask the person playtesting to Win+R powershell.exe and type Set-ExecutionPolicy to Unrestricted and then include a line in the script to change it back once everything has started. The problem with this is the user having to change the executionpolicy every time they try to play, and the biggest reason I dont like this is that the user has to mess with powershell at all. That was my way around the problem.

    My way through the problem was to find a way to bypass the execution policy. I tried running a few lines of code I picked up here in cmd as a batch file and a javascript file. The line I ran was:

    http://stackoverflow.com/questions/9271681/how-to-run-powershell-script-even-if-set-executionpolicy-is-banned

    powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File <C:\Users\Public\TESTPC-remote\switchrun.ps1>

    Batch through cmd gave me bad syntax, JS basically said the same thing and suggested adding semicolons to fix the problems.

    -What is the script syntax to start a diagnostic process and then check to see if its true?

    I can not figure out how to write the script to both start XBCE as a diagnostic process and then immediately after see if its responding. I can send the command to start but powershell doesnt move to the next line.

    #
    $p=[System.Diagnostics.Process]::Start('C:\Users\Public\TESTPC-remote\XBCE.exe')
    While $p.Responding = True

    Invoke and start both cause powershell to stop..

    -Can I use this command and chain the start commands together?

    While writing the script I have now I thought about the possibility of running a program, check to see if responding equals true as a case to start the next program, or else stop the previous process and close the session. Here's my gibberish with that:

    $p=[System.Diagnostics.Process]::Start('C:\Users\Public\TESTPC-remote\XBCE.exe')
    
    While $p.Responding = True
        $p=[System.Diagnostics.Process]::Start('C:\Users\Public\TESTPC-remote\Mekazoo.exe')
    
        Else Stop-Process ('XBCE.exe')
            Exit-PSSession
    
    While $p.Responding = True
        $p=[System.Diagnostics.Process]::Start('C:\Users\Public\TESTPC-remote\OBS.exe')
    
        Else Stop-Process ('Mekazoo.exe', 'XBCE.exe')
            Exit-PSSession

    I have more questions but honestly with how many people have viewed my question vs answered it's clear I'm just an idiot and need to read more.. but Ill keep posting.




    Youneed to drop back andlearn a bit more about how software based systems wotj and how progrmming systems work.

    THe code you posted cannot funciton because it makes no technical sense.

    We cannot answer every little questionfor you. You need to spend time learning the basics and ask quesitons when a real issue confuses you.

    You cannot use a non-existent variable in a loop test becase it wil always evaluate to false and the loop will never execute.  This si programming 101.

    Execution policy IS automated via Group Policy. Please as you domain admmisn or Netowrk Admmin to explain the to you. 

    Your original question has been answered.  If you have another issue please open a new topic.


    ¯\_(ツ)_/¯

    Saturday, January 17, 2015 1:14 AM

  • I know that the code I posted wont work, I even called it gibberish. Its a mental map of how the script will be written so I can focus on looking up one problem at a time. And frankly I haven't found anything like my problem so far during this week of research, which is why I have been updating my previous post to create sort of a script journal.

    I have the basic understanding of programming, you just threw powershell and couple commands at me and expected them to stick and I happily decided to use my time following your rabbit hole of information. I thought maybe you would be more understanding and apt to help me with what seems to be a pretty simple process if I just attempted what you have suggested honestly, especially after I repeatedly said this is not my expertise but I guess I was wrong.

    I wasn't asking the community those questions about powershell, they were directed at you. As you were the one telling me to do these things.

    And finally as for my original question, you're happy calling this thread answered with the statement, "No?" You want to split the thread which would in turn split my research and our work on my goal? Nah man, Ill just figure it out for myself. Thanks for your help.

    Saturday, January 17, 2015 2:53 AM
  • That cannot be determined if the program has not been designed to support a heart beat of somem kind.

    You need to define what "crashed" or "hung" equate to. Normally "crashed" indicates that the process has terminated unexpectedly.

    If you use WMI to runt he process then WMI will have the PID which can be used t poll for the procees and detect when it has terminated.

    We can do many more things with PowerShell and even more with a C# program.  VBScript is very limited.


    ¯\_(ツ)_/¯




    I repeat...the answer to your question is this.

    ¯\_(ツ)_/¯

    • Proposed as answer by jrv Saturday, January 17, 2015 3:02 AM
    Saturday, January 17, 2015 3:02 AM
  • It was definitely a start in a good direction, but then you totally confused me a post later. You said not to use wsf, then posted a cleaned up version of my script, then you said powershell was the only thing besides c# that lets you check to see if a process is responding. I dont know why I repeating what you said lol It's right there. 

    To speak directly at the post, I can not determine if the program has a heart beat of any kind because I did not write it. I wrote an email to a developer of the application 2 days ago about this very thing.

    Saturday, January 17, 2015 3:19 AM
  • I am sorry if the answer was too technical.  I had no other choice.

    Feel free to find a different answer if it will make you feel better. 


    ¯\_(ツ)_/¯

    Saturday, January 17, 2015 3:36 AM
  • This question is a support question for whoever wrote your application. It isn't a question we can answer for you in a scripting forum.


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by jrv Saturday, January 17, 2015 4:07 PM
    Saturday, January 17, 2015 3:47 PM
    Moderator
  • I was referring to the Process.Responding property in the System.Diagnostics namespace

    Net is not available to VBScript in or out of a WSF wrapper.

    Though I have this resource I dont have the ability to understand how to use this boolean..

    See above!

    I found this which I have failed to integrate with my script http://vb.mvps.org/articles/ap200009.asp

    Not applicable to your issue.

    Also I have a pretty limited knowledge on most scripting.

         You also have a limited knowledge of Windows technology and the question is really about how Windows proesses work – not about scripting.

    I already have to walk them through installing XBCE which can be a huge pain when it throws the xinput.dll is missing error. I need a script that can be run using a mostly fresh windows installing... java? Something that doesnt add a set of dev tools to the PC.

         You need to create a real installer using MSI to do what you want.  Search for many free tools that let you build installer packages.

    it sound like I'm on the right page here? Or am I overthinking this?

        Use PowerShell if you need to learn a language.  VBScript is limited and nearly obsolete.  You still cannot detect a hung app that isn’t instrumented to show that.


    ¯\_(ツ)_/¯


    • Edited by jrv Saturday, January 17, 2015 4:09 PM
    • Marked as answer by GMC_Bruce Thursday, January 22, 2015 12:17 AM
    Saturday, January 17, 2015 4:09 PM