The MASM Forum

Projects => Poasm => Pelle's C compiler and tools => Topic started by: Vortex on November 09, 2013, 08:29:24 PM

Title: Accessing network shares
Post by: Vortex on November 09, 2013, 08:29:24 PM
Here is a quick example to access network shares. The code is based on some MSDN examples.

Usage: ConnShare letter remotename username password

ConnShare.exe Z: \\server\share Administrator p@ssw0rd!
Title: Re: Accessing network shares
Post by: dedndave on November 09, 2013, 09:00:43 PM
interesting - and educational, Erol   :t
Title: Re: Accessing network shares
Post by: Gunther on November 09, 2013, 10:10:46 PM
Well done, Erol.  :t Thank you.

Gunther
Title: Re: Accessing network shares
Post by: jj2007 on November 10, 2013, 04:40:39 AM
Crispy and clear, Erol - really nice :t

Here is the Masm version, with formatted errors instead of the numbers. Can't test it right now because I don't have a network, but it should work, too ;-)

include \masm32\MasmBasic\MasmBasic.inc        ; download (http://masm32.com/board/index.php?topic=94.0)
uselib mpr

.data?
nr NETRESOURCE <?>

  Init
  push eax
  invoke CommandLineToArgvW, rv(GetCommandLineW), esp
  pop ecx
  .if ecx==5
        mov nr.dwType, RESOURCETYPE_ANY
        mov nr.lpLocalName, CL$(1)
        mov nr.lpRemoteName, CL$(2)
        and nr.dwType, 0
        push FALSE
        push CL$(3)
        push CL$(4)
        lea eax, nr
        push eax
        call WNetAddConnection2
        .if eax == NO_ERROR
                Print "Connection added: ", CL$(2)
        .else
                Print "Error: ", Err$()
        .endif
  .else
        wPrint "ConnShare V1.0", wCrLf$, wCrLf$, "Usage: ConnShare letter remotename username password"
  .endif
  wInkey
  Exit
end start

OPT_Arg1        Z: \\server\share Administrator p@ssw0rd        ; for testing (RichMasm sets arguments this way)


For me, it returns "Error: Nessun provider di rete ha accettato il percorso di rete specificato.", which is for Google translate "Error: No network provider accepted the given network path.".
Title: Re: Accessing network shares
Post by: GoneFishing on November 10, 2013, 04:55:58 AM
G**gle query
indexof: /share
will give you lots of shared folders on the internet  ;)
Title: Re: Accessing network shares
Post by: Gunther on November 10, 2013, 05:28:45 AM
Thank you, Jochen for the MasmBasic version. Works fine for me.

Gunther
Title: Re: Accessing network shares
Post by: jj2007 on November 10, 2013, 05:54:48 AM
I have no experience with shared folders.
Does one of you have a concrete commandline that works?
Plus one for WNetCancelConnection2?
Title: Re: Accessing network shares
Post by: dedndave on November 10, 2013, 07:00:32 AM
i don't really know of a command-line interface for working with shared folders
i do know that if you want to share a folder, you can right-click/properties/sharing tab and do it that way
i suspect the info is buried in NTFS System Volume Information or, more likely, in the registry
it may be a group policy thing - i never dug into it   :P
Title: Re: Accessing network shares
Post by: dedndave on November 10, 2013, 07:09:46 AM
according to technet, "net" works if Run As Admin

http://technet.microsoft.com/en-us/library/cc770880.aspx#BKMK_cp (http://technet.microsoft.com/en-us/library/cc770880.aspx#BKMK_cp)
Title: Re: Accessing network shares
Post by: FORTRANS on November 10, 2013, 07:15:54 AM
Quote from: dedndave on November 10, 2013, 07:00:32 AM
i don't really know of a command-line interface for working with shared folders

Hi,

   If a resource is already shared, you can use the "NET USE"
command to access it from a command line.  Try "NET HELP"
and "NET HELP USE" to maximize the local entropy.  "NET View"
to see shared stuff.

Cheers,

Steve N.
Title: Re: Accessing network shares
Post by: dedndave on November 10, 2013, 07:23:27 AM
with a little further reading, i find that "net is old technology - not very reliable"
Title: Re: Accessing network shares
Post by: Gunther on November 10, 2013, 08:01:56 AM
Dave,

Quote from: dedndave on November 10, 2013, 07:23:27 AM
with a little further reading, i find that "net is old technology - not very reliable"

that's right. Here's a short summary. (http://www.computerhope.com/nethlp.htm#01)

Gunther
Title: Re: Accessing network shares
Post by: Vortex on November 10, 2013, 09:09:44 AM
Quote from: Gunther on November 10, 2013, 08:01:56 AM
Dave,

Quote from: dedndave on November 10, 2013, 07:23:27 AM
with a little further reading, i find that "net is old technology - not very reliable"

that's right. Here's a short summary. (http://www.computerhope.com/nethlp.htm#01)

Gunther

Hi Gunther and Dave,

I have to disagree. The net command does perfectly its job. I use it everyday at work to assign letters to network shares and I didn't experience any problem with the net command.
Title: Re: Accessing network shares
Post by: dedndave on November 10, 2013, 11:43:45 AM
well - i tried
net view
i got an error 6118
which may be a valid error, as i have no shares
Title: Re: Accessing network shares
Post by: Vortex on November 10, 2013, 08:35:02 PM
Hi Dave,

The net command is using the SMB protocol. Maybe, you have a firewall \ AV issue blocking the communication.
Title: Re: Accessing network shares
Post by: Gunther on November 10, 2013, 09:28:36 PM
Hi Erol,

no offense, I haven't used SMB since version 2.0. In the late 80s and in the 90s SMB was sometimes a bit tricky. That was my point. But you're right: it's under active development now.

Gunther