Solved

ShellWait does not work in VB Visual Studio 2005

Posted on 2006-11-01
8
319 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Notepad++ how to remove delimiter : from beggning of the line? 3 105
How to Add / Edit Windows Menu 4 60
Help me. 3 54
MS Access 03, TransferText, decimal places 8 69
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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

773 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