none
VBscript para mapeamento com autenticação RRS feed

  • Pergunta

  • Boa terde,

    gostaria de saber se tem como eu fazer um VBScript para mapeamento de maneira que ao executar o script seja solicitado o usuario e senha.

    desde já agradeço a ajuda

    • Movido Richard Juhasz segunda-feira, 7 de junho de 2010 16:25 Thread criada em fórum incorreto. (De:Windows Server 2008)
    quarta-feira, 2 de junho de 2010 16:54

Respostas

  • Segue a gambiarra.

    .VBS

    strDrive = "X:"
    strShare = "\\Server\Public"
    
    
    set objShell = WScript.CreateObject( "WScript.Shell" )
    sHTMDir = objShell.ExpandEnvironmentStrings("%temp%")
    
    
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    
    Call GetPWInfo(oFSO, sUserName, sPassword)
    
    
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    
    WshNetwork.MapNetworkDrive strDrive, strShare,False,sUserName,sPassword
    		
    		
    'Funções =========================================
    Sub GetPWInfo(oFSO, sUserName, sPassword)
        Call WriteHTML(oFSO)
        Dim oIEPW, strButton, sPWHTML, sPWHTMLVBS
    
        Set oIEPW = WScript.CreateObject("InternetExplorer.Application", "IE_")
    
        With oIEPW
            .Navigate "file:///" & sHTMDir & "\password.htm"   
            .ToolBar = 0
            .StatusBar = 0
            .Width = 325
            .Height = 160
            .Left = 72
            .Top = 72
            .Visible = 1
        End With
    
        On Error Resume Next
        Do While (oIEPW.Document.Body.All.OKClicked.Value = "")
            ' If Window is manually closed by user an error will be 
                ' generated, exit sub
            If Err <> 0 Then
                Call DelHTML(oFSO)
                Exit Sub
            End If
            Wscript.Sleep 250
        Loop 
        On Error GoTo 0
    
        sUserName = oIEPW.Document.Body.All.UserName.Value
        sPassword = oIEPW.Document.Body.All.UserPassword.Value
        oIEPW.Quit
        Call DelHTML(oFSO)
    End Sub
    
    Sub WriteHTML(oFSO)
        Dim sPWHTML, oTS
    
        sPWHTML = _
            "<!-- saved from url=(0054)http://msdn2.microsoft.com/en-us/" & _
                "library/ms537628.aspx -->" & VbCrLf & _
            "<head><title>Input Credentials</title></head>" & VbCrLf & _
            "<SCRIPT LANGUAGE=" & Chr(34) & "VBScript" & Chr(34) & ">" & VbCrLf & _
            VbCrLf & _
            "    Sub RunScript" & VbCrLf & _
            "        OKClicked.Value = " & Chr(34) & "OK" & Chr(34) & VbCrLf & _
            "    End Sub" & VbCrLf & _
            VbCrLf & _
            "    Sub CancelScript" & VbCrLf & _
            "        OKClicked.Value = " & Chr(34) & "Cancelled" & Chr(34) & _
            VbCrLf & _
            "    End Sub" & VbCrLf & _
            VbCrLf & _
            "</SCRIPT>" & VbCrLf & _
             VbCrLf & _
            "<BODY>" & VbCrLf & _
                "<font size=" & Chr(34) & "2" & Chr(34) & " face=" & Chr(34) & _
                    "Arial" & Chr(34) & ">UserName:&nbsp;&nbsp; </font>" & VbCrLf & _
                "<font face=" & Chr(34) & "Arial" & Chr(34) & "><input type=" & _
                    Chr(34) & "text" & Chr(34) & " name=" & Chr(34) & "UserName" _
                    & Chr(34) & " size=" & Chr(34) & "25" & Chr(34) & _
                    "></font><br>" & VbCrLf & _
                "<font size=" & Chr(34) & "2" & Chr(34) & " face=" & Chr(34) & _
                    "Arial" & Chr(34) & ">Password:&nbsp;&nbsp;&nbsp; </font>" _
                    & VbCrLf & _
                "<font face=" & Chr(34) & "Arial" & Chr(34) & "><input type=" _
                    & Chr(34) & "password" & Chr(34) & " name=" & Chr(34) & _
                    "UserPassword" & Chr(34) & " size=" & Chr(34) & "25" & _
                    Chr(34) & "></font></p>" & VbCrLf & _
                "<input type=" & Chr(34) & "hidden" & Chr(34) & " name=" & _
                    Chr(34) & "OKClicked" & Chr(34) & " size = " & Chr(34) & _
                    "20" & Chr(34) & ">" & VbCrLf & _
                "<center><input id=runbutton class=" & Chr(34) & "button" & _
                    Chr(34) & " type=" & Chr(34) & "button" & Chr(34) & _
                    " value=" & Chr(34) & " OK " & Chr(34) & " name=" & Chr(34) _
                    & "ok_button" & Chr(34) & " onClick=" & Chr(34) & "RunScript" _
                    & Chr(34) & ">" & VbCrLf & _
                "&nbsp;&nbsp;&nbsp;" & VbCrLf & _
                "<input id=runbutton class=" & Chr(34) & "button" & Chr(34) & _
                    " type=" & Chr(34) & "button" & Chr(34) & " value=" & _
                    Chr(34) & "Cancel" & Chr(34) & " name=" & Chr(34) & _
                    "cancel_button" & Chr(34) & " onClick=" & Chr(34) & _
                    "CancelScript" & Chr(34) & "></center>" & VbCrLf & _
            "</BODY>" & VbCrLf
    
    
        If oFSO.FolderExists(sHTMDir) = False Then oFSO.CreateFolder(sHTMDir)
    
        Set oTS = oFSO.OpenTextFile(sHTMDir & "\password.htm", 2, True)
        oTS.Write sPWHTML
        oTS.Close
    End Sub
    
    Sub DelHTML(oFSO)
        If oFSO.FileExists(sHTMDir & "\password.htm") Then oFSO.DeleteFile sHTMDir & "\password.htm", True
    End Sub

    Links:

    Username / Password entry with masking 

    www.tek-tips.com/viewthread.cfm?qid=1464252

    MapNetworkDrive Method 

    msdn.microsoft.com/en-us/library/8kst88h6(VS.84).aspx.

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

    Multirão de Respostas

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


    Fábio de Paula Junior

    quarta-feira, 24 de outubro de 2012 14:44
    Moderador