' ********************************************************************* ' ' Name : Verify User Password.vbs ' Author : 3Ds (UK) Limited ' Description : VBScript to verify a SQL Server user/password. ' ' Arguments : 1 - Network Share Name ' 2 - Windows User ID. ' 3 - Password. ' ' WIZARD:PARAMS=1 = The name of a network share the user has access to|2 = The Windows User ID to verify|3 = The user's password ' WIZARD:PARAMEXAMPLE= ' ' Returns : 0 - Success ' 1 - Another error occurred, see below. ' 2 - The share does not exist or the user/password is invalid. ' ' WIZARD:RESULTS=Return code ...||0 = OK|1 = An error prevented the script from running|2 = Either the share name does not exist or the user/password is invalid.||Script output also indicates "OK" for success, or "Error" with details of the faults found. ' ' Notes : Requires Windows Scripting Host (for VBScript), ' a SQL Server target database & SQL Server client ' connectivity. ' ' Change the "TODOs" for your own requirements. ' ' ********************************************************************* ' Enable in-line error handling On Error Resume Next ' ------ Local declarations ------ Dim objArgs ' Inbound command-line arguments Dim objNetwork ' Network object Dim strShareName ' Target network share Dim strUser ' Windows user Dim strPassword ' Password Dim strDriveToMap ' The local drive mapping Dim intValue ' Holds our data ' ------ Main Logic ------ Set objArgs = WScript.Arguments ' Retrieve command line arguments If objArgs.Count <> 3 Then ' Insufficient arguments WScript.Echo "Error. One or more arguments missing, or too many specified" WScript.Quit(1) End If strShareName = objArgs.Item(0) strUser = objArgs.Item(1) strPassword = objArgs.Item(2) ' TODO: Set this to a free drive letter strDriveToMap = "X:" ' Create our network reference Set objNetwork = WScript.CreateObject("WScript.Network") If Err.Number <> 0 Then ' Error WScript.Echo "Error. Unable to create the network object. " & Err.Description WScript.Quit(1) End If ' Map the drive using the user/password provided objNetwork.MapNetworkDrive strDriveToMap, "\\" & strServer & "\" & strShare, False, strUser, strPassword If Err.Number <> 0 Then ' Failed to map Set objNetwork = Nothing WScript.Echo "Error. Unable to map drive using the user/password provided. " & Err.Description WScript.Quit (2) End If ' All OK so unmap it objNetwork.RemoveNetworkDrive strDriveToMap ' ------ Cleanup ------ Set objNetwork = Nothing WScript.Echo "OK. User ID & password correct & accessible" WScript.Quit (0) ' ------ End of Script ------