现在的位置: 首页网络正文

启动时自动挂载网络硬盘


'When you logon the Windows Vista machine, it will ping the server.
'If ping succeeds, it will map the network drives by using net use command.
'If not, it will wait for 5 seconds, and try to ping again.
'When the user logoff, the network drives will be deleted automatically.

Option Explicit

Dim strHost

‘ Check that all arguments required have been passed.

‘If Wscript.Arguments.Count < 1 Then

‘ Wscript.Echo “Arguments required. For example:” & vbCrLf _

‘ & “cscript vbping.vbs savdaldc01″

‘ Wscript.Quit(0)

‘End If

‘strHost = Wscript.Arguments(0)

strHost= “192.168.0.1″ ‘It is the IP address of the server, please change the parameter with the environment

While Ping(strHost) = False

‘ Wscript.Echo “Host ” & strHost & ” could not be contacted”

‘ Dim WshShell

‘ set WshShell = WScript.CreateObject(“WScript.Shell”)

WScript.Sleep 5000

‘ Ping(strHost)

Wend

If ping(strHost) = True Then

Dim oShell

Set oShell = WScript.CreateObject (“WSCript.shell”)

oShell.run “cmd /C net use * /delete /y”,0,true
WScript.Sleep 100
oShell.run “cmd /C net use z: \\192.168.0.1\public $密码$ /USER:$用户名$ /persistent:y”,0,true ‘map network drives by using the net use command, please change the parameter according to the environment

Set oShell = Nothing

‘ Wscript.Echo “Host ” & strHost & ” contacted”

End If

Function Ping(strHost)

dim objPing, objRetStatus

set objPing = GetObject(“winmgmts:{impersonationLevel=impersonate}”).ExecQuery(“select * from Win32_PingStatus where address = ‘” & strHost & “‘”)

for each objRetStatus in objPing

if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then

Ping = False

‘WScript.Echo “Status code is ” & objRetStatus.StatusCode

else

Ping = True

‘Wscript.Echo “Bytes = ” & vbTab & objRetStatus.BufferSize

‘Wscript.Echo “Time (ms) = ” & vbTab & objRetStatus.ResponseTime

‘Wscript.Echo “TTL (s) = ” & vbTab & objRetStatus.ResponseTimeToLive

end if

next

End Function

分享家:Addthis中国

相关日志

给我留言

留言没头像?这里教你设置头像!

Powered by WP Hashcash