Announcement

Collapse
No announcement yet.

Using scriptpw.dll to mask input box in VBS

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using scriptpw.dll to mask input box in VBS

    Hello,

    I put together a login script, primarily raken from this forum entry:

    http://forums.petri.com/showthread.php?t=9607&page=1

    It maps drives, printers, and promtps a user for a login and password to authenticate to a Samba Share we've got running.

    Typically the InputBox cannot mask passwords, but googleing around I found that XP and 2003 have a .dll that vbs can call to and pull the funtionality. Scripting Guy had an \entry on it:

    http://www.microsoft.com/technet/scr...5/hey0204.mspx

    It basically consists of this:

    ----------------
    Set objPassword = CreateObject("ScriptPW.Password")
    WScript.StdOut.Write "Please enter your password:"

    strPassword = objPassword.GetPassword()
    Wscript.Echo
    Wscript.Echo "Your password is: " & strPassword
    -----------------

    Now being a complete noob at this, I've managed to get this entire script working, but cannot get the password masking to work. How would I implement the above snippet into this script below? The bold section indicates the section I want to change. Thanks in advance for any help:

    ----------------------------------------------

    'COMPANY Draft Login Script
    'October 2006
    'SFCG
    'Code almost explicitly taken from http://forums.petri.com/showthread.php?t=9607
    'Thanks Brian873 for doing all the work for me

    ON ERROR RESUME NEXT

    Dim WSHShell, WSHNetwork, objDomain, DomainString,UserString, UserObj, Path, objNetwork, objNetwork1

    Set WSHShell = CreateObject("WScript.Shell")

    '---------------------------------- Printer Maps ----------------------------------------
    '
    '***** SAM *****

    Set WshNetwork = CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection "\\server\SAM"


    '***** SYD *****

    Set WshNetwork = CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection "\\server\syd"

    '**** COLOR ****

    Set WshNetwork = CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection "\\server\printer"


    '**** BETH ****

    Set WshNetwork = CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection "\\server\beth"

    '--------------------- Drive Maps & Default Printer Settings ---------------------------
    '
    'DRIVE MAPPINGS UNC PATH Group with permissions to Drive
    '
    'DEPARTMENTAL MAPPINGS
    'I: \\server\Administration$ Administration
    'J: \\server\IT$ Tech
    'K: \\server\NewAccounts$ NewAccounts
    'L: \\server\SalesAndMarketing$ SalesAndMarketing
    'M: \\server\CarrierManagment$ CarrierManagement
    'N: \\server\CustomerService$ CustomerService
    '
    'COMMON MAPPINGS
    'E: \\server\share
    'S: \\server\share2
    '
    'USER MAPPINGS
    'H: \\server\%USERNAME%$ Individual Users (Active Directory)
    '
    'SPECIAL MAPPINGS
    'Z: \\server\appdata SPECIAL
    'X: \\server\shared SPECIAL


    Set WSHNetwork = CreateObject("WScript.Network")

    'Automatically find the domain name
    Set objDomain = getObject("LDAP://rootDse")
    DomainString = objDomain.Get("dnsHostName")
    WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

    'Grab the user name
    UserString = WSHNetwork.UserName

    'Bind to the user object to get user name and check for group

    memberships later
    Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

    'Grab the computer name for use in add-on code later
    strComputer = WSHNetwork.ComputerName

    'Disconnect ALL mapped drives
    Set clDrives = WshNetwork.EnumNetworkDrives
    For i = 0 to clDrives.Count -1 Step 2
    WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
    Next

    'Give the PC time to do the disconnect, wait 300 milliseconds
    wscript.sleep 300

    'Map drives
    'Note the first command uses the user name as a variable to map to a user share.
    'WSHNetwork.MapNetworkDrive "p:", "\\server\users\" & UserString,True (COMMENTED FOR REFERENCE)
    WSHNetwork.MapNetworkDrive "e:", "\\server\share",True
    'WSHNetwork.MapNetworkDrive "s:", "\\server\share2",True (COMMENTED, NOT MOVED YET)

    'Now check for group memberships and map appropriate drives
    For Each GroupObj In UserObj.Groups
    Select Case GroupObj.Name


    'Check for group memberships and take needed action

    Case "Administration"
    WSHNetwork.MapNetworkDrive "I:", "\\server\administration$",True

    Case "IT"
    WSHNetwork.MapNetworkDrive "J:", "\\server\it$",True

    Case "NewAccounts"
    WSHNetwork.MapNetworkDrive "K:", "\\server\newaccounts$",True

    Case "SalesAndMarketing"
    WSHNetwork.MapNetworkDrive "L:", "\\server\salesandmarketing$",True

    Case "CarrierManagement"
    WSHNetwork.MapNetworkDrive "M:", "\\server\carriermanagement$",True

    Case "CustomerService"
    WSHNetwork.MapNetworkDrive "N:", "\\server\customerservices$",True


    Case "Domain Users"
    Set objNetwork = WScript.CreateObject("WScript.Network")
    strLocalDrive = "S:"
    strRemoteShare = "\\server\shared"
    strPer = "FALSE"
    strUsr = InputBox("Username for S: drive:")
    strPas = InputBox("Passworfd for S: drive:")
    objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas


    'Check for Zone Group and map appropriate default printer

    Case "SFZONE1"
    WshNetwork.SetDefaultPrinter "\\server\SAM"

    Case "SFZONE2"
    WshNetwork.SetDefaultPrinter "\\server\SYD"

    Case "SFZONE3"
    WshNetwork.SetDefaultPrinter "\\server\BETH"

    'COMMENTED FOR REFERENCE

    'WSHNetwork.MapNetworkDrive "w:", "\\Server\Share",True
    'Case "grp-FTP-root-rw"
    'Set objNetwork = WScript.CreateObject("WScript.Network")
    'strLocalDrive = "M:"
    'strRemoteShare = "\\server\share"
    'strPer = "FALSE"
    'strUsr = "username"
    'strPas = "password"
    'objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare,

    'strPer, strUsr, strPas
    'Case "grp-ftp-root-r"
    'Set objNetwork1 = WScript.CreateObject("WScript.Network")
    'strLocalDrive1 = "L:"
    'strRemoteShare1 = "\\server\share"
    'strPer1 = "FALSE"
    'strUsr1 = "username"
    'strPas1 = "password"
    'objNetwork1.MapNetworkDrive strLocalDrive1, strRemoteShare1,

    'strPer1, strUsr1, strPas1
    End Select
    Next

    '=====================================
    'Add On Code goes above this line

    'Clean Up Memory We Used
    Set UserObj = Nothing
    Set GroupObj = Nothing
    Set WSHNetwork = Nothing
    Set DomainString = Nothing
    Set WSHSHell = Nothing
    Set WSHPrinters = Nothing
    Set objNetwork = Nothing
    Set objNetwork1 = Nothing

    'Quit the Script
    wscript.quit
    Last edited by sfcg; 14th October 2006, 01:12.

  • #2
    Re: Using scriptpw.dll to mask input box in VBS

    hello?

    Comment


    • #3
      Re: Using scriptpw.dll to mask input box in VBS

      I looked at the example link you provided...

      This only works at the command prompt, which means it uses cscript. Are you aware of that?

      To make it work you'd need to launch the script from the command line.

      It would look something like this...

      Code:
      Wscript.StdOut.Write "Please enter the user name: "
      strUser = WScript.StdIn.ReadLine
      
      Set objPassword = CreateObject("ScriptPW.Password") 
      WScript.StdOut.Write "Please enter your password: " 
      
      strPassword = objPassword.GetPassword()
      To test it, create a vbs file and copy/paste the above code in it. Open a cmd prompt and browse to the vbs file you created. At the prompt type "cscript test.vbs", the output should look something like the following:

      Originally posted by ahinson
      C:\Documents and Settings\Username\Desktop>cscript test.vbs

      Microsoft (R) Windows Script Host Version 5.6

      Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

      Please enter your username: Username
      Please enter your password:
      Last edited by ahinson; 17th October 2006, 15:23.
      Andrew

      ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

      Comment


      • #4
        Re: Using scriptpw.dll to mask input box in VBS

        Thanks. I've never really learned about VBScripting so this is all new to me.

        I created the script and the cscript test.vbs command executed fine with your instructions. How do I get that to work with the script I've currently got? I tried creating the test script and matching the variable names to the ones in my script, and creating a batch file that runs the test.vbs first and then runs mine next. But I guess calling variables from memory doesn't work that way.

        Should I just put the text from test.vbs into my script and run the whole thing from the command line with cscript? I'll try that, I'm just trying to illustrate my ingorance so you understand where I'm coming from.

        Thanks for your help.

        Chris

        Comment


        • #5
          Re: Using scriptpw.dll to mask input box in VBS

          Awesome. I just included the test.vbs code into the script, matched up the variable names, ran it from cscript and it worked like a charm.

          Thanks ahinson!

          Chris

          Comment


          • #6
            Re: Using scriptpw.dll to mask input box in VBS

            Originally posted by sfcg
            Awesome. I just included the test.vbs code into the script, matched up the variable names, ran it from cscript and it worked like a charm.

            Thanks ahinson!

            Chris
            This is exactly what you needed to do. Glad you got it working.
            Respect the rep.
            Andrew

            ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

            Comment

            Working...
            X