KingNoble1
asked on
Error trying to open external application using VB 2008 code
I receive this error
System.ComponentModel.Win3 2Exception was unhandled
ErrorCode=-2147467259
Message="The specified executable is not a valid Win32 application."
NativeErrorCode=193
Source="System"
StackTrace:
at System.Diagnostics.Process .StartWith CreateProc ess(Proces sStartInfo startInfo) at System.Diagnostics.Process .Start() at System.Diagnostics.Process .Start(Pro cessStartI nfo startInfo) at System.Diagnostics.Process .Start(Str ing fileName, String userName, SecureString password, String domain) at WindowsApplication1.Form1. Command1_C lick(Objec t sender, EventArgs e) in C:\Documents and Settings\noblem\My Documents\Visual Studio 2008\Projects\OpenClose\Op enClose\Fo rm1.vb:lin e 77 at System.Windows.Forms.Contr ol.OnClick (EventArgs e) at System.Windows.Forms.Butto n.OnClick( EventArgs e) at System.Windows.Forms.Butto n.OnMouseU p(MouseEve ntArgs mevent) at System.Windows.Forms.Contr ol.WmMouse Up(Message & m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Contr ol.WndProc (Message& m) at System.Windows.Forms.Butto nBase.WndP roc(Messag e& m) at System.Windows.Forms.Butto n.WndProc( Message& m) at System.Windows.Forms.Contr ol.Control NativeWind ow.OnMessa ge(Message & m) at System.Windows.Forms.Contr ol.Control NativeWind ow.WndProc (Message& m) at System.Windows.Forms.Nativ eWindow.De buggableCa llback(Int Ptr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.Unsaf eNativeMet hods.Dispa tchMessage W(MSG& msg) at System.Windows.Forms.Appli cation.Com ponentMana ger.System .Windows.F orms.Unsaf eNativeMet hods.IMsoC omponentMa nager.FPus hMessageLo op(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Appli cation.Thr eadContext .RunMessag eLoopInner (Int32 reason, ApplicationContext context) at System.Windows.Forms.Appli cation.Thr eadContext .RunMessag eLoop(Int3 2 reason, ApplicationContext context) at System.Windows.Forms.Appli cation.Run (Applicati onContext context) at Microsoft.VisualBasic.Appl icationSer vices.Wind owsFormsAp plicationB ase.OnRun( ) at Microsoft.VisualBasic.Appl icationSer vices.Wind owsFormsAp plicationB ase.DoAppl icationMod el() at Microsoft.VisualBasic.Appl icationSer vices.Wind owsFormsAp plicationB ase.Run(St ring[] commandLine) at WindowsApplication1.My.MyA pplication .Main(Stri ng[] Args) in 17d14f5c-a337-4978-8281-53 493378c107 1.vb:line 81 at System.AppDomain._nExecute Assembly(A ssembly assembly, String[] args) at System.AppDomain.ExecuteAs sembly(Str ing assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.Hos tingProces s.HostProc .RunUsersA ssembly() at System.Threading.ThreadHel per.Thread Start_Cont ext(Object state) at System.Threading.Execution Context.Ru n(Executio nContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHel per.Thread Start()
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:\Document s and Settings\noblem\Desktop\te stFile.txt ", "")
System.ComponentModel.Win3
ErrorCode=-2147467259
Message="The specified executable is not a valid Win32 application."
NativeErrorCode=193
Source="System"
StackTrace:
at System.Diagnostics.Process
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:\Document
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
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.
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.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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\te stFile.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
Dim sfile = "C:\Documents and Settings\noblem\Desktop\te
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.
ASKER