Link to home
Start Free TrialLog in
Avatar of mediaproxy
mediaproxy

asked on

use WNetAddConnection2 and WNetCancelConnection2 in javascript

Can anyone show me how to use WNetAddConnection2 and WNetCancelConnection2 in javascript to connect/disconnect to a remote computer?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of pinaldave
pinaldave
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mediaproxy
mediaproxy

ASKER

I've never used vbscript before. Can you let me know how to put them in a .aspx page ? And how to invoke the sub ?
I've tried to put it under the <body> tag but does not work
<script language="vbscript">
                        Option Explicit
                        Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String,                         errInfo = WNetAddConnection2(NETR, sPassword, sUser, CONNECT_UPDATE_PROFILE)

                                                                ..............................................' cut and paste the above code'

                        ConnectUserPassword = errInfo = NO_ERROR
                        End Function
                        
                        
                        
                        
            </script>
            <script language="vbscript">
                  msgbox("Connecting...")
                  Call ConnectUserPassword("\\192.168.100.110", "", "username", "password")
                                                msgbox("Connected")
                  
            </script>

The msgbox("connected") line is never executed. This means something went wrong before that line.
hi,
I personally never used vbscript that much. Very little knowledge. Let me give you small example.
Also there is very easy tutorial for vbscript in one or two pages, one can learn things.
http://visualbasic.about.com/library/bllvbscriptb.htm

   <html>
     <head>
     <title>Two Button Form</title>
     <SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
     <!--
     Sub buttonA_onclick
     MsgBox("Button A was clicked")
     End Sub
     Sub buttonB_onclick
     MsgBox("Button B was clicked")
     End Sub
     -->
     </SCRIPT>
     </head>
     <body>
     <INPUT type="button" value="A" id=buttonA name=buttonA>
     <INPUT type="button" value="B" id=buttonB name=buttonB>
     </body>
     </html>