Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple vbs script failing

Status
Not open for further replies.

superhl

IS-IT--Management
Dec 16, 2001
20
0
0
US
What am I doing wrong? I have verified the unc path is correct.

' VBScript to map a user s home drive using string variables
' Guy Thomas January 2005. Guy Thomas Page 15 of 70 LogonScripts V52
' ----------------------------------------
Dim objNetwork, strDriveLetter, strUNCpath, strUser
strDriveLetter = "K:"
strUNCpath = "\\encsd3\data\users\admin\"
Set objNetwork= CreateObject("Wscript.Network")
strUser =objNetwork.UserName
objNetwork.MapNetworkDrive strDrvieLetter, strUNCpath & struser
WScript.echo " Drive Mapped " & DriveLetter
WScript.Quit

Error: Line 9
char 1
Error: The specified network resource or device is no longer availabe
code 80070037
WSHNetwork.MapNetworkDrive
thanks
From ONScript, here is the error: WSHNetwork.MapNetworkDrive: The specified network resource or device is no longer available.
 
Ok,getting somewhere now... I rebooted and ran this script and it maps to K:; however, I get this message at the end of the script:
C:\Users\hblancaster\Desktop\home.vbs(15,1)
Microsoft VBScript runtime error: Variable is undefined: 'DriveLetter'


Option Explicit
Dim objNetwork, strDriveLetter, strUNCpath, strUser
strDriveLetter = "K:"
strUNCpath = "\\encsd3\data\users\admin\"
Set objNetwork= CreateObject("Wscript.Network")
strUser =objNetwork.UserName
On Error Resume Next
objNetwork.MapNetworkDrive strDriveLetter, strUNCpath & struser
If Err.Number <> 0 Then
WScript.echo "Got Error#" & Err.Number & ": " & Err.Description
WScript.echo "While mapping " & strUNCpath & struser & " to " & strDriveLetter
WScript.quit
End If
On Error Goto 0
WScript.echo " Drive Mapped " & DriveLetter
WScript.Quit



 
Remember, adding OPTION EXPLICIT requires that you define all variables. Do you see "DriveLetter" in you DIM? No. But as I mentioned before.

Code:
WScript.echo " Drive Mapped " & [green]str[/green]DriveLetter

-Geates



"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
That's because you have yet another typo that I thought we resolved like a dozen posts ago!

Do yourself a favor... fix the typo, make sure the K: drive is disconnected, and re-test.
 
Got it! This script was from an ebook I purchased from an expert. You would think it would be error free. Anyhow, corrected and now runs error free. Now that I have a little more knowledge, I am going to create ElseIf with groups since under "users" I have 3 other groups.

Thanks for the great help!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top