Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Error Handling with objNetwork

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,61657
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Error Handling with objNetwork
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Error Handling with objNetwork - 6/20/2008 1:52:36 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
So far, i have this:
 
Set
objNetwork = CreateObject("WScript.Network")
WScript
.Echo "Enter Your CIANT Network Credentials"
WScript
.StdOut.Write "Username: "
strUsername =
WScript.StdIn.ReadLine
WScript
.StdOut.Write "Password: "
strPassword =
WScript.StdIn.ReadLine
objNetwork.MapNetworkDrive
"I:", "\\hqfile\software",, strDomain & "\" & strUsername, strPassword


Now, the problem is that if the password is bad, the script won't prompt the user. It will just crap out. How can i get it to re-prompt the user?

I tried adding this after the MapNetworkDrive but it didnt return a err.


 
If Err <> 0 Then

WScript.Echo err

End If




< Message edited by GreatBarrier86 -- 6/20/2008 1:53:58 AM >
 
 
Post #: 1
 
 RE: Error Handling with objNetwork - 6/20/2008 3:04:15 AM   
  dm_4ever


Posts: 2664
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
You would have to put On Error Resume Next before you try mapping the drive...then if Err.Number <> 0 re-prompt and On Error Goto 0.

Maybe put the prompt to get the info into a Sub or Function to make it re-calling it easier.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to GreatBarrier86)
 
 
Post #: 2
 
 RE: Error Handling with objNetwork - 6/20/2008 3:14:17 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
Ok. Let me try that

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Error Handling with objNetwork - 6/20/2008 5:01:57 AM   
  dm_4ever


Posts: 2664
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
not tested...got bored and tossed this together


      

EDIT://small change

< Message edited by dm_4ever -- 6/20/2008 5:10:59 AM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to GreatBarrier86)
 
 
Post #: 4
 
 RE: Error Handling with objNetwork - 6/20/2008 5:54:08 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline

Set
objNetwork = CreateObject("WScript.Network")

WScript
.Echo "Enter Your Network Credentials"

WScript
.StdOut.Write "Username: "

strUsername =
WScript.StdIn.ReadLine

WScript
.StdOut.Write "Password: "

strPassword =
WScript.StdIn.ReadLine

On
Error Resume Next

objNetwork.MapNetworkDrive
"I:", "my server",, strDomain & "\" & strUsername, strPassword

Do
While Err = -2147023677
Err.Clear
WScript.Echo
WScript.Echo "Username or Password Incorrect - Please Re-Enter Credentials"

WScript.StdOut.Write "Username: "

strUsername =
WScript.StdIn.ReadLine
WScript.StdOut.Write "Password: "

strPassword =
WScript.StdIn.ReadLine
objNetwork.MapNetworkDrive
"I:", "my server",, strDomain & "\" & strUsername, strPassword

Loop

That's what i did. Notice the Err.Clear. for some reason, unless it is clear, the next mapping won't update the error code.

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: Error Handling with objNetwork - 6/20/2008 5:56:43 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
I like the ScriptPW.Password but unfortunately it doesnt' work with Vista

(in reply to GreatBarrier86)
 
 
Post #: 6
 
 RE: Error Handling with objNetwork - 6/20/2008 7:32:20 AM   
  dm_4ever


Posts: 2664
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
quote:

ScriptPW.Password but unfortunately it doesnt' work with Vista


Good to know.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to GreatBarrier86)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Error Handling with objNetwork Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts