.Net 屏幕保护程序找不到配置文件
我用 C# 和 Windows 窗体编写了一个屏幕保护程序。为了测试,我很懒,只是使用配置文件进行所有设置(还没有设置对话框),但是当 Windows 运行屏幕保护程序时,程序似乎无法找到或读取配置文件。
当我使用预览按钮或以任何方式手动运行它时,它才起作用,只有当它遇到屏幕保护程序超时时,它才无法找到配置文件。
让它记录 AppDomain.CurrentDomain.SetupInformation.ConfigurationFile 它返回短名称:C:\Windows\System32\MYSCRE~1.config
它应该在 C:\Windows\System32\MyScreenSaverName.scr.Config
所以我猜测问题是它找不到具有短名称路径的配置文件。
不确定是否是由于 Windows 7 运行屏幕保护程序的系统帐户所致,或者是由于其运行方式所致。任何信息都会有帮助,谢谢。
编辑:尝试找出任何差异:
- 我能找到的唯一差异是
Environment.CommandLine
返回C:\Windows\system32\MYSCRE~1.SCR /s
当 Windows 运行屏幕保护程序时,但当我运行它时具有正常路径 Process.GetCurrentProcess().StartInfo
下的所有内容都是相同的WindowsIdentity.GetCurrent().Name
是我的帐户名
查看其他问题,似乎 User32 是启动屏幕保护程序的,所以我认为它必须是关于如何启动 scr 的过程。
解决方法:将我的 .scr 文件重命名为 8 个或更少的字符,使其能够正常工作。所以现在有效,仍然很想知道为什么这个问题存在。
I've written a screen saver in C# and Windows Forms. For testing I've been lazy and just used the config file for all my settings (no settings dialog yet), but the program seems to be unable to find or read the config file when windows runs the screensaver.
It works when I use the preview button or run it manually in any way, its only when it hits the screensaver timeout that it is unable to find the config file.
Having it log AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
It returns the short name: C:\Windows\System32\MYSCRE~1.config
Where it should be C:\Windows\System32\MyScreenSaverName.scr.Config
So I'm guessing the problem is that it can't find the config file with the short name path.
Not sure if its due to the system account which Windows 7 runs screen savers under, or something else about how it gets run. Any information would be helpful, thanks.
Edit: Trying to find any differences:
- Only difference I can find is that
Environment.CommandLine
returnsC:\Windows\system32\MYSCRE~1.SCR /s
when Windows runs the screen saver, but has the normal path when I run it - Everything under
Process.GetCurrentProcess().StartInfo
is the same WindowsIdentity.GetCurrent().Name
is my account name
Looking at other questions, it seems that User32 is what starts the screensavers, so I'm figuring it has to be something about how that starts up the scr process.
Work Around: Renaming my .scr file to have 8 characters or less allows it to work correctly. So that works for now, would still love to know why this problem exists.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:哎呀...我注意到这是一个一年前的问题了,为时已晚...好吧,也许有人会发现这个有用。
您确定文件系统不是 fat/fat32 而不是 ntfs 吗?
也许是从旧的fat/fat32格式的系统升级而来的Win7? (所以 fs 没有升级)?
也许我错了,这只是我的猜测,看到了短名称。我最近在 C# 中开发了一个屏幕保护程序项目,并且完全没有遇到任何问题...说实话,我很久以来都没有看到短名称...
您应该从磁盘管理中看到 fs 类型。
做了一些研究我也得到了这个,检查 FUTIL.EXE 是否可以提供帮助,那里有一个奇怪的“disable8dot3”选项:
http://commandwindows.com/fsutil.htm
edit: ouch... I noticed too late that it's a 1 year old question.... well maybe someone can find this usefull anyway.
Are you sure the filesystem isn't fat/fat32 instead of ntfs?
Maybe it's a Win7 upgraded from an old fat/fat32 formatted system? (and so fs were not upgraded)?
Maybe I'm wrong, it's just my guess to see short names in place. I recently worked on a screensaver project in c# and I encountered no problems at all... I don't see short names since ages to be honest...
You should see the fs type from Disk management.
Doing some research i also got this, check if FUTIL.EXE can help, there is a curious "disable8dot3" option right there:
http://commandwindows.com/fsutil.htm