paul28
(Fresh Scripter)
2010-03-31 12:30 AM
message box mapped drive choice

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.


AllenAdministrator
(KiX Supporter)
2010-03-31 03:11 AM
Re: message box mapped drive choice

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

 Code:
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


paul28
(Fresh Scripter)
2010-03-31 10:09 AM
Re: message box mapped drive choice

Thanks Allen.

I will see if I can get this up and running.


paul28
(Fresh Scripter)
2010-03-31 01:27 PM
Re: message box mapped drive choice

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


Richard H.Administrator
(KiX Supporter)
2010-03-31 02:12 PM
Re: message box mapped drive choice

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

 Code:
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