2015-04-30 52 views
1

我有一個映射驅動器的VBS腳本。根據用戶映射通用文件夾(不需要憑據)或個人文件夾(需要用戶名和密碼)。我目前正在使用標準的WSH輸入端,這顯然不太安全,因爲密碼是未被屏蔽的將輸入值從HTA返回到打開它的VBS腳本

我已經使用ScriptPW.dll尋找解決方案,但這已不再是Windows原生(I' m使用Windows 7),並從XP複製並註冊時不起作用。

我現在正在看的一個解決方案是使用HTA來提示輸入用戶名/密碼。當需要的時候,我已經到了運行該文件的地步,但我不知道如何(或者即使可以)從窗體返回輸入值到父腳本。

這可能嗎?

注意 - 由於表格在所有情況下都不需要,我不能將整個腳本放在HTA中。

這裏是我如何調用HTA -

Dim Shell 
Set Shell = Wscript.CreateObject("Wscript.Shell") 
Shell.Run("test.hta"), 1, True 
Set Shell = Nothing 

這裏是HTA -

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /> 
    <title>Login Application</title> 
    <hta :application 
     applicationname="LoginBox" 
     border="dialog" 
     borderstyle="normal" 
     caption="My HTML Application" 
     contextmenu="no" 
     maximizebutton="no" 
     minimizebutton="yes" 
     navigable="no" 
     selection="no" 
     showintaskbar="yes" 
     singleinstance="yes" 
     sysmenu="yes" 
     version="1.0" 
     windowstate="normal" /> 

</head> 
<body> 
    <form id="LoginForm"> 
     Enter Username: <input type="textbox" id="UserName"/><br /> 
     Enter Password: <input type="password" id="Password"/><br /> 
     <input type="submit" value="Open my scans"/> 
    </form> 
</body> 
</html> 
+0

不要將用戶和密碼返回給調用者。映射在HTA的驅動器 –

回答

1

我覺得這個功能PasswordBox可以幫你,只是給一個嘗試; )

' Just an example of how to use the function 
' 
wsh.echo "You entered: ", _ 
      Join(PasswordBox("Enter UID and password", _ 
       "Testing"), ", ") 

' A function to present a Password dialog in a VBS (WSF) 
' script 
' Requires WScript version 5.1+ 
' Tom Lavedas <[email protected]> 
' with help from and thanks to Joe Ernest and 
' Michael Harris 
' 
' modified 1/2008 to handle IE7 
' 
Function PasswordBox(sPrompt,sDefault) 
    set oIE = CreateObject("InternetExplorer.Application") 
    With oIE 
' Configure the IE window 
    .RegisterAsDropTarget = False 
    .statusbar = false : .toolbar = false 
    .menubar = false : .addressbar = false 
    .Resizable = False 
    .Navigate "about:blank" 
    Do Until .ReadyState = 4 : WScript.Sleep 50 : Loop 
' Test for IE 7 - cannot remove 'chrome' in that version 
    sVersion = .document.parentWindow.navigator.appVersion 
    if instr(sVersion, "MSIE 7.0") = 0 Then .FullScreen = True 
    .width = 400  : .height = 270 
' Create the password box document 
    With .document 
     oIE.left = .parentWindow.screen.width \ 2 - 200 
     oIE.top = .parentWindow.screen.height\ 2 - 100 
     .open 
     .write "<html><head><" & "script>bboxwait=true;</" _ 
      & "script><title>Password _</title></head>"_ 
      & "<body bgColor=silver scroll=no " _ 
      & "language=vbs style='border-" _ 
      & "style:outset;border-Width:3px'" _ 
      & " onHelp='window.event.returnvalue=false" _ 
      & ":window.event.cancelbubble=true'" _ 
      & " oncontextmenu=" _ 
      & "'window.event.returnvalue=false" _ 
      & ":window.event.cancelbubble=true'" _ 
      & " onkeydown='if ((window.event.keycode>111)"_ 
      & " and (window.event.keycode<117)) or" _ 
      & " window.event.ctrlkey then" _ 
      & " window.event.keycode=0" _ 
      & ":window.event.cancelbubble=true" _ 
      & ":window.event.returnvalue=false'" _ 
      & " onkeypress='if window.event.keycode=13" _ 
      & " then bboxwait=false'><center>" _ 
      & "<div style='padding:10px;background-color:lightblue'>" _ 
      & "<b>&nbsp" & sPrompt & "<b>&nbsp</div><p>" _ 
      & "<table bgcolor=cornsilk cellspacing=10><tr><td>" _ 
      & " <b>User:</b></td><td>" _ 
      & "<input type=text size=10 id=user value='" _ 
      & sDefault & "'>" _ 
      & "</td><tr><td> <b>Password:</b></td><td>" _ 
      & "<input type=password size=12 id=pass>" _ 
      & "</td></tr></table><br>" _ 
      & "<button onclick='bboxwait=false;'>" _ 
      & "&nbsp;Okay&nbsp;" _ 
      & "</button> &nbsp; <button onclick=" _ 
      & "'document.all.user.value=""CANCELLED"";" _ 
      & "document.all.pass.value="""";" _ 
      & "bboxwait=false;'>Cancel" _ 
      & "</button></center></body></html>" 
     .close 
     Do Until .ReadyState = "complete" : WScript.Sleep 100 : Loop 
     .all.user.focus 
     .all.user.select ' Optional 
     oIE.Visible = True 
     CreateObject("Wscript.Shell")_ 
     .Appactivate "Password _" 
     PasswordBox = Array("CANCELLED") 
     On Error Resume Next 
     Do While .parentWindow.bBoxWait 
     if Err Then Exit Function 
     WScript.Sleep 100 
     Loop 
     oIE.Visible = False 
     PasswordBox = Array(.all.user.value, _ 
          .all.pass.value) 
    End With ' document 
    End With ' IE 
End Function 
+0

看起來非常有前途,我即將嘗試並融入我的解決方案... –

+1

這工作像一個魅力,除了一些CSS添加到標題(這就是我只是OCD thouhg) ,它開箱即用。感謝發佈。 –