system.diagnostics.process will not open Excel file without Excel open first - vb.net

I have a VB.Net application in which I have a general method to open documents that exist on the local drive using system.diagnostics.process.
Public Shared Function OpenFileWithProcess(ByVal lsFileNameWithPath As String, Optional ByVal lPrintOption As PrintOutputOption = PrintOutputOption.Preview)
Try
Select Case lPrintOption
Case PrintOutputOption.Preview
Dim P As System.Diagnostics.Process
P = Process.Start(lsFileNameWithPath)
If Not P Is Nothing Then
Dim handle As IntPtr = P.Handle
SetForegroundWindow(handle)
End If
Case PrintOutputOption.Print
Dim Proc As New Process
Proc.StartInfo.FileName = lsFileNameWithPath
Proc.StartInfo.UseShellExecute = True
Proc.StartInfo.Verb = "Print"
Proc.Start()
End Select
Catch ex As Exception
If oSQL.Key_Developer Then
Stop
End If
Throw ex
End Try
End Function
On some computers that have Windows8 and OFfice2010, this method will not open an Excel file without Excel being open first. Instead it will error with "Run-Time Error 2147467259 (80004005). An error occurred in sending the command to the application".
If Excel is open prior to the method call, then the file opens just fine.
Some additional environment info:
- VB.NET application compiled to .Net Framework 4
- Application is deployed on Windows 7, 8 and 8.1
I could trap for the error and try to start the process again using the Excel session that hangs open after the error but I'm wondering if someone can tell me or help me figure out what is going on here.
Thank you for your time.

Related

Open External Password Protected Database with Automation in Access Runtime Version

I want to open an external password protected database in separate window. I have tried follwoing code (shared by Isladogs from MendipDataSystems on some forum):
Public Function RunExternalDatabase() As Boolean
Dim app As Access.Application, strPath As String
'Start a new MSAccess application
Set app = New Access.Application
'Open the remote database and run a macro, then close the remote database
With app
'Syntax: .OpenCurrentDatabase(filepath, Exclusive, strPassword) - the last 2 items are optional
strPath = "C:\Programs\MendipDataSystems\JATFA\JATFA.accdb" 'replace with your file path
.OpenCurrentDatabase strPath, True, "password"
' .DoCmd.RunMacro "mcrRefreshPersTable" 'run your macro
.CloseCurrentDatabase 'closes external database as that is current
End With
'Quit the spawned app
app.Quit acQuitSaveNone
Set app = Nothing
'Quit the current app - optional
Application.Quit acQuitSaveNone
End Function
Above code works fine in full Access but gives error for those users who are using Access runtime version. The line of code that gives error is Set App = New Access.Application.
How can I fix it OR is there any alternative method to get the purpose done?
Purpose is to open the password encrypted database in separate window in Access runtime version without entering the password manually.
Best Regards

Windows 10 COMException HRESULT:0X800A03EC while saving Excel file

I have a VB.Net windows forms application which is working fine in windows 7 environment.
Now, I want to upgrade to windows 10. So I have started to test my application in windows 10 server machine.
I am getting an Exception (Exception from HRESULT:0X800A03EC) while saving a dynamically generated file in one of the folders on server.
I have identified the issue is not with the permissions.
'getting exception at this line of code.
xlApp.Workbooks(1).SaveAs(filename , xl.XlFileFormat.xlHtml)
Code for reference:
Private Sub VierwInBrowser(ByVal xlApp As xl.Application)
Dim fileName As String = String.Format("{0}\{1}", "C:\Data", GetUniqueFileName())
Try
xlApp.Workbooks(1).SaveAs(fileName, xl.XlFileFormat.xlHtml)
Catch ex as Exception
Messagebox.Show(ex.Message)
End Try
xlApp.Quit()
xlApp = Nothing
GC.Collect()
browser.Visible = True
browser.Navigate(fileName)
browser.BringToFront()
End Sub
I have identified that the issue is with converting the excel sheet to html page in windows 10.
For this I have found a solution at https://support.microsoft.com/en-in/help/922850/error-message-in-office-when-a-file-is-blocked-by-registry-policy-sett

