我正在尝试在我的 C# 程序中使用 dll,但我似乎无法让它工作。我制作了一个测试应用程序,如下所示。返回值是 0,但它实际上并没有做它应该做的事情。
而以下命令确实有效:
rundll32 cmproxy.dll,SetProxy /source_filename proxy-1.txt /backup_filename roxy.bak /DialRasEntry NULL /TunnelRasEntry DSLVPN /Profile "C:\Documents and ettings\Administrator\Application Data\Microsoft\Network\Connections\Cm\dslvpn.cmp"
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.Net;
using WUApiLib;
namespace nac
{
class Program
{
[DllImport("cmproxy.dll", CharSet = CharSet.Unicode)]
static extern int SetProxy(string cmdLine);
static void Main(string[] args)
{
string cmdLine = @"/source_filename proxy-1.txt /backup_filename proxy.bak /DialRasEntry NULL /TunnelRasEntry DSLVPN /Profile ""C:\Documents and Settings\Administrator\Application Data\Microsoft\Network\Connections\Cm\dslvpn.cmp""";
Console.WriteLine(SetProxy(cmdLine));
}
}
}
这是 dumpbin /exports 命令的内容
File Type: DLL
Section contains the following exports for cmproxy.dll
00000000 characteristics
3E7FEF8C time date stamp Tue Mar 25 05:56:28 2003
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 00001B68 SetProxy
Summary
1000 .data
1000 .reloc
1000 .rsrc
2000 .text
当此操作起作用时,它会设置 VPN 连接的代理服务器。
EDIT:
我希望避免从 system.process 运行 rundll32
我还可以提供 dll 和我的测试应用程序的链接。尽管上面粘贴的代码是它所包含的全部内容,并且我认为该 dll 可以从服务器资源工具包中获得。
UPDATE:
我用 C++ 编写了一个测试 DLL,它只是回显给定的参数。它正在运行,但它说
句柄无效