首页 \ 问答 \ 是否可以选择在Windows中启动进程时使用的清单?(Is it possible to choose a manifest to use when starting a process in windows?)

是否可以选择在Windows中启动进程时使用的清单?(Is it possible to choose a manifest to use when starting a process in windows?)

我试图提供一个COM对象,可以用来替换我无法控制的可执行文件中的对象。 我已经使用所有相同的接口创建了这个COM对象的实现。 我希望能够偶尔使用这个替换,所以我不希望它的注册替换原始对象。

我可以通过修改可执行文件的清单来查看com对象而不是通过注册表查找原始文件,从而使用reg-free COM来获取可执行文件以加载我的COM对象而不是原始对象。

到现在为止还挺好。 但这样做需要修改可执行文件中的清单文件。 我不希望此更改是永久性的,并且由于可执行文件通常安装在“程序文件”中,因此还需要管理员权限才能更改此文件。

理想情况下,我希望保持原始可执行文件不变。 然后在需要时,我创建的单独的启动程序将使用重定向到我的com对象而不是可执行文件中的原始清单文件的清单来加载所请求的可执行文件。

这样的事情可能吗? 或者也许是一种更好的方式来做我想做的事情?

注意:我可能无法制作可执行文件的副本,并且在我具有写入权限的位置更改了清单,因为我事先并不知道此可执行文件的所有依赖项将是什么(它可能需要来自相同的目录,或子目录中的数据文件)。 我可以将修改后的可执行文件的工作目录设置为原始可执行文件的目录,但如果可执行文件根据其文件位置执行任何操作,则会中断。


I am trying to provide a COM object that can be used as a replacement for an object in an executable that I do not have control of. I have created an implementation of this COM object with all the same interfaces. I want to be able to use this replacement only occasionally so I do not want its registration to replace the original object.

I can get the executable to load my COM object instead of the original using reg-free COM by modifying the manifest of the executable to look in my dll to find the com object instead of finding to original through the registry.

So far so good. But doing this requires modifying the manifest file in the executable. I do not want this change to be permanent, and since the executable is usually installed in "program files" it would also require administrator privileges to change this file.

Ideally what I would like is to leave the original executable unchanged. Then when needed a separate launcher program I created would load the requested executable using the manifest that redirects to my com object instead of the original manifest file in the executable.

Is something like this possible? Or maybe a better way of doing what I am trying to do?

Note: I probably can't make a duplicate copy of the executable with the manifest changed in a location I have write access to because I do not know ahead of time what all the dependencies of this executable will be (it may need dlls from the same directory, or data files from a sub-directory). I could set the working directory of the modified executable to be the directory of the original executable but if the executable does anything based off of its file location it would break.


原文:https://stackoverflow.com/questions/18671147
更新时间:2022-07-16 10:07

最满意答案

问题是这一行: os.environ['DJANGO_SETTINGS_MODULE'] = 'myproj.settings'

  • 当你的脚本在myproj/之外时,你的PYTHON_PATH在myproj/之外启动,因此myproj是一个有效的包。

  • 当你的脚本在myproj/ ,你的PYTHON_PATH在myproj/启动,因此myproj不再是一个有效的包。

修复方法是从脚本中明确设置PYTHON_PATH。

然而

你应该做的是将你的脚本变成一个管理命令,这样你就可以运行python manage.py myscript并确保Django 运行你的代码之前已经完成了所有必要的初始化和检查。


The problem is this line: os.environ['DJANGO_SETTINGS_MODULE'] = 'myproj.settings'

  • When your script is outside myproj/, then your PYTHON_PATH starts outside myproj/, and hence myproj is a valid package.

  • When your script is inside myproj/, then your PYTHON_PATH starts inside myproj/, and hence myproj is no longer a valid package.

The fix would be to explicitly setup your PYTHON_PATH from inside the script.

HOWEVER

What you should do instead is turn your script into a management command so that you can run python manage.py myscript and be sure that Django has done all the necessary initialisation and checking before it runs your code.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。