简体   繁体   English

在.net(C#)中模拟并通过Process.start打开文件

[英]Impersonating in .net (C#) & opening a file via Process.start

HI, I was doing some impersonation using the LogonUser as it was explained in numerous places. 嗨,我正在使用LogonUser进行一些模拟,这在很多地方都得到了解释。

(I used the great class library introduced here , but the principle seems to be the same all over the web). (我使用了这里介绍的很棒的类库,但是原理似乎在整个网络上都是一样的)。

I've succeed to impersonate and go to a place that my "normal" user can't. 我已经成功地模拟并转到了我的“普通”用户无法访问的地方。 But when I try to programmatically open a doc file , or txt file or whatever, using Process.Start , I get the error 但是当我尝试使用Process.Start以编程方式打开doc文件或txt文件或其他文件时,出现了错误

"There is not enough memory or disk space to run Word." “没有足够的内存或磁盘空间来运行Word。”

I can start word programmatically using my normal user, but then, when I try to open the specific file programmatically using the other user, I'm getting: 我可以使用普通用户以编程方式启动word,但是,当我尝试使用其他用户以编程方式打开特定文件时,我得到了:

"access denied". “拒绝访问”。

BTW, when I logon by hand to my computer, this other user has the permissions to open the file. 顺便说一句,当我手动登录到计算机时,该其他用户有权打开文件。

This smells like a problem with ProcessStartInfo.LoadUserProfile. 这闻起来像ProcessStartInfo.LoadUserProfile的问题。 It defaults to false, with the side effect that the started process will see the HKCU registry settings of your account, not the impersonated one. 默认为false,其副作用是启动的进程将看到您帐户的HKCU注册表设置,而不是模拟的帐户。 Office programs are not going to like this. Office程序不会这样。

Beware that afaik you'll also have to set UseShellExecute to false to make this setting effective. 请注意,afaik还必须将UseShellExecute设置为false才能使此设置生效。 That will hamper your ability to start Word by simply passing a .doc file as the file name. 仅通过传递.doc文件作为文件名,将会限制您启动Word的能力。 You'll need to use "winword.exe" instead. 您需要使用“ winword.exe”代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM