Solved

Error trying to open external application using VB 2008 code

Posted on 2008-06-23
6
332 Views
Last Modified: 2013-11-26
I receive this error

 System.ComponentModel.Win32Exception was unhandled
  ErrorCode=-2147467259
  Message="The specified executable is not a valid Win32 application."
  NativeErrorCode=193
  Source="System"
  StackTrace:

       at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)    at System.Diagnostics.Process.Start()    at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)    at System.Diagnostics.Process.Start(String fileName, String userName, SecureString password, String domain)    at WindowsApplication1.Form1.Command1_Click(Object sender, EventArgs e) in C:\Documents and Settings\noblem\My Documents\Visual Studio 2008\Projects\OpenClose\OpenClose\Form1.vb:line 77    at System.Windows.Forms.Control.OnClick(EventArgs e)    at System.Windows.Forms.Button.OnClick(EventArgs e)    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)    at System.Windows.Forms.Control.WndProc(Message& m)    at System.Windows.Forms.ButtonBase.WndProc(Message& m)    at System.Windows.Forms.Button.WndProc(Message& m)    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)    at System.Windows.Forms.Application.Run(ApplicationContext context)    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)    at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81    at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)    at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

The code works fine when It is listed this way going to a file that doesn't need a user name or Password

Dim proc As New System.Diagnostics.Process()


        'proc = Process.Start("C:\Documents and Settings\noblem\Desktop\testFile.txt", "")
Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click

 

Dim sfile = "C:\Documents and Settings\noblem\Desktop\testFile.txt"

        Dim sUser As String = "user"

        Dim sPass As String = "password"

        Dim SDomain As String = "mydomain"

        Dim newPass As New Security.SecureString()

        For Each c As Char In sPass

            newPass.AppendChar(c)

        Next c

 

        Dim proc As New System.Diagnostics.Process()

 

        proc = Process.Start(sfile, sUser, newPass, SDomain)

End Sub

Open in new window

0
Comment
Question by:KingNoble1
  • 3
  • 3
6 Comments
 

Author Comment

by:KingNoble1
ID: 21854616
Just adjusted the questions layout
0
 
LVL 22

Expert Comment

by:cookre
ID: 21860990
You mention it works fine for files that don't need a password.

Does this mean you're trying to get to files with a different owner and to which the running process hasn't rights, or to OS encrypted files, or to files protected by some 3rd party software?

Note that this Start() overload specifies the user under which the spawned process will run.
0
 

Author Comment

by:KingNoble1
ID: 21861121
I'm trying to open up some shared files on a network server.  I can navigate to them and open them with my PC, just not with the VB project.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 22

Accepted Solution

by:
cookre earned 500 total points
ID: 21862303
In that case, the target file, 'sfile', must be fully qualified.

To map a drive:
http://www.mredkj.com/vbnet/vbnetmapdrive.html

A UNC:
\\computername\sharename\path\filename

might work, since the referencing process will be running under the remote user's credentials, but I've never tried it that way, and am skeptical.

0
 

Author Comment

by:KingNoble1
ID: 21868719
This works as an acceptable work-around, still would like to know why the built in function doesn't work correctly.  The program will tell me if the user name and or password is not correct if I intentionally make it not correct that is.

Dim sfile = "C:\Documents and Settings\noblem\Desktop\testFile.txt"
        Dim sUser As String = "user"
        Dim sPass As String = "password"
        Dim SDomain As String = "mydomain"
        Dim newPass As New Security.SecureString()
        For Each c As Char In sPass
            newPass.AppendChar(c)
        Next c
 
        Dim proc As New System.Diagnostics.Process()
 
        proc = Process.Start(sfile, sUser, newPass, SDomain)

"Cookre"  thanks for your help
0
 
LVL 22

Expert Comment

by:cookre
ID: 21892256
In the original code,  the spawned process would run - on the local box -  as the specified user, processing sFile, which was pointing to a local file.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

22 Experts available now in Live!

Get 1:1 Help Now