'Can't run Notepad from vb.net and I don't know why
I have an issue with a desktop app that is driving me crazy. I'm using vb.net in VS17 on Windows 11. My app needs to run notepad without passing it any parameters. In all my other apps Process.Start("notepad.exe") just works, but in this particular app it fails! I have also tried using Shell - and even on passing it the full path to the notepad executable it fails with "file not found" even after I checked that it does exist - and I can't figure that out either. Weird stuff.
I have done the hard work of creating the full and proper path to the executable (and I check that it really DOES exist), but the Process.Start call fails and returns this error "The remote procedure call failed". Here is my code.
Dim NPadExe As String = Environment.GetFolderPath(Environment.SpecialFolder.Windows) & "\notepad.exe"
Try
If File.Exists(NPadExe) Then
Process.Start(NPadExe)
End If
Catch ex As Exception
MessageBox.Show(NPadExe & " could not be started:" & vbCrLf & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
I know this is junior school stuff. I've done it uncountable times before. I really need a pointer here. It seems as if this particular project is missing some or other reference or config, but I can't figure out what. Any help will be appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
