Link to home
Start Free TrialLog in
Avatar of KingNoble1
KingNoble1Flag for United States of America

asked on

Error trying to open external application using VB 2008 code

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

Avatar of KingNoble1
KingNoble1
Flag of United States of America image

ASKER

Just adjusted the questions layout
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of cookre
cookre
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.