mount drive & script & net use & net share

最後更新: 2024-04-01

目錄

  • 有關 Services
  • net use
  • net view
  • XP mount Win7 shared folder
  • Mount Drive Script
  • cmdkey
  • Script 修改版
  • Win7 mount Win2000 shared folder
  • net share

 


有關 Services

 

  • Server (LanmanServer)
  • Workstation (LanmanWorkstation)
  • Computer Browser (Browser)

 


net use

 

Mount drive

# /user:USERNAME

net use z: \\192.168.88.150\mydata /user:tim

Pick the first available drive letter(不用填 "x:")

net use * \\192.168.88.150\mydata

Get more info

net use z:

Local name        Z:
Remote name       \\192.168.88.150\mydata
Resource type     Disk
Status            OK
# Opens           0
# Connections     1

Prompted to enter the password

net use z: \\192.168.88.150\mydata /user:tim *

Password in CLI

net use z: \\192.168.88.150\mydata /user:tim MYPW

Persistent

/persistent:{yes | no}        # /p:yes

Unmap Network Drive

net use \\192.168.88.150\mydata /delete

net use z: /delete

net use * /d /y

 


IPC$

 

net use

New connections will not be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
OK                     \\192.168.123.10\IPC$     Microsoft Windows Network
The command completed successfully.

 

 


net view

 

net view \\192.168.123.10

Shared resources at \\192.168.123.10

home server (Samba, Ubuntu)

Share name  Type  Used as  Comment

-------------------------------------------------------------------------------
2t_data     Disk           2T MD RAID1
iso         Disk
The command completed successfully.

 


XP mount Win7 shared folder

 

在 XP \\server 後出

System error 58 has occurred.
The specified server cannot perform the requested operation.

在 Win7 上執行:

secpol.msc

  1. Locate “Network Security: LAN Manager Authentication Level” in the list and double-click it.
  2. Change the setting from “Send NTMLv2 response only” to
    “Send LM & NTLM – use NTLMv2 session if negotiated”

 


Mount Drive Script

 

以下 script 會 mount 兩個 drive, 分別是 P 及 U

@ECHO OFF
REM # Last mtime 20140219
REM # Create by datahunter

REM ######################### Setting
set USER=MYUSER
set PW=MYPW
set SERVER=MYSERVER
REM #########################

REM # Msg
echo Map network drive on %SERVER%

REM # Delay
ping "%SERVER%" -n 3 -w 1000 > nul

net use p: /delete > %temp%\null 2>&1
net use u: /delete > %temp%\null 2>&1

REM ######################### Public
net use p: \\%SERVER%\Public "%PW%" /user:"%USER%" /p:no > nul 2>&1

REM ######################### User Private Folder
net use u: \\%SERVER%\%USER% "%PW%" /user:"%USER%" /p:no > nul 2>&1

REM ######################### END
echo Done

 * 注意 set 前後的空格 !!

 


cmdkey

 

建立、顯示、並刪除已儲存的使用者名稱和密碼。

# add

cmdkey /add:targetname /user:username /pass:password

i.e.

cmdkey /add:%SERVER% /user:USERNAME /pass:PASSWORD

# list

cmdkey /list

...
    目標: Domain:target=192.168.88.89
    類型: 網域密碼
    使用者: tim
...

cmdkey /list:targetname

目前為 192.168.88.89 存放的認證:

    目標: 192.168.88.89
    類型: 網域密碼
    使用者: tim

# delete

cmdkey /delete:targetname

 


Script 修改版

 

應用了 cmdkey, %ERRORLEVEL%

mount.bat

@echo off

set SERVER=IP
set USERNAME=?
set PASSWORD=?

echo Map network drive S: T: on %SERVER%

REM # check network
ping -n 3 -w 5000 %SERVER% | findstr "TTL" > nul
if not "%ERRORLEVEL%" EQU "0" ( echo "Network Issue !!" & pause > null )

cmdkey /add:%SERVER% /user:%USERNAME% /pass:%PASSWORD%

net use s: \\%SERVER%\share
net use t: \\%SERVER%\tech

echo Done

 

 


Win7 mount Win2000 shared folder

 

on your win 7 machine, run regedit and go to

HKLM\SYSTEM\CurrentControlSet\Control\Lsa

DWORD LmCompatibilityLevel set the value to 1

 * 不用 reboot

 


net share

 

net share sharename=drive:path

i.e.

# 將 "d:\share" 分享

net share MyShare=d:\share

# 取消分享

net share /delete MyShare

 

 

Creative Commons license icon Creative Commons license icon