2016-08-05 1 views
0

사용자 워크 스테이션에 로그온 할 때 사용자의 세션을 인증하는 HTA 애플릿을 만드는 중입니다. 이상적으로는 사용자 인증시 네트워크 드라이브를 제거하는 대신 활성 네트워크 세션을 종료 할 수 있기를 원합니다.특정 네트워크 세션 연결을 끊으십시오.

3 일 전에 HTA에 대해서 알았 기 때문에 약간 어려움을 겪을 수 있습니다. VBS 지식도 그다지 좋지 않으므로 코드 예제를 바느질하여 작업하고 있습니다. 함께. HTA 방법은 명백한 어려움없이 드라이브를 매핑 할 수 있기 때문에 내가하고 싶은 것을 성취하는 가장 간단하고 적합한 방법 인 것 같습니다.

누군가 내 스크립트를 살펴보고 내가 할 수있는 방법을 말해 줄 수 있습니까 내가 수행하려는 작업을 수행하기 위해 최적화 하시겠습니까?? 나는 모든 단계를 배우므로, 저를 적절한 해결책으로 인도하십시오. (먼저 시도해보고 싶습니다).


목적 :

HTA는 사용자에 의해 시작되는 경우에만 특정 서버에서 현재 활성화 된 네트워크 세션을 제거 할 수.

문제 및 대상 :

가정 올바른 자격 증명 : 자격 증명은 "ExecMapping"라는 서브로 행진하고 유효한 길이 (공 i)를 할 스크립트에 의해 검증된다.

  1. 스크립트는 새 매핑을 만들 때 오류가 있는지 확인하는 ExecMapping Sub를 통해 완전히 실행됩니다. 복수의 매핑이 존재하는 경우, 그 특정의 매핑에 대해서 에러 다이얼로그가 슬로우됩니다.

  2. 대개의 경우, 예상대로 "다중 연결"오류가 발생합니다. 이것은 해결되어야 할 것입니다.

    Multiple Connection Error

스크립팅 :

<HEAD> 
<!-- Full Credits to the Authors of the ReadIni Function 

    Dependencies: 
    -> Logo (./Logo_alpha.png) 
    -> Ini File (./config.ini) 
    -> Icon (./Kreede$arch$.ico) 
--> 
<TITLE>Kreede Authenticator</TITLE> 

<HTA:APPLICATION 
    APPLICATIONNAME="Kreede Authenticator" 
    VERSION="1.2" 
    BORDER="none" 
    INNERBORDER="no" 
    CAPTION="no" 
    SYSMENU="no" 
    MAXIMIZEBUTTON="no" 
    MINIMIZEBUTTON="no" 
    ICON="Kreede32.ico" 
    SCROLL="no" 
    SINGLEINSTANCE="yes" 
    SHOWINTASKBAR="no" 
    CONTEXTMENU="no" 
    SELECTION="no"/> 
</HEAD> 

<SCRIPT language="vbscript"> 

