Solved

Error trying to open external application using VB 2008 code

Posted on 2008-06-23
6
337 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
[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
  • 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
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 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

Industry Leaders: 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!

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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 …
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 …

632 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