Jump to content

login script, semi-urgent


Recommended Posts

Hey, I am not sure how to go about doing this, but I have 2 servers, one of which runs all the time, the other only when I need it. I want to map an extra 2 drives ONLY if the server is running, if the server is not running with the standard net use command it takes a few minutes for the login script to finish with an error, is there a way to do the following

if "ping 172.16.10.2" replies then net use * \\vms\ISOs else go to end

if "ping 172.16.10.2" replies then net use * \\vms\vms else go to end.

basically if the ping replies then map the drive, if it times out then end.

is there any way to do this?

thanks in advance.

Link to comment
Share on other sites


This would be much better handled by vb script:

' // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' //
' // Declare variables, and allocate storage space for them

Dim strTestPath
Dim intCount

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objVolatileEnv = objShell.Environment("VOLATILE")


' // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' //
' // Check to see if a UNC path is available when logon script runs
' // Format is strTestPath = "\\server\share"

strTestPath = "\\vms\ISOs"
intCount = 1


' // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' //
' // Test on volatile environment variable to avoid running logon script if
' // the user has already run the logon script

If Not objVolatileEnv("LogonScript") = "Done" Then

Do Until objFSO.FolderExists(strTestPath)

' // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' //
' // Sleep 5 seconds

WScript.Sleep 5000

' // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' //
' // Try connecting to strTestPath twice

intCount = intCount + 1
If intCount = 2 Then

' // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' //
' // strTestPath is not available - alert user and exit script

MsgBox "Unable to connect to network share for 10 seconds. Please notify your network administrator."
Exit Do
End If
Loop

' // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' //
' // If able to connect to strTestPath, that means that the server is
' // available, so continue mapping network drives

objnet.MapNetworkDrive "Z:", "\\vms\vms"
objnet.MapNetworkDrive "Y:", "\\vms\ISOs"

End If

Link to comment
Share on other sites

Me being the KiXtart junky that I am... :)

If Exist("\\vms\ISOs")
Use * "\\vms\ISOs"
If @ERROR = 0
? "Successfully mapped " + @RESULT + " to \\vms\ISOs"
EndIf
Use * "\\vms\vms "
If @ERROR = 0
? "Successfully mapped " + @RESULT + " to \\vms\vms"
EndIf
Else
MessageBox("The vms server is not available. Please contact your System Administrator","Error",4112)
EndIf

Link to comment
Share on other sites

alright..hmm...cuz i have a batch file i'd like to have in there as well.. on top of mapping other drives and such.

thanks, i'll take a closer look and let you know.

You can port most of what you do in a .cmd to vbscript, and if you can't, you can call it directly using objShell.Run or some other such construct. Long term, you have more power and flexibility in a .vbs than you will in a .cmd or .bat file, so at least consider it. You could always call the vbscript from your current .cmd logon script now, though :).

Link to comment
Share on other sites

:: Check IP1
PING -n 1 IP1 ¦ FIND "TTL=" >NUL
:: Is not available
IF ERRORLEVEL 1 goto Next1

net use ...
goto End

:Next1
PING -n 1 IP2 ¦ FIND "TTL=" >NUL
IF ERRORLEVEL 1 goto Next2

net use ...
goto End

:Next2
:End

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...