Results 1 to 8 of 8

Thread: [Resolved] Cannot map network drive!

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    53

    [Resolved] Cannot map network drive!

    Background:
    The website is run on a remote server. An asp-page handles access rights and list network drives. The asp-page is then redirected to an aspx-page with an ascx usercontrol. The usercontrol holds a dropdownlist with listed networkdrives as options to select.

    To achieve:
    Map selected driver.

    I have succeeded to map from the asp-page as long as the redirect to the aspx-page is disabled. If I redirect the mappping doesn't work.

    Now I have tryed several ways to map from the aspx-page

    1) reference to an interop dll made from an ocx that works on the asp-page. Doesn't work. I guess it's because it runs on server side.

    2) API functions from mpr.dll like WNetAddConnection2 function. Doesn't work. Same reason I believe though it works from an ordinary exe on the client.

    3) Using Diagnostic.Process.Start running net.exe. Same reason I believe (server side). Net.exe is registered and map drives from command window.

    4) Running a vb script doesn't work either. I believe vb scripts doesn't run with .net.

    5) Last try was with a javascript. Added "onchange" attribute to dropdownlist to run the javascript function. I can start Word with ActiveXobject("Word.Application") but I can't run net.exe whith ActiveXobject("Shell.Application").

    Any ideas how to solve this would be appreciated.
    Last edited by minor28; May 23rd, 2007 at 01:18 AM.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Cannot map network drive!

    I don't understand the first part of your question. What are you trying to do that requires you to redirect, what do you mean by 'map selected driver'?

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: Cannot map network drive!

    It's a local network, .NET web application ( I don't know the correct expression in english) the platform is .NET but ther is a part that is asp. Theese asp-pages are very complicated so it is nessessary to keep them for now. However I am changing some asp code to be able to either proceed to other asp pages or go a new .NET web application. That requires to redirect. I am not sure this makes it clearer.

    Now I have the path to network drives and corresponding local names. The drives are listed in the dropdownlist. Select a drive and it should be mapped.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Cannot map network drive!

    So from what I gather, you want to be able to map a network drive using an ASP.NET page.

    I would say #2 then, even though you couldn't get it to work. In any case, you would need to use WMI to accomplish the mapping of a drive.

    But, but, but, but before that... do you want to map the drive on the web server or on the user's machine?

    If it's the user's machine then you'd most likely have to go for #1, assuming that it's an ActiveX control. And if it is, just have the same control sit on the ASP.NET page.

    Keep in mind, ASP.NET is just like ASP, you can't directly affect a user's machine from the web server. You need some 'client' code. That's where ActiveX comes in.

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: Cannot map network drive!

    I want to map on the user´s machine.

    Using the .ocx on the asp page works if as long as I not redirect to aspx. The mapping is executed before redirecting.

    I have also tryed to insert the ocx on the aspx page in the same way as on the asp. It doesn't work.

    Using #2 will throw this exeption "No network provider accepted the given network path".
    #3 will throw "The directory name is invalid"
    #1 this "Retrieving the COM class factory for component with CLSID {..} failed due to the following error: 80040154

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Cannot map network drive!

    "as long as I not redirect to aspx"

    When and in what component does this redirection occur

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: Cannot map network drive!

    This is the asp page and this works. Redirect instruction commented. Map() is a function in an .ocx.
    Code:
    txt = split(mappingString,"|||")
    str = split(txt(1),"||")
    for each str in txt
    	s = split(str,"||")
    	Response.Write "<script type=""text/VBScript"">Map(""" & s(1) & """)</script>"
    next
    'Response.Redirect("KMP.aspx?uppdrnr=" & Uppdragsnr & "&mapping=" & mappingString)
    And this doesn't. Redirect instruction uncommented.
    Code:
    txt = split(mappingString,"|||")
    str = split(txt(1),"||")
    for each str in txt
    	s = split(str,"||")
    	Response.Write "<script type=""text/VBScript"">Map(""" & s(1) & """)</script>"
    next
    Response.Redirect("KMP.aspx?uppdrnr=" & Uppdragsnr & "&mapping=" & mappingString)
    Actually I don't want to mapp all drives. My intention is to list the drives in the dropdownlist and map the selected drive.

    My present situation is a success to map selected drive but with a security warning. To the dropdownlist I added onchange attribute and a javascript fuction MapDrive() and set AutoPostback to false.
    Code:
    <asp:DropDownList onchange="MapDrive();" ID="DropDownList1" runat="server" Width="240px" Font-Size="10px">
    This is the javascript function
    Code:
    function MapDrive()
    {
        var selectedvalue = "";
        var oDD = document.getElementsByTagName("option");
        var count = document.getElementsByTagName("option").length;
        var i = 0;
        
        for (i = 0; i < count; i++)
        {
            if (oDD.item(i).selected == true)
            {
                selectedvalue = oDD.item(i).value;
                break;
            }
        }
        if (selectedvalue != "Choose server")
        {
            var splitted = selectedvalue.split('|');
            var commandParam = "net.exe use " + splitted[2] + ": " + splitted[0]
            var oWSCRIPT = new ActiveXObject("WSCRIPT.SHELL");
            oWSCRIPT.Run(commandParam,0,true);
        }
    }
    var oWSCRIPT = new ActiveXObject("WSCRIPT.SHELL") gives the security warning but will map the drive.

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: [Resolved] Cannot map network drive!

    I solved the problem by writing my own safe ActiveX component.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width