+ Post New Thread
Page 1 of 3 123 LastLast
Results 1 to 15 of 31
Coding Thread, error with WaitForExit() in Coding and Web Development; Hi there My code is written in vb.net, What am doing is I want to tell the compiler to wait ...
  1. #1

    Join Date
    Aug 2013
    Posts
    37
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    error with WaitForExit()

    Hi there

    My code is written in vb.net, What am doing is I want to tell the compiler to wait until vbs file finished exeutition then continuoe the rest of the code as the following:


    myProcess_uninstall = Process.Start("filepath.vbs")
    myProcess_uninstall.WaitForExit()



    The problem here is the error message (Object reference not set to an instance of an object) when using myProcess_uninstall.WaitForExit()

    So, any idea how to solve it.


  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,689
    Thank Post
    334
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    What have you declared myProcess_uninstall as? Unless it's a process that won't work.

    Example:

    Code:
            Dim MyProcess As Process = Process.Start("C:\test\echo.vbs")
            MyProcess.WaitForExit()
            MsgBox("ended")
    Won't show msgbox until the process ends. If it's complaining about your object I'd take a guess that "myprocess_uninstall" isn't declared as a process, and rather a return code variable?

    Steve

  3. #3

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,655
    Thank Post
    516
    Thanked 2,443 Times in 1,891 Posts
    Blog Entries
    24
    Rep Power
    831
    Looks like you're not using the Process class correctly. This is Microsoft's C# example

    Code:
    // Start the child process.
     Process p = new Process(); 
    // Redirect the output stream of the child process. 
    p.StartInfo.UseShellExecute = false; 
    p.StartInfo.RedirectStandardOutput = true; 
    p.StartInfo.FileName = "Write500Lines.exe"; 
    p.Start(); // Do not wait for the child process to exit before
     // reading to the end of its redirected stream. 
    // p.WaitForExit(); 
    // Read the output stream first and then wait. 
    string output = p.StandardOutput.ReadToEnd(); 
    p.WaitForExit();
    So, you need to instantiate a Process, tell it what FileName you're calling and any extra options, and then run the Start method.After that, you run your WaitForExit method.

  4. #4

    Join Date
    Aug 2013
    Posts
    37
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi Steve

    I used your declaration , it's still the same error message. When I try the same code with file.exe it's worked fine. So I think (WaitForExit() function) just worked with exe files and does not accept vbs file and see it as null.

    regards

  5. #5

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,689
    Thank Post
    334
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    I just tested that and that works fine.

    Can you post exactly what you're using?

    Thanks,
    Steve

  6. #6

    Join Date
    Aug 2013
    Posts
    37
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi localzuk

    I used your code and still I got the same error, and as I told steve that waitforexit() function just worked fine with exe file.

    Regards

  7. #7

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,447
    Thank Post
    1,438
    Thanked 1,168 Times in 797 Posts
    Rep Power
    707
    Have you tried wrapping the VBS in to a CScript call?

    Code:
    Dim MyProcess As Process = Process.Start("CScript.exe C:\test\echo.vbs")
            MyProcess.WaitForExit()
            MsgBox("ended")

  8. #8

    Join Date
    Aug 2013
    Posts
    37
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi steve

    This is my code

    Dim myProcess_uninstall As New Process
    myProcess_install = Process.Start("C:\Users\admin\Desktop\OffScrub10.v bs")
    MyProcess.WaitForExit()

    MsgBox("ended")



    I have attached the vbs file.Regards
    Attached Files Attached Files

  9. #9

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,655
    Thank Post
    516
    Thanked 2,443 Times in 1,891 Posts
    Blog Entries
    24
    Rep Power
    831
    You've declared "myProcess_uninstall" then assign to "myProcess_install".

  10. #10

    Join Date
    Aug 2013
    Posts
    37
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Sorry this is my code



    Dim myProcess_uninstall As New Process


    myProcess_uninstall = Process.Start("C:\Users\admin\Desktop\OffScrub10.v bs")
    myProcess_uninstall.WaitForExit()


    Where Still not working

    Regards

  11. #11

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,447
    Thank Post
    1,438
    Thanked 1,168 Times in 797 Posts
    Rep Power
    707
    Quote Originally Posted by engineer_z View Post
    Sorry this is my code



    Dim myProcess_uninstall As New Process


    myProcess_uninstall = Process.Start("C:\Users\admin\Desktop\OffScrub10.v bs")
    myProcess_uninstall.WaitForExit()


    Where Still not working

    Regards
    Try it wrapped in a Cscript call; if it is the fact it's not an exe, this should fix it:

    Code:
    Dim myProcess_uninstall As New Process
    
    myProcess_uninstall = Process.Start("CScript.exe C:\Users\admin\Desktop\OffScrub10.vbs")
    myProcess_uninstall.WaitForExit()

  12. #12

    Join Date
    Aug 2013
    Posts
    37
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi LosOjos

    unfortunately still the same error

    Regards

  13. #13
    SovietRussia's Avatar
    Join Date
    Mar 2013
    Location
    Powys, Wales
    Posts
    607
    Thank Post
    67
    Thanked 131 Times in 102 Posts
    Rep Power
    43
    Try this:


    Code:
    Dim startInfo As New ProcessStartInfo
    startInfo.FileName = "cscript"
    startInfo.Arguments = "C:\Users\admin\Desktop\OffScrub10.vbs"
    Process.Start(startInfo)
    startInfo.WaitForExit()
    Last edited by SovietRussia; 25th November 2013 at 10:57 AM.

  14. #14

    Join Date
    Aug 2013
    Posts
    37
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi SovietRussia

    I have tried it and it give me error with line (
    startInfo.WaitForExit()) ,
    The error is "
    WaitForExit() is not a member of system.Diagnostics.processStartInfo"

    Regards

  15. #15

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,447
    Thank Post
    1,438
    Thanked 1,168 Times in 797 Posts
    Rep Power
    707
    Missing a step:

    Code:
    Dim myProcess_uninstall As New Process
    Dim startInfo As New ProcessStartInfo
    startInfo.FileName = "cscript"
    startInfo.Arguments = "C:\Users\admin\Desktop\OffScrub10.vbs"
    myProcess_uninstall = Process.Start(startInfo)
    myProcess_uninstall.WaitForExit()

SHARE:
+ Post New Thread
Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 5
    Last Post: 21st January 2009, 08:58 AM
  2. DFS/FRS error with removing an old server
    By FatBoy in forum Windows
    Replies: 2
    Last Post: 23rd October 2008, 10:05 AM
  3. Error with NEW SSL Cert in OWA
    By ICTNUT in forum Windows
    Replies: 3
    Last Post: 15th November 2007, 08:35 AM
  4. Cachepilot error with myLGFL
    By philtomo-25 in forum Windows
    Replies: 2
    Last Post: 27th June 2007, 10:45 AM
  5. Stupid CMD error with logon script
    By tarquel in forum Windows
    Replies: 37
    Last Post: 14th June 2006, 09:07 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •