#198285 - 2010-03-31 12:30 AM
message box mapped drive choice
|
paul28
Fresh Scripter
Registered: 2008-02-28
Posts: 20
Loc: UK
|
I would like to give my users a choice whether to map a drive or not at logon. To cut a long story short we have a need to connect periodically on a add hoc basis to an external partnership company.
If the user decides to make the connection they will have to provide logon credentials.
I was thinking / hoping I could use a message box to give both the choice of mapping a drive plus providing a little bit of a professional feel about the logon process
All the examples I have seen fully explain about the make up of the components of the message box i.e. message, title, style, timeout but I’m looking for assistance with the basics.
Can it be scripted for a user to be given the choice YES NO whether to map a drive? If the user chooses YES then they should be prompted for user input and provide logon credentials.
|
Top
|
|
|
|
#198286 - 2010-03-31 03:11 AM
Re: message box mapped drive choice
[Re: paul28]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
Untested... more just to get you started. You will need to paste the inputbox UDF to the bottom of the script.
Inputbox - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=197076#Post197076
if messagebox("Map a Drive?","Login Support",4,30)=6
$username=inputbox("Enter Your Username","Login Support")
$password=inputbox("Enter Your Password","Login Support")
if $username and $password
use z: "\\server\share" /user:$username /password:$password
endif
endif
|
Top
|
|
|
|
#198287 - 2010-03-31 10:09 AM
Re: message box mapped drive choice
[Re: Allen]
|
paul28
Fresh Scripter
Registered: 2008-02-28
Posts: 20
Loc: UK
|
Thanks Allen.
I will see if I can get this up and running.
|
Top
|
|
|
|
#198290 - 2010-03-31 01:27 PM
Re: message box mapped drive choice
[Re: paul28]
|
paul28
Fresh Scripter
Registered: 2008-02-28
Posts: 20
Loc: UK
|
I have tested Allen’s suggestion but unfortunately, I am struggling to get this to work. When I run the script I get the message box but after choosing yes it fails with the following error
ERROR : undefined variable [username]! Script: C:\KIXTART.KIX
This is the extract of my script
IF INGROUP ("TE_HELP")
messagebox("Please logon with your Username and Password. The username will be of the form JJHT\Username. Remember to include the JJHT\","Login",36,30)=6 $username=inputbox("Enter Your Username","Login") $password=inputbox("Enter Your Password","Login") if $username and $password
USE \\jjht1\ipc$ USE \\jjht4\ipc$ USE \\jjht3\ipc$ USE l: "\\jjht13\work" /user:$username /password:$password USE n: "\\jjht14\projects" /user:$username /password:$password
ENDIF ENDIF
Function InputBox($sPrompt, Optional $sTitle, $sDefaultValue) Dim $sc $sc = CreateObject("ScriptControl") $sc.language = "VBScript" $inputbox = $sc.Eval('Inputbox("' + $sPrompt + '","' + $sTitle + '","' + $sDefaultValue + '")') EndFunction
|
Top
|
|
|
|
#198291 - 2010-03-31 02:12 PM
Re: message box mapped drive choice
[Re: paul28]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
If you are following best practice and have SetOption("Explicit","ON") at the start of your script then you will need to DIM all variables, including the ones presented in sample code.
You are also missing an IF/EndIf
Dim $username,$password
If INGROUP("TE_HELP")
If messagebox("Please logon with your Username and Password. The username will be of the form JJHT\Username. Remember to include the JJHT\","Login",36,30)=6
$username=inputbox("Enter Your Username","Login")
$password=inputbox("Enter Your Password","Login")
If $username AND $password
USE \\jjht1\ipc$
USE \\jjht4\ipc$
USE \\jjht3\ipc$
USE l: "\\jjht13\work" /user:$username /password:$password
USE n: "\\jjht14\projects" /user:$username /password:$password
EndIf
EndIf
EndIf
Function InputBox($sPrompt, Optional $sTitle, $sDefaultValue)
Dim $sc
$sc = CreateObject("ScriptControl")
$sc.language = "VBScript"
$inputbox = $sc.Eval('Inputbox("' + $sPrompt + '","' + $sTitle + '","' + $sDefaultValue + '")')
EndFunction
Edited by Richard H. (2010-03-31 02:16 PM) Edit Reason: Spotted the missing If/EndIf, posted entire code.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 248 anonymous users online.
|
|
|