Solved

ShellWait does not work in VB Visual Studio 2005

Posted on 2006-11-01
8
325 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 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 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 85

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

749 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