Solved

ShellWait does not work in VB Visual Studio 2005

Posted on 2006-11-01
8
317 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
  • 4
  • 3
8 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17852299
I don't see what you made "wrong"...
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17852450
Show us your code...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 142

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 142

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now