1. Programmatically Map Network Drive in Windows
- Posted by euphoric (admin) Dec 01, 2010
- 2423 views
I need to be able to programmatically map/disconnect network drives in Windows. MS provides this functionality in the WNetAddConnection2 function, but I don't know how to make use of it.
I checked the archive and there's nothing there for this.
The page linked above has sample code in C. If someone would write a Euphoria wrapper, I'd be very thankful! :)
2. Re: Programmatically Map Network Drive in Windows
- Posted by jimcbrown (admin) Dec 01, 2010
- 2425 views
I need to be able to programmatically map/disconnect network drives in Windows. MS provides this functionality in the WNetAddConnection2 function, but I don't know how to make use of it.
I checked the archive and there's nothing there for this.
The page linked above has sample code in C. If someone would write a Euphoria wrapper, I'd be very thankful! :)
system("net use ...",2) system("net use /d ...",2)
3. Re: Programmatically Map Network Drive in Windows
- Posted by jimcbrown (admin) Dec 01, 2010
- 2435 views
I need to be able to programmatically map/disconnect network drives in Windows. MS provides this functionality in the WNetAddConnection2 function, but I don't know how to make use of it.
I checked the archive and there's nothing there for this.
The page linked above has sample code in C. If someone would write a Euphoria wrapper, I'd be very thankful! :)
Untested.
include std/machine.e include std/dll.e constant it = define_c_func(open_dll("Mpr.dll"), "WNetAddConnection2", {C_POINTER, C_POINTER, C_POINTER, C_INT}, C_INT) function doit(sequence localdrive, sequence remoteshare) atom ret, ptr, providername = 0, username = 0, -- null to make it windows 9x friendly password = 0, -- null to make it windows 9x friendly localptr = allocate_string(localdrive), remoteptr = allocate_string(remoteshare) integer flags = 4, sizeof_netresource = 8*4, resourcetype_disk = 1 ptr = allocate(sizeof_netresource) memset(ptr, 0, sizeof_netresource) poke4(ptr+4, resourcetype_disk) poke4(ptr+16, localptr) poke4(ptr+20, remoteptr) poke4(ptr+28, providername) -- i know this is redundant because of the memset() ret = c_func(it, {ptr, username, password, flags}) free(ptr) free(localptr) free(remoteptr) return ret end function
4. Re: Programmatically Map Network Drive in Windows
- Posted by euphoric (admin) Dec 01, 2010
- 2351 views
Thanks jim!
Interesting to see a commandline method.