1. Programmatically Map Network Drive in Windows

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! :)

new topic     » topic index » view message » categorize

2. Re: Programmatically Map Network Drive in Windows

euphoric said...

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) 
new topic     » goto parent     » topic index » view message » categorize

3. Re: Programmatically Map Network Drive in Windows

euphoric said...

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 
new topic     » goto parent     » topic index » view message » categorize

4. Re: Programmatically Map Network Drive in Windows

Thanks jim!

Interesting to see a commandline method.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu