.net web 配置如下:
<add key="FileStorageNetUseArguments" value=" use \\172.16.3.11\File\Data Adm07 /user:q0037"/>
这配置是Global.asax中使用到:
protected void Application_Start(Object sender, EventArgs e)
{
using (Process process = new Process())
{
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //启动进程时窗口状态
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = "net.exe";//如果file在System32文件夹中,此处只需填写文件名即可
process.StartInfo.Arguments = ConfigurationSettings.AppSettings["FileStorageNetUseArguments"];
process.Start();
}
}
请问配置中 use是什么意思?这样写是固定的么?,及Adm07是FileServer的账号密码么?
打开控制台输入net use /?就有解释
Microsoft Windows [Version 10.0.17134.345]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\username>net use /?
The syntax of this command is:
NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
[/USER:[domainname\]username]
[/USER:[dotted domain name\]username]
[/USER:[username@dotted domain name]
[/SMARTCARD]
[/SAVECRED]
[/REQUIREINTEGRITY]
[/REQUIREPRIVACY]
[[/DELETE] | [/PERSISTENT:{YES | NO}]]
NET USE {devicename | *} [password | *] /HOME
NET USE [/PERSISTENT:{YES | NO}]
但是实际上,我们一般不在C#里调用net use,而是直接调用它的windows api版本:WNetAddConnection2
https://blog.csdn.net/ma_jiang/article/details/8970928
如果你熟悉打开共享目录的处理应该就可以一眼验出来这是什么意思了,用指定的账户名和密码打开共享目录,命令格式如下所以,共享路径地址、密码、账户名是可变的,其余都是windows的命令符:
use [共享路径地址] [密码] /user:[账户名]