我希望能够从我的笔记本电脑连接到(wifi)网络硬盘,但只是偶尔。如果我在WinXP资源管理器中使用“映射网络驱动器”命令,我必须输入驱动器的IP地址和名称,然后是路由器名称及其密码。记得太多了!
我正在寻找一种编写此活动(使用任何语言)的方法,例如:
map Z: \\10.0.1.1\DRIVENAME "ROUTERNAME\PW"
我并不特别关心脚本的编写语言.BTW,我知道DOS'subst'命令,但我不认为我可以在这种情况下使用它,因为密码保护。
答案 0 :(得分:27)
使用net use
命令:
net use Z: \\10.0.1.1\DRIVENAME
编辑1:此外,我认为应该简单地附加密码:
net use Z: \\10.0.1.1\DRIVENAME PASSWORD
您可以通过以下方式找到有关此命令及其参数的更多信息:
net use ?
编辑2:正如Tomalak在评论中提到的,您可以稍后通过
取消映射net use Z: \delete
答案 1 :(得分:13)
这不起作用(假设“ROUTERNAME”是路由器期望的用户名)吗?
net use Z: "\\10.0.1.1\DRIVENAME" /user:"ROUTERNAME" "PW"
或者,您可以使用小型VBScript:
Option Explicit
Dim u, p, s, l
Dim Network: Set Network= CreateObject("WScript.Network")
l = "Z:"
s = "\\10.0.1.1\DRIVENAME"
u = "ROUTERNAME"
p = "PW"
Network.MapNetworkDrive l, s, False, u, p
答案 2 :(得分:4)
Tomalak's回答对我很有用(+1)
我只需要为了我的目的稍微改变一下,我不需要密码 - 它适用于公司域名:
Option Explicit
Dim l: l = "Z:"
Dim s: s = "\\10.10.10.1\share"
Dim Network: Set Network = CreateObject("WScript.Network")
Dim CheckDrive: Set CheckDrive = Network.EnumNetworkDrives()
Dim DriveExists: DriveExists = False
Dim i
For i = 0 to CheckDrive.Count - 1
If CheckDrive.Item(i) = l Then
DriveExists = True
End If
Next
If DriveExists = False Then
Network.MapNetworkDrive l, s, False
Else
MsgBox l + " Drive already mapped"
End If
或者如果您想断开驱动器:
For i = 0 to CheckDrive.Count - 1
If CheckDrive.Item(i) = l Then
WshNetwork.RemoveNetworkDrive CheckDrive.Item(i)
End If
Next
答案 3 :(得分:3)
为什么不映射网络驱动器但取消选择“登录时重新连接”?只有在您尝试访问它时,驱动器才会连接。请注意,如果某些应用程序指向它,则会失败,但如果您直接通过Windows资源管理器访问文件,则此方法效果很好。
答案 4 :(得分:2)
尝试net use命令
答案 5 :(得分:1)
// Below the MSDN page for MapNetworkDrive Method with link and in case if Microsoft breaks it like every now and then the path to the documentation of now.
// https://msdn.microsoft.com/en-us/library/8kst88h6(v=vs.84).aspx
// MSDN Library -> Web Development -> Scripting -> JScript and VBScript -> Windows Scripting -> Windows Script Host -> Reference (Windows Script Host) -> Methods (Windows Script Host) -> MapNetworkDrive Method
var WshNetwork = WScript.CreateObject('WScript.Network');
function localNameInUse(localName) {
var driveIterator = WshNetwork.EnumNetworkDrives();
for (var i=0, l=driveIterator.length; i < l; i += 2) {
if (driveIterator.Item(i) == localName) {
return true;
}
}
return false;
}
function mount(localName, remoteName) {
if (localNameInUse(localName)) {
WScript.Echo('"' + localName + '" drive letter already in use.');
} else {
WshNetwork.MapNetworkDrive(localName, remoteName);
}
}
function unmount(localName) {
if (localNameInUse(localName)) {
WshNetwork.RemoveNetworkDrive(localName);
}
}