We have a small app to link printers and it was working before we upgraded to Windows10 - 20h2. I know we can revert back but we are trying not to because this includes a bunch of security patches.
I hope you guys can help.
...more codes here
strSelectedPrinterPath = "\\server\myprinter"
Dim objNetwork = CreateObject("WScript.Network")
**objNetwork.AddWindowsPrinterConnection(strSelectedPrinterPath)**
objNetwork.SetDefaultPrinter(strSelectedPrinterPath)
Results to:
System.Runtime.InteropServices.COMException 'Exception from HRESULT: 0x8007011B'
Any insight is highly appreciated.
Thanks...
Related
Sorry for my English, I write from Italy.
I use the Access 2007 DB in a business data management procedure in VB Net.
As is known, Access DBs expand during use and consequently I need to compact them when the program is closed.
I perform the compaction in this way
Dim MioEngine As New Microsoft.Office.Interop.Access.Dao.DBEngine
MioEngine.CompactDatabase(myAccesDB, newAccessDB,)
Application.DoEvents()
but often and not on all PCs on the network, the compaction does not finish and gives me the following error message:
The process cannot access the 'C:\myAccesDB.accdb' file because it is being used by another process
Analyzing in depth what happens, I see that when the error occurs, the .laccdb file is not closed at the time of compacting.
Is there any way other than the one I used to do the compacting safely?
I specify that all the PCs in our network are Windows 10 pro and all updated; when Windows 10 was in its infancy, I didn't get this error.
Since my comment was not enough, here's an answer:
The idea is to try to opetn .laccdb file before you try to compact the database. You can do something like this:
Dim file as System.IO.FileInfo = New System.IO.FileInfo("c:\myAccesDB.laccdb")
Dim stream As FileStream = Nothing
Try
stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None)
stream.Close()
'if stream is successfully closed, file is not in use and database can be compacted
MioEngine.CompactDatabase(myAccesDB, newAccessDB,)
Catch ex As Exception
'show some message to user that file is in use so it can try again
End Try
I worked with VB and Access ages ago, so this is only a direction that you should take.
Thanks, I'll try.
I also had a look to this:
https://support.microsoft.com/en-us/topic/office-error-accdb-remains-locked-after-oledb-connection-is-closed-37d42348-9edf-4493-a5f4-35c685af3160?ui=en-us&rs=en-us&ad=us
Where I find:
This issue is now fixed. If you launch Access, click 'File', then 'Account', then 'Update Options', and 'Update Now', this will ensure that you have the latest version, and all versions should have the fix available.
But I'm not able to find 'File' opening Access,....
I have a desktop application written in VB.net that runs a macro in an access. Recently we upgraded from office 2010 to office 365. Now when i run this application i get this error :
Exception that comes up
Error Image
Could not load file or assembly 'Microsoft.Office.Interop.Acces.Dao,Version =15.0.0.0...' or one of its dependencies'
Below is the code that causes the exception:
If _accessApp Is Nothing Then
_accessApp = New Application
End If
Try
If JobFolderPath.Length <= 0 Or JobFolderPath Is Nothing Then
Exit Sub
End If
If _accessApp.CurrentDb() Is Nothing Then
_accessApp.OpenCurrentDatabase(JobFolderPath & "somedb.mdb", False)
_accessApp.Run("SomeProcess")
Else
_accessApp.Run("SomeProcess")
End If
_accessApp.Quit(AcQuitOption.acQuitSaveNone)
Catch ex As Exception
Finally
_accessApp = Nothing
End Try
I even included teh Interop.Access.Dao verion 15 dll in the references for the project. Not sure if this way of running macros is obsolete in access 16. If so, what is the correct way of doing this?
Thanks in advance.
The error also says "or one of its dependencies", install the interop from the link below.
https://www.nuget.org/packages/Microsoft.Office.Interop.Excel/15.0.4795.1000
Click on "Manual Download on the right ...
Not an answer to your question, but a macro can be run without Access references with late binding:
Dim accObj = GetObject(JobFolderPath & "somedb.mdb") ' opens the file if not already open
accObj.Application.Run("SomeProcess") ' the .Application part might not be needed
accObj.Application.Quit(2) ' AcQuitOption.acQuitSaveNone = 2
or command line switches (also not tested):
Process.Start(JobFolderPath & "somedb.mdb" "/x SomeProcess")
Finally i was able to fix it by installing 'microsoft office 16.0 access database engine'(32 bit version) and adding the required dlls as COM references instead of normal dll references.
I have a VB.net program that I wrote and have used hundreds of times. Whilst using Windows 7 I "upgraded" to Office 2010 and IIRC had to make a few small changes to get it to work. I have now (and again I put it in quotes as I fail to see the benefits of calling it an upgrade !) "upgraded" to Windows 10 but went back to Office 2007 as I much prefer it. I am also using Visual Studio Community 2015. All of that may or may not be of help !!!
So, I run the program and it fails with the following error :
An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
KA_Newsletter.exe
Additional information: Word cannot open this document template.
(L:...\Customize Ribbon Example 2.dotm)
I have looked up the error and there is a Microsoft page ...
MS Support Bug
... that suggests this may be a Bug, it explains why it may be happening and gives a resolution but I program for fun, I'm not an expert in VB at all and it may as well be written in Russian for all it helps me !!!
I also have no idea why Word should be trying to open that Example Template either, I copy a Template of my own to create a new Word document, this is pretty basic stuff !!! This is the relevant code, any help would be very much appreciated ...
Dim myNewsLetter As String
.
.
.
If File.Exists(myNewsLetter) Then
'do nothing
Else
myTemplate = myTempFolder & "KA_Newsletter.doc"
File.Copy(myTemplate, myNewsLetter)
Create_Blank_Newsletter()
End If
.
.
.
Private Sub Create_Blank_Newsletter()
myMSWord = New Word.Application
myMSDoc = myMSWord.Documents.Open(myNewsLetter) << <Error occurs on this line
myMSWord.WindowState= Word.WdWindowState.wdWindowStateNormal
myMSWord.Visible= False
UPDATE :
Olaf, I updated the code as follows ...
myMSWord = New Word.Application
Dim inval As Object
'Marshal the object before passing it to the method.
inval = New System.Runtime.InteropServices.DispatchWrapper(myNewsLetter)
myMSDoc = myMSWord.Documents.Open(inval)
'myMSDoc = myMSWord.Documents.Open(myNewsLetter)
... but I am getting a similar error on the Open statement ...
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in KA_Newsletter.exe
Additional information: Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
Any ideas ?
The MS page says you should try something like
Dim inval As Object
'Marshal the object before passing it to the method.
inVal = New System.Runtime.InteropServices.DispatchWrapper(myNewsLetter)
myMSDoc = myMSWord.Documents.Open(inval)
We have this simple piece Where in we are registering an Addin and trying to find the Addin by looping through the list of Addins. This is not consistently reproducible on all the machines and we started seeing this on a client machine. We don't see anything wrong with the code either. We didn't see much on any of the forums. Please help.
When the code hits the for loop we get this error. Runtime Error -2147310770(8002801d). method 'comaddins' of object '_application' failed.
For Each oAddin In oWordApp.COMAddIns
Sub Main()
Call RegisterAddin
Dim oWordApp As New Word.Application
Dim oAddin As Office.COMAddIn
**For Each oAddin In oWordApp.COMAddIns**
If oAddin.DESCRIPTION = "TestingCom Addin" Then
oAddin.Connect = True
End If
Next
Try casting another Microsoft.Office.Interop.Word._Application variable to Word.Application, then use Microsoft.Office.Core.COMAddIn to get items in the _Application.COMAddIns collection.
I was able to fix this using the below link. Looks like the previous/latest version of Office was not uninstalled properly and was causing problems with Office 2007.
http://kb.palisade.com/index.php?pg=kb.page&id=528
I have Client-Server environment and developed a project for Client-Server.
I need to share a folder of my Server machine programmatically using VB.NET
Please help me.
Here's one example which shows the concept using ManagmentClass. It's C# but easily convertible to VB.NET:
UPDATE:
Directory.CreateDirectory("C:\MyTestShare")
Dim managementClass As New ManagementClass("Win32_Share")
Dim inParams As ManagementBaseObject = managementClass.GetMethodParameters("Create")
inParams.Item("Description") = "My Files Share"
inParams.Item("Name") = "My Files Share"
inParams.Item("Path") = "C:\MyTestShare"
inParams.Item("Type") = 0
If (DirectCast(managementClass.InvokeMethod("Create", inParams, Nothing).Properties.Item("ReturnValue").Value, UInt32) <> 0) Then
Throw New Exception("Unable to share directory.")
End If
I have code that looks similar to this which works on vista and win2k3 machines, but when i try it on Windows server 2008 R2 (with recent updates) it fails with an "access denied" error. I've tried your exact code above and the same result. I am an Admin on the box and I have tried disabling UAC but without any effect.
(i know this isn't an answer, I have no power to comment)