Function ReadIni(myFilePath, mySection, myKey) 
    ' This function returns a value read from an INI file 
    ' 
    ' Arguments: 
    ' myFilePath [string] the (path and) file name of the INI file 
    ' mySection [string] the section in the INI file to be searched 
    ' myKey  [string] the key whose value is to be returned 
    ' 
    ' Returns: 
    ' the [string] value for the specified key in the specified section 
    ' 
    ' CAVEAT:  Will return a space if key exists but value is blank 
    ' 
    ' Written by Keith Lacelle 
    ' Modified by Denis St-Pierre and Rob van der Woude 

    Const ForReading = 1 
    Const ForWriting = 2 
    Const ForAppending = 8 

    Dim intEqualPos 
    Dim objFSO, objIniFile 
    Dim strFilePath, strKey, strLeftString, strLine, strSection 

    Set objFSO = CreateObject("Scripting.FileSystemObject") 

    ReadIni  = "" 
    strFilePath = Trim(myFilePath) 
    strSection = Trim(mySection) 
    strKey  = Trim(myKey) 

    If objFSO.FileExists(strFilePath) Then 
     Set objIniFile = objFSO.OpenTextFile(strFilePath, ForReading, False) 
     Do While objIniFile.AtEndOfStream = False 
      strLine = Trim(objIniFile.ReadLine) 

      ' Check if section is found in the current line 
      If LCase(strLine) = "[" & LCase(strSection) & "]" Then 
       strLine = Trim(objIniFile.ReadLine) 

       ' Parse lines until the next section is reached 
       Do While Left(strLine, 1) <> "[" 
        ' Find position of equal sign in the line 
        intEqualPos = InStr(1, strLine, "=", 1) 
        If intEqualPos > 0 Then 
         strLeftString = Trim(Left(strLine, intEqualPos - 1)) 
         ' Check if item is found in the current line 
         If LCase(strLeftString) = LCase(strKey) Then 
          ReadIni = Trim(Mid(strLine, intEqualPos + 1)) 
          ' In case the item exists but value is blank 
          If ReadIni = "" Then 
           ReadIni = " " 
          End If 
          ' Abort loop when item is found 
          Exit Do 
         End If 
        End If 

        ' Abort if the end of the INI file is reached 
        If objIniFile.AtEndOfStream Then Exit Do 

        ' Continue with next line 
        strLine = Trim(objIniFile.ReadLine) 
       Loop 
      Exit Do 
      End If 
     Loop 
     objIniFile.Close 
    Else 
     WScript.Echo strFilePath & " doesn't exists. Exiting..." 
     Wscript.Quit 1 
    End If 
End Function 

Sub Window_onLoad 
    Dim objNetwork 
    Dim objFSO 
    Set objNetwork = CreateObject("WScript.Network") 

    '### First Impressions! ### 
    window.resizeTo 480,270 
    window.moveTo screen.width/3, screen.height/4 

    '### Remove Previous Session's Access to Shared Drives ### 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    If objFSO.DriveExists("O") Then 
     objNetwork.RemoveNetworkDrive("O:") 
    End If 
    If objFSO.DriveExists("S") Then 
     objNetwork.RemoveNetworkDrive("S:") 
    End If 
    Set objNetwork = Nothing 

End Sub 

Sub CancelAction 

    '### Remove Previous Session's Access to Shared Drives ### 
    Set objNetwork = CreateObject("WScript.Network") 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    If objFSO.DriveExists("O") Then 
     objNetwork.RemoveNetworkDrive("O:") 
    End If 
    If objFSO.DriveExists("S") Then 
     objNetwork.RemoveNetworkDrive("S:") 
    End If 

    MsgBox "You have not logged in, and will not be able to access drives O: and S: To regain access, please run Kreede from your Desktop again.", vbOKOnly + vbCritical, "Important" 
    Set oShell = Nothing 
    Set objNetwork = Nothing 
    Self.Close() 

End Sub 

