开发者

Environment.GetFolderPath returns null in WMI provider

I have a decoupled WMI provider (Windows service) that is configured with a file that lives in the C:\ProgramData\CompanyName folder. When the service loads up it uses the Environment.GetFolderPath(Enviornment.SpecialFolder.CommonApplicationData) method to grab the C:\ProgramData portion of the path.

While the ser开发者_Python百科vice is running I attempt to write to the same file, through a WMI call into the service, using the same method call but this time is fails; returning null.

Is there something about the fact that I'm now running in the context of WMI that causes this to happen?


I have been having the same problems, however perhaps I can offer a solution. Slightly different usage attempting to get special folders on a web server to write temporary files but indeed having issues with the user that it runs as (runs under the DefualtAppPool domain group rather than a user even)

Had blanks returned even on my local win 7 machine for attempts to get

 Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

However i did manage to use the AppDomain.CurrentDomain.GetData method to get what i wanted, it has several different options to find different folders in the file structure but instead of being user based it works based on the application or i suppose the system. I pretty sure its just as "clean" a method to use as the Environment.GetFolderPath method

http://msdn.microsoft.com/en-us/library/system.appdomain.getdata.aspx

One of the the enumerations is bound to achieve what you are looking for.

AppDomain.CurrentDomain.GetData("ProgramFiles");

or @JohnB

AppDomain.CurrentDomain.GetData("StartMenu");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