不好意思,我不会编程,我们这里有个worklog小程序,每次连接位于局域网202机器上的数据库时,都需要输入账户密码,能不能在程序里加上啊?贴一段源程序:using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;namespace worklog
{
  static class Program
  {
  internal static ApplicationContext appContext = new ApplicationContext(new Form2());
  internal static string uName = string.Empty;
  internal static string uPwd = string.Empty;
  internal static string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\192.168.1.202\\tool\\worklog.mdb;Jet OLEDB:Database Password=admindaojin;";
  internal static bool autoLogin = false;
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
  Application.EnableVisualStyles();
  //Application.SetCompatibleTextRenderingDefault(false);
  Application.Run(appContext);
  }
  }
}请问是在粗体的地方加吗?如果不是,我再把全部代码发上来,很小的程序,一共2个form。

解决方案 »

  1.   

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\192.168.1.202\\tool\\worklog.mdb;Jet OLEDB:Database Password=admindaojin;";
    ''Database Password=admindaojin 这个密码正确吗?如果不正确,则修改admindaojin 为你的登录密码
    如果正确,那么提示你输入的密码是那台服务器的登录密码吗?
    如果是登录密码,那么你设置权限。
      

  2.   

    database password是数据库的密码。在访问局域网共享文件时,要输入用户名密码(guest已经禁用掉了),如果先手动通过 \\192.168.1.202输入账户密码(假设是abc,密码1)之后,这个小程序是能正常使用的。
    我想,能不能把这一步动作加入到程序中去呢?罗嗦了这么多,不知道解释清楚了没。
      

  3.   

    你创建网络磁盘映射好了,那样使用起来就像本地磁盘一样,只是在创建网络磁盘映射的时候需要用户名和密码,以后不管是在资源管理器还是代码中都不需要。
    创建一个.bat的文件,如disk.bat,代码类似于下面的格式:net use Z: \\192.168.0.46\data这样“\\192.168.0.46\data”就变成你的电脑的Z盘了,访问就像本地文件一样。
      

  4.   

    我写了个小批处理,也是用映射。但是映射在vista中报错,win7 xp正常。 
    我想能不能不用批处理,直接在程序源码中就解决掉呢?
      

  5.   

    要不我把整个源码发上来吧,直接在form中调用cmd命令?
    shellExecute(NULL,NULL,"cmd.exe"," /c net use \\pc1 /user:abc \"1\"",NULL, SW_HIDE);网上搜了下,好像用上面这个命令。但不晓得怎么加到程序里。
      

  6.   

            public static string RunCmd(string FileName, string command)
            {
                Process p = new Process();
                string ResultStr;
                p.StartInfo.FileName = FileName;
                p.StartInfo.Arguments = " " + command;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.ErrorDialog = false;
                p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                try
                {
                    p.Start();
                    ResultStr = p.StandardOutput.ReadToEnd();
                    p.Close();
                    return ResultStr;
                }
                catch (Exception ex)
                {
                    return ex.Message.ToString();
                }
            }
      

  7.   

    想起来了,2000年做过一个德企OA,用过win32api动态连共享文件夹。源码已无,上网搜了下,找到段C#的。没测,你自测吧。using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;namespace ManageCenter
    {
        public  class ConnShareRes
        {
            private string userName;
            private string userPwd;
            private string shareResDictionary;
            //构造函数
            public ConnShareRes(string myUserName, string myUserPwd, string myShareResDictionary)
            {
                this.userName = myUserName;
                this.userPwd = myUserPwd;
                this.shareResDictionary = myShareResDictionary;
            }
            [StructLayout(LayoutKind.Sequential)]
            public struct NETRESOURCEA
            {
                public int dwScope;
                public int dwType;
                public int dwDisplayType;
                public int dwUsage;
                [MarshalAs(UnmanagedType.LPStr)]
                public string lpLocalName;
                [MarshalAs(UnmanagedType.LPStr)]
                public string lpRemoteName;
                [MarshalAs(UnmanagedType.LPStr)]
                public string lpComment;
                [MarshalAs(UnmanagedType.LPStr)]
                public string lpProvider;
                public override String ToString()
                {
                    String str = "LocalName: " + lpLocalName + " RemoteName: " + lpRemoteName + " Comment: " + lpComment + " lpProvider: " + lpProvider;
                    return (str);
                }
            }
            [DllImport("mpr.dll")]
            public static extern int WNetAddConnection2([MarshalAs(UnmanagedType.LPArray)] NETRESOURCEA[] lpNetResource, [MarshalAs(UnmanagedType.LPStr)] string lpPassword, [MarshalAs(UnmanagedType.LPStr)] string UserName, int dwFlags);
            [DllImport("mpr.dll")]
            public static extern int WNetCancelConnection2(string lpName, int dwFlags, bool fForce);
            //开始远程连接
            public  bool RemoteConnect(bool bConnected)
            {
                int res;
                NETRESOURCEA[] n = new NETRESOURCEA[1];
                n[0] = new NETRESOURCEA();
                n[0].dwType = 1;
                int dwFlags = 1; // CONNECT_INTERACTIVE;
                //n[0].lpLocalName = @"X:";
                n[0].lpLocalName = @"";            n[0].lpRemoteName = shareResDictionary;
                //n[0].lpRemoteName = @"\\wanglh\manageshare";
                n[0].lpProvider = null;
                //Console.WriteLine(n[0]);
                if (bConnected)
                {
                    res = WNetAddConnection2(n, userPwd, userName, dwFlags);
                }
                else
                {
                    res=WNetCancelConnection2(shareResDictionary, 1, true);
                }
                return (res == 0) ? true : false;
            }
        }//class
    }//namespace
      

  8.   

    参考一下
            private void Connection_Lan()
            {
                
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;
                p.Start();
                string strOutput = null;
                p.StandardInput.WriteLine("net use \\xxx.xxx.xx\c$ "密码" /user:"用户名"
    ");
                p.StandardInput.WriteLine("exit");
                strOutput = p.StandardOutput.ReadToEnd();
                Console.WriteLine(strOutput);
                p.WaitForExit();
                p.Close();        }