Open raster file error: A Debugger is attached to w3wp exe but not configured

I have written a vb.net function to open a raster file. The function is as follows:
Public Function OpenRaster(ByVal directoryName As String, ByVal fileName As String) As IRaster
Dim workspaceFactory As IWorkspaceFactory
Dim rasterWorkspace As IRasterWorkspace
Dim rasterDataset As IRasterDataset = Nothing
Try
workspaceFactory = New RasterWorkspaceFactory
ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass()
rasterWorkspace = TryCast(workspaceFactory.OpenFromFile(directoryName, 0), IRasterWorkspace)
rasterDataset = rasterWorkspace.OpenRasterDataset(fileName)
Catch e As Exception
End Try
Dim pRasterLayer As IRasterLayer = New RasterLayer()
pRasterLayer.CreateFromDataset(rasterDataset)
Dim pRaster As IRaster = Nothing
pRaster = pRasterLayer.Raster
Return pRaster
End Function
The above function is throwing below error in TryCast statement :
A Debugger is attached to w3wp exe but not configured to debug this unhandled exception. To debug this expression detach the current debugger.
I searched on google also, some suggestions were to enable 32-bit in IIS application pool, but enabling this also is not making the code work

Writing to Command Line Not Working

An application I need to use (USB capture utility) has a .cmd version that I can call from my Visual Basic code. I am able to launch the application and put it in "command line mode" like this:
Public Class MyClass
Dim StreamWriteUtility As System.IO.StreamWriter
Dim StreamReadUtility As System.IO.StringReader
Dim ProcessInfo As ProcessStartInfo
Dim Process As Process
Public Sub StartUSBCapture(ByVal DataStorageLocation As String)
Dim ProcessInfo As ProcessStartInfo
Dim Process As New Process
ProcessInfo = New ProcessStartInfo("C:\FW_Qualification_Suite\data-center-windows\data-center\bin\datacenter.cmd", "-c ")
ProcessInfo.CreateNoWindow = True
ProcessInfo.UseShellExecute = False 'Must be changed if redirect set to True
ProcessInfo.RedirectStandardInput = True
Process = Process.Start(ProcessInfo)
SWUtility = Process.StandardInput
While True
SWUtility.WriteLine("run") 'Looping for test to ensure this isn't a timing issue
End While
End Sub
End Class
This launches the application and opens a separate command line window that should accept further commands (i.e., capture, run, stop, etc). However, I am having trouble getting those subsequent commands to show up in the command line window. I've tried redirecting the standard input of the process, but still nothing shows up in the console window.
Can anyone tell how I'm supposed to actually get these commands from my Visual Basic program into this application?

Object Reference Error VB.NET

I keep getting an error:
System.NullReferenceException: Object reference not set to an instance
of an object.
Everytime I run the application outside the IDE, but for some magical reason, it works fine inside the IDE. I am definitely sure the error is caused by this code as the app ran smoothly when I removed it:
Public Function GetCommonFolder() As String
On Error GoTo ErrH
Dim winPath As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
Dim commonfolderpath As String
commonfolderpath = Replace(winPath & "\MyApp Data", "\\", "\")
If My.Computer.FileSystem.DirectoryExists(commonfolderpath) = False Then
System.IO.Directory.CreateDirectory(commonfolderpath)
End If
GetCommonFolder = commonfolderpath
Exit Function
ErrH:
GetCommonFolder = ""
Msgbox("Error retrieving common folder")
End Function
Does anyone here know what is causing this annoying problem?
It seems like the user that you run the program on outside the IDE doesn't have access to the common application data folder. Try executing it by "Run as administrator". Are you running on Windows Vista or newer? Maybe you have to require UAC elevation?