Solved

Error trying to open external application using VB 2008 code

Posted on 2008-06-23
6
333 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

This article will show, step by step, how to integrate R code into a R Sweave document
A short article about a problem I had getting the GPS LocationListener working.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

809 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