1

I run my project in win 7 and xp, but there is an error message, in this project I use shell32.shell to copy and extract automatic exe file, does shell32.shell not work in windows 7 and xp? if you can, please suggest that sheell32.shell can run

Dim sc As New Shell32.Shell()
Dim pathExeOnServer As String = "\\server\UpdateProgram\"

Try
                If (Not System.IO.Directory.Exists(Path.Combine(Application.StartupPath() & "\RS_Application"))) Then
                    Directory.CreateDirectory(Path.Combine(Application.StartupPath() & "\RS_Application"))
                Else
                    'DO NOTHING
                End If

                Me.Cursor = Cursors.WaitCursor
                File.Copy(Path.Combine(pathExeOnServer, fileName & ".zip"), Path.Combine(Application.StartupPath() & "\RS_Application", fileName & ".zip"), True)
                System.IO.File.Delete(Application.StartupPath() & "\RS_Application\" & fileName & ".exe")
                Dim output As Shell32.Folder = sc.NameSpace(Application.StartupPath() & "\RS_Application")
                Dim input As Shell32.Folder = sc.NameSpace(Application.StartupPath() & "\RS_Application\" & fileName & ".zip")
                output.CopyHere(input.Items, 4)
                Me.Cursor = Cursors.Arrow
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Critical)
            End Try

error message

  • Is this a WinForms or console app? In which line the error thrown? As the first step, try adding `STAThreadAttribute` on the `Main` method in Program.vb if exists. – Tetsuya Yamamoto Sep 12 '17 at 04:25
  • this is winform, initially i run this project in windows 10 and work fine, file copy and extract file running normally, when i try to run the exe file in windows 7 and xp, then it appears his error message – Kamarur Rama Sep 12 '17 at 04:37
  • 1
    Look at the stack trace of the exception, it is not bombing in this code. The constructor of the form bombed. Always high odds that it is running on a worker thread, the VB.NET default instance feature is a very dangerous one. Write Sub New, create the Shell object there, set a breakpoint on it. Use the Debug > Windows > Threads window to verify that it runs on the main thread. Do note that this went wrong a while ago, whatever form has the Update button is already running on the wrong thread. – Hans Passant Sep 12 '17 at 07:12

0 Answers0