?
Solved

ShellWait does not work in VB Visual Studio 2005

Posted on 2006-11-01
8
Medium Priority
?
333 Views
Last Modified: 2012-06-27
I have a ShellWait function that works in VB6, but not in Visual Studio 2005.  How would I launch the following command and have it wait until it completes?

Call ShellWait("net use \\Server\Share Password /user:UserName")

Thanks for the help!
BPL
0
Comment
Question by:bpl5000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 17852029
http://www.devx.com/dotnet/Article/7914/1954?pf=true


in short:


      ' create a new process
      Dim myProcess As Process = _
         System.Diagnostics.Process.Start("net use \\Server\Share Password /user:UserName")
   
      ' wait until it exits
      myProcess.WaitForExit()
   
0
 
LVL 5

Author Comment

by:bpl5000
ID: 17852252
When I run this, it gives the error "Declaration expected" for the line "myProcess.WaitForExit()".  What am I doing wrong?  I copied and pasted the lines.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17852299
I don't see what you made "wrong"...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17852450
Show us your code...
0
 
LVL 5

Author Comment

by:bpl5000
ID: 17852460
Here's what my code looks like:

Public Class Form1
    Private Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long

    'create a new process
    Dim myProcess As Process = _
    System.Diagnostics.Process.Start("net use \\Server\Share Password /user:UserName")

    ' wait until it exits
     myProcess.WaitForExit()


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim rv As Integer

        'SetCurrentDirectory("\\winapps.bcs\Barclay")
        'rv = Shell("\\Server\Share Password /user:UserName\program.exe", vbNormalFocus)
        Call Shell("\\Server\Share Password /user:UserName\program.exe", AppWinStyle.NormalFocus)

    End Sub

End Class
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17852524

Public Class Form1
    Private Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


      'create a new process
      Dim myProcess As Process = _
      System.Diagnostics.Process.Start(""\\Server\Share Password /user:UserName\program.exe"")

      ' wait until it exits
       myProcess.WaitForExit()

    End Sub

End Class
0
 
LVL 5

Author Comment

by:bpl5000
ID: 17852653
Could I do the same thing like this?

Call Shell("\\Server\Share Password /user:UserName\program.exe", AppWinStyle.NormalFocus, True)

It seems the 3rd parameter decides whether or not to wait for the program to finish.  Is this the case?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17852681
the myProcess.WaitForExit() replaces that functionality.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question