-
-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting "NULL COM pointer access" when script calls from windows service #633
Comments
Hi, First of all, it should be mentioned that MS Office is generally not suitable for server-side automation. I am particularly concerned about whether Word is installed in that Windows environment. Additionally, I think it might be necessary to pass the |
@junkmd |
I passed |
I think this is more of a technical issue related to COM rather than comtypes or Python. Do you have any references for what you’re trying to do? |
I don't sure I got it right about reference you said, but the sample process for making remote procedure call I used is like: public Word2PDFResult word2pdfConvert(string arguments)
{
var file = "Word2PDF";
//var file = "Word2PDFS";
var fileName = System.IO.Directory.GetFiles(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "*"+ file + "", System.IO.SearchOption.AllDirectories).FirstOrDefault();
var pythonPath = "C:\\Python\\Python312\\Python";
var output = new StringBuilder();
var error = new StringBuilder();
using (var process = new Process())
{
try
{
process.StartInfo.FileName = pythonPath;
process.StartInfo.Arguments = fileName + " " + arguments;
//process.StartInfo.FileName = fileName;
//process.StartInfo.Arguments = " " + arguments;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
//process.StartInfo.Verb = "runas";
//process.StartInfo.WorkingDirectory = Path.GetDirectoryName(fileName);
using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
{
process.OutputDataReceived += (s, e) =>
{
if (e.Data == null)
{
outputWaitHandle.Set();
}
else
{
output.AppendLine(e.Data);
}
};
process.ErrorDataReceived += (s, e) =>
{
if (e.Data == null)
{
errorWaitHandle.Set();
}
else
{
error.AppendLine(e.Data);
}
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
process.Close();
}
}
catch(Exception ex) { process.Kill(); }
}
return new Word2PDFResult { Error = error.ToString(), Output = output.ToString() };
} |
Before I make the procedure like RPC service which I mentioned, I called the process with iis directly and when user is not log on on remote the server, I got this error:
When I was connecting to the remote server, the client request was successful, which means it needed to admin user be present on remote server to can client user on web can pass the request. |
To confess, I currently have no detail knowledge of RPC. Recently, I had the opportunity to read some old COM technical documents, but I haven't come up with a modern way to use RPC. Since this is a topic that requires help from the community, I have added the appropriate label. |
I'm trying to make a RPC service for calling my script which used comtypes package to create a pdf file from docx.
When I call my script on the command line prompt I have no any problem, but when I make calling from windows service I get this error from the output:
This is my script:
I call my script with this:
python .\\w2PDF .\\word.docx .\\word.pdf
I get this on windows service output:
Traceback (most recent call last):\r\n File \"<frozen runpy>\", line 198, in _run_module_as_main\r\n File \"<frozen runpy>\", line 88, in _run_code\r\n File \"D:\\Word2PDF-Service\\WindowsService1\\bin\\Debug\\Word2PDF\\__main__.py\", line 3, in <module>\r\n File \"D:\\Word2PDF-Service\\WindowsService1\\bin\\Debug\\Word2PDF\\Word2PDF_Python.py\", line 127, in cli\r\n File \"D:\\Word2PDF-Service\\WindowsService1\\bin\\Debug\\Word2PDF\\Word2PDF_Python.py\", line 76, in convert\r\n File \"D:\\Word2PDF-Service\\WindowsService1\\bin\\Debug\\Word2PDF\\Word2PDF_Python.py\", line 41, in windows\r\n File \"D:\\Word2PDF-Service\\WindowsService1\\bin\\Debug\\Word2PDF\\packages\\comtypes\\_meta.py\", line 14, in _wrap_coclass\r\n File \"D:\\Word2PDF-Service\\WindowsService1\\bin\\Debug\\Word2PDF\\packages\\comtypes\\_post_coinit\\unknwn.py\", line 520, in QueryInterface\r\nValueError: NULL COM pointer access
I couldn't find the problem, When I change the user log on to
Network Service
orLocal Service
above error changes to access is denied :Traceback (most recent call last):\r\n File \"<frozen runpy>\", line 198, in _run_module_as_main\r\n File \"<frozen runpy>\", line 88, in _run_code\r\n File \"D:\\Word2PDF-Service\\WindowsService1\\bin\\Debug\\Word2PDF\\__main__.py\", line 3, in <module>\r\n File \"D:\\Word2PDF-Service\\WindowsService1\\bin\\Debug\\Word2PDF\\Word2PDF_Python.py\", line 127, in cli\r\n File \"D:\\Word2PDF-Service\\WindowsService1\\bin\\Debug\\Word2PDF\\Word2PDF_Python.py\", line 76, in convert\r\n File \"D:\\Word2PDF-Service\\WindowsService1\\bin\\Debug\\Word2PDF\\Word2PDF_Python.py\", line 26, in windows\r\n File \"D:\\Word2PDF-Service\\WindowsService1\\bin\\Debug\\Word2PDF\\packages\\comtypes\\client\\__init__.py\", line 273, in CreateObject\r\n File \"D:\\Word2PDF-Service\\WindowsService1\\bin\\Debug\\Word2PDF\\packages\\comtypes\\_post_coinit\\misc.py\", line 149, in CoCreateInstance\r\n File \"_ctypes/callproc.c\", line 1008, in GetResult\r\nPermissionError: [WinError -2147024891] Access is denied
The text was updated successfully, but these errors were encountered: