Solved

Error trying to open external application using VB 2008 code

Posted on 2008-06-23
6
331 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
Comment Utility
Just adjusted the questions layout
0
 
LVL 22

Expert Comment

by:cookre
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 22

Accepted Solution

by:
cookre earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

762 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

10 Experts available now in Live!

Get 1:1 Help Now