Impersonating in .net (C#) & opening a file via Pr

2019-02-28 17:27发布

HI, I was doing some impersonation using the LogonUser as it was explained in numerous places.

(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

"There is not enough memory or disk space to run 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:

"access denied".

BTW, when I logon by hand to my computer, this other user has the permissions to open the file.

1条回答
你好瞎i
2楼-- · 2019-02-28 17:37

This smells like a problem with 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. Office programs are not going to like this.

Beware that afaik you'll also have to set UseShellExecute to false to make this setting effective. That will hamper your ability to start Word by simply passing a .doc file as the file name. You'll need to use "winword.exe" instead.

查看更多
登录 后发表回答