Announcement

Collapse
No announcement yet.

VBScript Connect to network drive

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

  • VBScript Connect to network drive

    Hi Guys,

    I like the code from this post http://forums.petri.com/archive/index.php/t-15578.html

    I need help to modify it a little more though. so far I have;

    Code:
    <HTML>
    <HEAD>
    <TITLE>Share</title>
    <HTA:APPLICATION
    ApplicationName="MappingWithCredentials.HTA"
    SingleInstance="Yes"
    WindowsState="Normal"
    Scroll="No"
    Navigable="Yes"
    MaximizeButton="No"
    SysMenu="Yes"
    Caption="Yes"
    ></HEAD>
    
    <SCRIPT LANGUAGE="VBScript">
    
    Sub Window_Onload
    'Size Window
    sHorizontal = "440"
    sVertical = "175"
    Set objWMIService = GetObject _
    ("winmgmts:\\" & "." & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_DesktopMonitor")
    For Each objItem in colItems
    intHorizontal = objItem.ScreenWidth
    intVertical = objItem.ScreenHeight
    next
    Window.resizeTo sHorizontal,sVertical
    'Center window
    intLeft = (intHorizontal - sHorizontal) /2
    intTop = (intVertical - sVertical) /2
    Window.moveTo intLeft, intTop
    Set colItems = Nothing
    Set objWMIService = Nothing
    'default window content
    window.location.href="#Top"
    End Sub
    
    
    Sub RunScript
    on Error Resume Next
    
    ' *** variables
    
    
    
    fnOpenUrl("\\SERVER\Secret Share")
    
    
    minUSRnamelength = 4
    minPASSwrdlength = 3
    
    
    ' *** Map drive using the entered credentials
    
    strUsr = UsrnameArea.Value
    strPas = PasswordArea.Value
    
    Set objNetwork = CreateObject("WScript.Network")
    Set oShell = CreateObject("Shell.Application")
    
    If Len(strUsr) >= minUSRnamelength then
    strUsr = Ucase(strUsr) & strUPNsuffix '<--- adds the UPNsuffix to the account
    
    if Len(strPas) >= minPASSwrdlength then
    Err.Clear
    objNetwork.MapNetworkDrive mDrive, strRemoteShare, "FALSE", strUsr, strPas
    If Err.Number = 0 Then
    oShell.NameSpace(mDrive).Self.Name = strDriveAlias
    End If
    ELSE 
    Msgbox chr(34) & strPas & """ is an incorrect password !"
    Exit Sub
    End If
    ELSE 
    Msgbox chr(34) & strUsr & """ is an incorrect Username !"
    Exit Sub
    End If
    
    
    Set oShell = Nothing
    Set objNetwork = Nothing
    Self.Close()
    End Sub
    
    
    
    Sub fnOpenUrl(url)
    
    open url ,"NewWindow"
    
    
    End Sub
    
    
    
    Sub CancelScript
    Set oShell = Nothing
    Set objNetwork = Nothing
    Self.Close()
    End Sub
    
    
    </SCRIPT>
    
    
    <BODY STYLE="font:14 pt arial; color:white; filter:progid:DXImageTransform.Microsoft.Gradient( GradientType=1, StartColorStr='#000000', EndColorStr='#0000FF')">
    <a name="Top"></a><CENTER>
    <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="UsrnameArea" size="30"></td></tr>
    <tr>
    <td height="30">
    <p align="right">Password</p>
    </td>
    <td height="30">&nbsp;&nbsp; <input type="password" name="PasswordArea" size="30"></td></tr>
    </table><BR>
    <HR color="#0000FF">
    <Input id=runbutton class="button" type="button" value=" Open SHARE " name="run_button" onClick="RunScript">
    &nbsp;&nbsp;&nbsp; 
    <Input id=runbutton class="button" type="button" value="Cancel" name="cancel_button" onClick="CancelScript">
    </CENTER>
    </BODY>
    
    </HTML>
    What I need is for it to check against the Users Current Username and Password from their Win XP Pro session login on the Domain, then Open Secret Share in a new explorer window with no address bar.

    If the they enter the wrong Username or password then it needs to fail and popup with a msg as to why


    The reason for this is because with have info we want to keep hidden from service techs who remotely control the users desktop to show them how to do stuff in a business management program the users have.

    This in affect will give me the ability to have a system where the Users have to Login to connect to the network share and the Tech cant veiw this data unless the window is open.

    I hope I have explained this well enough,

    Any Help would be greatly appreciated.

    Cheers
    Last edited by vajutza; 13th June 2008, 06:43. Reason: spelling

  • #2
    Re: VBScript Connect to network drive

    I kind of think I know what you are trying to achieve but what is the actual problem?

    Topper
    * Shamelessly mentioning "Don't forget to add reputation!"

    Comment

    Working...
    X