补充一下: 读写.ini文件,我使用了, [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key,string val,string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key,string def, StringBuilder retVal, int size,string filePath);
so everything is local or downloaded from the server? go to Control Panel->Administrative Tools->.NET Framework 1.1 Configuration, right click on Runtime Security Policy, try to add or adjust security, give permissions to run Unmanaged code
in the first method, the default current directory is Application.StartupPath, but in IE, it has its own default current directory, somewhere in "C:\Documents and Settings\YourLogin"?try MessageBox.Show(System.Environment.CurrentDirectory)
原来,通过IE打开后CurrentDirectory 由 E:\Documents and Settings\qiuji\My Documents\Visual Studio Projects\myApp1\bin\Debug 变成了: E:\Documents and Settings\qiuji\桌面非常感谢各位的回答!特别要感谢思归! 现在结贴!
看看可不可以通过设置IE解决,将安全级别降到最低高手切磋,全当参考吧
我把安全级别设置为最低还是不行。to cnhgj(戏子):
你的意思是不是直接打开和通过IE按钮打开是一样的?
但是,我这边确实不一样。
E:\Documents and Settings\qiuji\My Documents\Visual Studio Projects\myapp1\bin\Debug\myapp1.exe
CLSID = {1FBA04EE-3024-11D2-8F1F-0000F87ABD16}
DEFAULT VISIBLE = YES
EXEC = G:\myprogram\test.exe
HOTICON = G:\icon\Funny\mr e-mail.ico
ICON = G:\icon\Funny\look no hands.ico
直接运行,没有问题,能够取到.ini中的值,但是,在IE中用按钮打开依然不行。
读写.ini文件,我使用了,
[DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key,string val,string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key,string def, StringBuilder retVal, int size,string filePath);
我把所有的选项全部设置为“完全信任”,还是跟原来一样。另外,我的程序与服务器无关,完全是在本地运行,而且该程序跟一般的程序一样,并且不需要网络的支持。
就算其他的开发工具可以,但是.net下不能实现也不行啊,我想一定是有原因的。
我终于发现错误了,
我以前用:
ini=new Form2("inifile\\test.ini");
直接运行,没有问题,在IE中打开就不行。现在换成:
ini=new Form2(Application.StartupPath+"\\inifile\\test.ini");
两者都可以了。不过,为什么第一个方法有问题?
难道通过IE点击的应用程序运行的时候,还与IE保持一定的关系?
"C:\Documents and Settings\YourLogin"?try
MessageBox.Show(System.Environment.CurrentDirectory)
由
E:\Documents and Settings\qiuji\My Documents\Visual Studio Projects\myApp1\bin\Debug
变成了:
E:\Documents and Settings\qiuji\桌面非常感谢各位的回答!特别要感谢思归!
现在结贴!