I am using this code to open a Word document:
Dim Word as Object, Doc as Object
Set Word = CreateObject("Word.application")
if not (Word is nothing) then
set Doc = Word.Documents.Open("C:\temp\testfile.doc")
if not (doc is nothing) then
doc.close false
set doc = nothing
end if
Word.Quit
set Word = nothing
End if
I compiled it into an exe and it works fine when running it interactively or as a service on my test machine (Windows Server 2008 R2 with Office 2007). But on an other server with same OS and same Word version it works fine only when running the exe interactively. As soon as I run it as a service, the line
set Doc = Word.Documents.Open("C:\testfile.doc")
fails with the error "Object required".
I tried the following:
Using the service account Local System
Configured the service to use the same user account as I am logged on as
Opening a new empty document with set Doc = Word.Documents.Add works fine
I ran Word with the /r parameter to repair it and also with the /RegServer
Checked / turned off Virus scanner (being MS Security Essentials)
No success.
Does anyone have an idea?
You probably need to enable your service to interact with the desktop. See screenshot in this question
Related
I am able to execute the vbs files in VM (UFT Installed).Now I want to execute the vbs files in VM from my local machine (UFT Not installed).Can any one please help me how can i connect the QTP in VM from local machine and execute scripts.
I am using below code to connect to ALM/QTP in VM . Its working good because UFT is installed in VM. But in my case i want to host that code and get URL. So that every one from my team can use that scripts from there local machines (without installing UFT).
Dim qtApp
Set qtApp = CreateObject("QuickTest.Application")
If qtApp.launched <> True then
qtApp.Launch
End If
qtApp.Visible = True
If Not qtApp.TDConnection.IsConnected Then
qtplch.TDConnection.connect "QCLink","CERNATECH","EDUTRACKER","kiran.goud","kiran123",true
End If
qtApp.Open "[QualityCenter] Subject\filePath", False
qtApp.Test.Run
qtApp.TDConnection.Disconnect
'Close QTP
qtApp.quit
'Release Object
Set qtApp = Nothing
VBS is always executed locally --> You need to keep this script on the machine where UFT is installed and provide a different way of triggering it remotely....
OR and this is a Big OR with some COM remoting use such a way:
Set qtApp = CreateObject("QuickTest.Application", "NameOfTheMachineWithUFT_Installed")
The only difference is when you create the Automation Object, you tell the system that it should be created on an other machine and not locally.
However this is a High Security Risk and in most Enterprise Networks forbidden.
I would propose a simple wrapper around your script, eposed by a URL or as already suggested, Jenkins
I had piece of code that was working perfectly until earlier this week, when I changed my domain password. After that, when trying to open a shared mailbox using GetSharedMailbox, I receive the error Could not find the store DN. Now, the really weird thing is that this only happens on one machine (unfortunately, the machine I really need it to run on). It works fine on my development laptop. Both machines have been rebooted, and logged back in repeatedly since then.
Both machines are logged into a Windows AD domain, under my account, and have no problems accessing other domain resources. I can open Outlook on the problem machine with no problem, and view both my personal inbox and the shared mailbox. Remote debug on the problem machine shows that it's opening a connection to Exchange ok (rdo.Logon works, and I can walk through its objects). The error is thrown when I try to open the shared mailbox.
Any suggestions would be welcome!
Try
Dim rdo as RDOSession = New RDOSession
rdo.Logon()
Dim sharedBox As RDOStore = rdo.GetSharedMailbox("SharedMailbox#domain.com") 'Throws error here
inbox = sharedBox.GetDefaultFolder(rdoDefaultFolders.olFolderInbox)
Console.WriteLine(String.Format("Mailbox: {0} ({1})", sharedBox.Name, sharedBox.EntryID))
' Do a bunch of stuff with inbox.Items
Catch err As Exception
My.Application.Log.WriteException(err, TraceEventType.Error, "Error connecting to mail server")
End Try
The error usually means that Redemption does not have the credentials to retrieve autodiscover XML and configure the connection to the delegate mailbox. If you were using LogonHostedExchangeMailbox instead of Logon, Redemption would have used the specified credentials. Otherwise you can cache the credentials using RDOSession.Creadentials.Add.
I have following network location
Dim myfolder As String = "\\10.0.0.90\myfolder\"
I am able to create a new file in this folder using following code:
File.Create (myfolder)
But when I try to read contents of this folder using code below I get error.
Code
Dim orderedFiles = New System.IO.DirectoryInfo(myfolder).GetFiles()
Error
The system detected a possible attempt to compromise security. Please
ensure that you can contact the server that authenticated you.
File writing is being done by ASP.Net page while reading is done from Windows Service. Could this be the issue?
Windows Service was running as "Local System". I right click on it, went into properties and changed the "Log on as" to some user account and now it can access network folder.
My application (vb.net windows application deployed via ClickOnce) uses Word to open and fill .dot templates to create new Word documents. I reference Microsoft Word 14 Object Library and uses this code :
Dim oWord As Word.Application = Nothing
Dim oDoc As Word.Document = Nothing
Try
oWord = New Word.Application
Dim strFileName As String = ""
Select Case strType
Case "LettreReception"
strFileName = Path.Combine(GetParam(1), "Template_LettreReception.dot")
If File.Exists(strFileName) Then
oDoc = oWord.Documents.Add(strFileName)
On the last line I receive "could not open macro storage" error on deployed machines (not on my development machine).
I develop with Windows 7 - Office 2010 - VS 2010 (.Net 3.5). My deployment machine is also a Windows 7 with Office 2010 installed.
I tried to remove normal.dotm (I found some links advicing it) without success. The .dot template used contains no macro.
Check the properties of the word document and make sure the files are unblocked. Sometimes when you get the documents from a different computer or download them from the internet they will be blocked which will cause the the throwing of this exception "could not open macro storage"
Because Word Interop is actually running behind the scenes as if it was running in an interactive session, certain permissions are required of the account used during execution.
Are you using Windows Authentication and impersonation in you web app? If so, the user being impersonated must have local log on rights to the server to run Word... In addition, you must actually log on to the server with that account at least once so that a profile exists on that machine for that user so the registry hive can be loaded. I've also found that you may need to actually run Word at least once as that user (to make sure any first-time initialization messages get taken care of before trying to run Word from code).
If not, then the service account that the application is running under (usually NETWORK SERVICE) requires the aforementioned permissions (which I will describe shortly) and you'll have to do something fancy like loading a registry hive dynamically at run-time. Personally, I prefer implementing an in-code temporary impersonation with a user account that has local log on permissions on the server in question.
Local log on permissions can be a bit tricky depending on your network and group policy configurations (if you want to be somewhat secure and not just use a Domain Admin account).
The reason everything works on your computer running in VS is because the context of the web application is YOUR user account - which, of course, has local log on permissions on your machine with a registry hive that can be loaded.
Now for the permissions:
First, you must run "dcomcnfg" on the server and make the following configuration change:
Right click on Component Services\computers\My Computer\DCOM Config\Microsoft Word 97 - 2003 Document and go to Properties
In the Properties screen, go to the Security tab and change the "Launch and Activation Permissions" to Customize.
Click the Edit button and add the local computer NETWORK SERVICE account (If not using impersonation... If using impersonation, add the appropriate user or group) to the list of users and check "Local Launch" and "Local Activation"
Make sure that the local computer NETWORK SERVICE account (If not using impersonation... If using impersonation, then the appropriate user or group) has appropriate read/modify permissions on the folder(s)and file(s) that you will be opening and/or saving to.
Create a "Desktop" directory under: C:\Windows\System32\config\systemprofile\ and give Full permissions to the local NETWORK SERVICE account (or the account that your ASP .NET application is running under) [NOTE: I believe this and the next step only apply if NOT using impersonation]
Give Modify/Read/Execute permissions on the C:\Windows\System32\config\systemprofile folder
Hope that helps some and wasn't too confusing...
Right click on the file that is opened -> Click the Unblock tick box -> Apply
Worked for me at least.
"could not open macro storage" is telling you that VBA is looking for a particular structured storage file such as a .DOT or .DOC, and looking for the storage (a kind of stream within the file) in that file that contains the VBA code. If it can't open it, possible reasons include:
the container (the .doc/.dot) isn't there
the container cannot be opened with the caller's permissions
the container is there but the storage isn't there (e.g. on the target system there is a container with the expected name, but it contains no macros)
the container is there and the storage is there but cannot be opened with the caller's permissions
So one thing to do is to look through your project looking for anything it references (perhaps even other objects or DLLs that you specified via Tools->References) that is not also being delivered with your template.
Go to the Word document (if it's a template, be sure to open it, not create a new document with it) and disable Protected View:
https://casecomplete.zendesk.com/hc/en-us/articles/200685047-Could-not-open-macro-storage
I am migrating from a Win 2003 server to a Win 2008 R2 server. I'm running a classic ASP application. In the 2003 server the following code worked for creating a file:
CONST SCRATCH_DIR = "E:\Temp\"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TFL = FSO.CreateTextFile(SCRATCH_DIR & "Debug.txt", True)
On the NEW server the Set TFL line gives me this error:
Microsoft VBScript runtime error '800a0046'
Permission denied
/inc/vbutil.inc, line 110
If I remove the Drive designation "E:\" from the CONST, the procedure works just fine; (except it writes to the C:\ drive) so I'm sure the error message is correct.
Could anyone please point me at where/how I'd change permissions for this (E:\Temp) directory?
Thanks very much in advance,
(A dumb application programmer;)
You can change permissions on the folder by right clicking it > Properties > Security > Advanced.
Uncheck "Include inheritable permissions from this object's parent".
Click "Add"
Modify permissions for the user running the script. They will need read, write and create permissions.