wscript 中inputbox 並不能隱藏密碼,必須使用ScriptPW,但是 windows home edition版本並沒有相關的dll檔。除了copy scriptpw.dll 再執行註冊的方法外。參考

另一簡單方法就是跑html+vbscript or javascript

此法利用internet explorer,設計一個form 能輸入帳密後,再讓javascript 呼叫外部程式,傳參數到vbs 檔中,對samba server分享的磁碟机進行掛載,建立一html, 一vbs檔,放同文件夾


<head>
<script script type="text/javascript">

function showElements(oForm) {
  //current directory
  path = unescape(document.location) ;
  path = path.substring(8,path.lastIndexOf("/")+1) ;
  //str = "Form Elements of form " + oForm.name + ": \n"
 
   //for (i = 0; i < oForm.length; i++)
      id = oForm.elements[0].value ;
      passwd = oForm.elements[1].value ; //alert(passwd)
   
   //wscript vbsfile argv1 argv2  帶兩個參數進vbs
   cmdstr = 'wscript '+path+"mapdisk.vbs"+' '+id+' ' +passwd ;  //alert(cmdstr)
   
   var WshShell = new ActiveXObject("WScript.Shell");
   var oExec = WshShell.Exec(cmdstr);
 
}

</script>

</head>
<body>

<form name ="連結網路磁碟机" action="#" method="post">
帳號: <input type="text" name="id" size="50">
<p>
密碼: <input type="password" name="passwd" size="50">
<p>


<input type="button" name="submit" value="確定" onclick="showElements(this.form);">
</form>
</body>



  

mapdisk.vbs

'批次掛載屬行政人員帳號
if WScript.Arguments.Count < 2 Then
    WScript.Echo "帳號或密碼不得為空白"           
else
   
  Set argvs = WScript.Arguments
  'WScript.Echo (argvs.Item(0) & argvs.Item(1))
  id = argvs.Item(0)
  passwd = argvs.Item(1)
  Dim WshNetwork
 
  '有掛載的先移除,避免錯誤
                                               
  Set oExec = CreateObject("WScript.Shell")
  cmd = "net use " & "*" & " /delete /yes"
  'WScript.Echo cmd
  oExec.Run(cmd),1,1
     Wscript.Sleep 3000
      Set  WshNetwork = WScript.CreateObject("WScript.Network")
     UserHome="\\dns\教職員工$\" & id
     'WScript.Echo UserHome
     WshNetwork.MapNetworkDrive "u:",UserHome,"TRUE",id,passwd
      WshNetwork.MapNetworkDrive "x:","\\dns\共享資料夾$","TRUE",id,passwd                                                                     
      
       WshNetwork.MapNetworkDrive "w:","\\dns\行政業務$","TRUE",id,passwd
                                              
       WshNetwork.MapNetworkDrive "p:","\\dns\數位相片$","TRUE",id,passwd
       WshNetwork.MapNetworkDrive "r:","\\dns\Download$","TRUE",id,passwd
       WshNetwork.MapNetworkDrive "s:","\\dns\學生資料夾$","TRUE",id,passwd
       WshNetwork.MapNetworkDrive "y:","\\dns\WebAll$","TRUE",id,passwd

       WshNetwork.AddWindowsPrinterConnection "\\dns\RICOH2027"      
       WshNetwork.AddWindowsPrinterConnection "\\dns\HP5100"
       WshNetwork.AddWindowsPrinterConnection "\\dns\hp1300"      
        WshNetwork.AddWindowsPrinterConnection "\\dns\HP_C3700"  
       WshNetwork.AddWindowsPrinterConnection "\\dns\HP_C3800"    

       WshNetwork.SetDefaultPrinter "\\dns\RICOH2027"  
       WScript.Echo "掛載磁碟机成功"
      
end if 'WScript.Arguments.Count            



參考:

http://www.javascript-coder.com/javascript-form/javascript-forms-get-all-form-objects.htm

http://www.webdeveloper.com/forum/archive/index.php/t-98434.html

http://msdn.microsoft.com/en-us/library/8kst88h6%28VS.85%29.aspx

http://blogs.technet.com/b/heyscriptingguy/archive/2005/02/04/how-can-i-mask-passwords-using-an-inputbox.aspx

enumerate

http://www.computerperformance.co.uk/Logon/LogonScript_enumnetworkdrives.htm#Enumerate_Mapped_Network_Drives_Scenario_

創作者介紹
創作者 igogo 的頭像
igogo

牛大叔.生活隨筆

igogo 發表在 痞客邦 留言(0) 人氣()