9 Replies - 16527 Views - Last Post: 20 July 2011 - 07:14 AM Rate Topic: -----

#1 bob12321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 19-July 11

Win32Exception “The System Cannot Find the File Specified”

Posted 19 July 2011 - 11:02 AM

I want the program to run a batch file (IP) which is both in resources and in the application path (i.e. bin/debug and /release). I want it run on a relative path (so wherever I take it, it can be run in a portable manner)

The batch file works when double clicked by itself and when I use an absolute path, it opens correctly.

I keep on getting win32exception "cannot find the file specified". I have checked and the computer is opening the right file and finding it, but it is not executing it. Here is my code. I have tried everything on the internet and nothing has worked...

 Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim OK = MessageBox.Show("Are you sure you want to renew the computer's IP?", "IP Renew?", MessageBoxButtons.OKCancel)
If OK = DialogResult.OK Then
Dim IP As New ProcessStartInfo
IP.FileName = Application.StartupPath & "\IP.bat"
IP.WindowStyle = ProcessWindowStyle.Hidden
Process.Start(IP)
End If
End Sub 


And here is the exception detail:
 System.ComponentModel.Win32Exception was unhandled
ErrorCode=-2147467259
Message=The system cannot find the file specified
NativeErrorCode=2
Source=System
StackTrace:
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at Internet_Connection_Availability.Form1.Button3_Click_1(Object sender, EventArgs e) Form1.vb:line 228
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 Internet_Connection_Availability.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:


By the way, I am a beginner, so I might not be able to understand a lot of things!

Is This A Good Question/Topic? 0
  • +

Replies To: Win32Exception “The System Cannot Find the File Specified”

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,169
  • Joined: 12-June 08

Re: Win32Exception “The System Cannot Find the File Specified”

Posted 19 July 2011 - 11:09 AM

Slap a break point on that first section of code, line 5. Step over that and see what the value of "IP.FileName" is. I bet it is not what you expect. This is a great example to hone those Debugging (tutorial) skills!

This post has been edited by modi123_1: 19 July 2011 - 11:09 AM

Was This Post Helpful? 0
  • +
  • -

#3 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Win32Exception “The System Cannot Find the File Specified”

Posted 19 July 2011 - 01:05 PM

After you take modi123_1 advice, check the actual path. Application.StartupPath is the path where the exe file is created and that depends on solution's configuration (Release or Debug). I would suggest you to load every file your application needs as a resource. This way you don't have to worry if the file is copied to the newest build path.

Don't mind me, I sleep with my eyes open. Go with modi123_1's suggestion.

This post has been edited by Ionut: 19 July 2011 - 01:06 PM

Was This Post Helpful? 0
  • +
  • -

#4 bob12321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 19-July 11

Re: Win32Exception “The System Cannot Find the File Specified”

Posted 20 July 2011 - 06:07 AM

View Postmodi123_1, on 19 July 2011 - 11:09 AM, said:

Slap a break point on that first section of code, line 5. Step over that and see what the value of "IP.FileName" is. I bet it is not what you expect. This is a great example to hone those Debugging (tutorial) skills!


Ok i did what you said... it appears the error is thrown when I say

 Process.start(IP) 


Any reason why...

Because I am using relative path, do I have to use a different statement? Please help!

When I use the same code but for an absolute path it works...

What is the problem then!
Was This Post Helpful? 0
  • +
  • -

#5 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Win32Exception “The System Cannot Find the File Specified”

Posted 20 July 2011 - 06:20 AM

Are you sure that your file exist in the directory? Application.StartupPath contains something like this:
HardLetter:\YourProjectFolder\bin\Debug\

This post has been edited by NoBrain: 20 July 2011 - 06:20 AM

Was This Post Helpful? 0
  • +
  • -

#6 bob12321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 19-July 11

Re: Win32Exception “The System Cannot Find the File Specified”

Posted 20 July 2011 - 06:42 AM

Yes I am convinced, i have checked loads of times and included it in project

It even says that it is proceeding to run the file!
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,169
  • Joined: 12-June 08

Re: Win32Exception “The System Cannot Find the File Specified”

Posted 20 July 2011 - 06:43 AM

You said you debugged up to some point in your code - what does the "IP" variable look like before it's ran? Is the path right there?
Was This Post Helpful? 0
  • +
  • -

#8 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Win32Exception “The System Cannot Find the File Specified”

Posted 20 July 2011 - 06:44 AM

what do your absolute path looks like

This post has been edited by NoBrain: 20 July 2011 - 06:47 AM

Was This Post Helpful? 0
  • +
  • -

#9 bob12321  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 19-July 11

Re: Win32Exception “The System Cannot Find the File Specified”

Posted 20 July 2011 - 07:11 AM

The relative paths area all correct... I even tried resources but that returned the same error...

My absolute path is C://IP.bat
Was This Post Helpful? 0
  • +
  • -

#10 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Win32Exception “The System Cannot Find the File Specified”

Posted 20 July 2011 - 07:14 AM

uhm ok try to put as absolute path the path to your file in your project directory and see what happens. Also as modi suggest when debugging check are the paths correct in your IP object. you can debug.print() then if it will be easier for you

This post has been edited by NoBrain: 20 July 2011 - 07:15 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1