在 ac# Windows 服务应用程序中使用 net.exe 映射另一个域上的共享文件夹
我正在尝试将网络驱动器映射到用 C# 编写的 Windows 服务内的服务器。 我尝试使用 net.exe 和下面的代码,
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "net.exe";
p.StartInfo.Arguments = " use " + DriveLetter + Path + " " + Password + " /user:" + Username;
p.Start();
p.WaitForExit();
参数基本上转换为“ use X: \\192.45.xx.xxx\sharename "xxxx" /user:domainname\username”
执行时出现“未找到网络名称”错误。我尝试访问的服务器与我的应用程序所在的域位于不同的域,这就是我认为我收到该错误的原因。
有谁知道我如何克服这个问题并将共享文件夹从另一个域映射到我的本地计算机?
我非常感谢任何帮助
谢谢 卡蒂克
I am trying to map a network drive on to the server inside a windows service written in c#.
I tried using net.exe with below code
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "net.exe";
p.StartInfo.Arguments = " use " + DriveLetter + Path + " " + Password + " /user:" + Username;
p.Start();
p.WaitForExit();
the arguments basically translate to " use X: \\192.45.xx.xxx\sharename "xxxx" /user: domainname\username"
i get a "network name not found" error when this executes. The server i am trying to access is on a different domain than the one my app is sitting on, which is why i think i get that error.
Does anyone know how i can get past this and map a shared folder from another domain on to my local computer?
I'd greatly appreciate any help
Thanks
Karthik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设其他一切都正确,此错误是由于在 IP 地址之前指定一个反斜杠引起的 - 您需要 2 个反斜杠。
更新
为了响应您的评论,显然您已通过身份验证来访问其他域的资源。除非它是完全开放的,否则 Windows 服务不太可能运行在一个系统 。
作为故障排除步骤,将您的服务更改为在您的帐户下运行,看看这是否会产生影响
Assuming everything else is correct, this error is caused by specifying one backslash before the IP address -- you need 2 backslashes.
update
In response to your comments, clearly you are authenticated to access resources this other domain. Unless it is wide open, it is unlikely that the Windows Service, which is probably running under a system account, can access those resources.
As a troubleshooting step, change your service to run under your account, and see if that makes a difference.