Sub ExecMapping 
    On Error Resume Next 

    Dim objNetwork, oShell, WshShell 

    Set objNetwork = CreateObject("WScript.Network") 
    Set oShell = CreateObject("Shell.Application") 
    Set WshShell = CreateObject("WScript.Shell") 

    '### Initialise all variables needed ### 
    strDriveLetter1 = "O:" 
    strDriveLetter2 = "S:" 
    '### Our Fail-Safe Locations, just in case... ### 
    strRemotePath1 = "\\172.16.18.3\corporate" 
    strRemotePath2 = "\\172.16.18.3\scratch" 
    strDriveAlias1 = "Corporate (HO)" 
    strDriveAlias2 = "Scratch (HO)" 
    intTimeout = 1 'Seconds 
    strMessage = "Login Succeeded!" 
    strTitle = "Success!" 

    '### We'll find out who you are in bit, but we first need to know where you are? ### 
    strBranch = UCase(ReadIni(".\config.ini", "Config-Data", "branch")) 

    Select Case strBranch 
     Case "HO" 
      strRemotePath1 = "\\172.16.18.3\corporate" 
      strRemotePath2 = "\\172.16.18.3\scratch" 
      strDriveAlias1 = "Corporate (HO)" 
      strDriveAlias2 = "Scratch (HO)" 
     Case "REM" 
      strRemotePath1 = "\\172.16.20.3\corporate" 
      strRemotePath2 = "\\172.16.20.3\scratch" 
      strDriveAlias1 = "Office (Remote)" 
      strDriveAlias2 = "Scratch (Remote)" 
    End Select 

    '### Are we working with humans? Set minimum length for validation ### 
    validUsr = 2 
    validPass = 3 

    '### Check if the Computer lied... ### 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    If objFSO.DriveExists("O") Then 
     objNetwork.RemoveNetworkDrive("O:") 
    End If 
    If objFSO.DriveExists("S") Then 
     objNetwork.RemoveNetworkDrive("S:") 
    End If 

    '### Map drives using the entered credentials ### 

    'STEP 1: Collect Credentials 
    strUser = TextBox1.Value 
    strPwd = TextBox2.Value 

    'STEP 2: Validate and Map! 
    If Len(strUser) >= validUser Then 
     strUsr = Ucase(strUser) 

     If Len(strPwd) >= validPass Then 
      Err.Clear 

      objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1, False, strUser, strPwd 
      If Err.Number <> 0 Then 
       MsgBox "MAP-O :: Error Occurred [" & Err.Number & "]: " & Err.Description    
      End If 

      objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2, False, strUser, strPwd 
      If Err.Number <> 0 Then 
       MsgBox "MAP-S :: Error Occurred [" & Err.Number & "]: " & Err.Description  
       Call CancelAction  
      End If 

      If Err.Number = 0 Then 
       oShell.NameSpace(strDriveLetter1).Self.Name = strDriveAlias1 
       oShell.NameSpace(strDriveLetter2).Self.Name = strDriveAlias2 
       intResult = WshShell.Popup(strMessage, intTimeout, strTitle) 
      End If 

     Else 
      Msgbox "Password is invalid!" 
      Exit Sub   
     End If 

    ELSE 
     Msgbox chr(34) & strUser & """ is not a valid username!" 
     Exit Sub 
    End If 

    Set oShell = Nothing 
    Set objNetwork = Nothing 
    Self.Close() 

End Sub 


</SCRIPT> 


<BODY STYLE=" 
    TEXT-ALIGN: center; 
    background-color: #dddddd; 
    FONT:10 pt verdana; 
    COLOR:black; 
    filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#FFCC66', EndColorStr='#FFFFFF') 
    "> 

<img src="./Logo_alpha.png" alt="Logo"></a><br> 
Please enter your corporate user credentials to access the Corporate Servers.<br><br> 
<CENTER> 
<HR color="#FF0000"> 
<table border="0" cellpadding="0" cellspacing="0"><font size="2" color="black" face="Arial"> 
    <tr> 
     <td height="30"> 
      <p align="right">Username</p> 
     </td> 
     <td height="30">&nbsp;&nbsp; <input type="text" name="TextBox1" size="30"> 
     </td> 
    </tr> 
    <tr> 
     <td height="30"> 
      <p align="right">Password</p> 
     </td> 
     <td height="30">&nbsp;&nbsp; <input type="password" name="TextBox2" size="30"> 
     </td> 
    </tr> 
</table> 

<HR color="#FF0000"> 
<Input id=runbutton class="button" type="button" value=" Login " name="run_button" onClick="ExecMapping"> 

&nbsp;&nbsp;&nbsp; 

<Input id=runbutton class="button" type="button" value="Cancel" name="cancel_button" onClick="CancelAction"><br> 
<span style="font-size: 8pt; color: red"><strong>If you cancel, you will not be able to access the O: and S: drives in this session.</strong></span> 
</CENTER> 
</BODY> 

답변

0

난 당신이 현재의 연결을 통해 모든 연결, 또는 첫번째 반복 처리를 제거하고 어떤 일치를 분리하기 위해 아래의 명령 행을 사용할 수 있습니다 중 하나를 생각한다 당신의 기준.

net use * /delete /yes 

또는 그 각각에 대해 다음 objNetwork.RemoveNetworkDriveobjNetwork.EnumNetworkDrives을한다.

** 참고 : 로컬 드라이브 문자로 매핑되어 그 연결, 당신은 objNetwork.RemoveNetworkDrive 같은 뭔가를 ("기업 \ \ 172.16.18.3")

행운이 필요합니다하십시오.

관련 문제