Solved

ShellWait does not work in VB Visual Studio 2005

Posted on 2006-11-01
8
315 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

759 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

18 Experts available now in Live!

Get 1:1 Help Now