"Larry Smith" <no_spam@_nospa m.comwrote in message
news:%2******** **********@TK2M SFTNGP05.phx.gb l...
>The easiest solution for this is to create a "use record" for your login
session.
the command should look like:
"net use \\otherpc\share name passwd /user:validUserO nOtherpc"
The way you do this is by placing a "net use" command in your
autoexec.bat file.
Another option is to execute the above "net use" from your code (using
System.Diagnos tics.Process.St art), this way you can delete the network
connection when done with it.
Note that you can use the IPC$ instead of a share name, this gives you
access to all of the resources on the "other" pc.
There should be a .NET function for this somewhere however since spawning
"net.exe" from code is ugly IMO (and he shouldn't publish his password in
a batch file if he decides to go that route). Also note that IPC$ is
really just a login (authentication ) resource for all intents and purposes
(unlike other resources where a DACL check is immediately conducted
against the resource). Once your're authenticated on the remote machine
using IPC$, your network session on that machine is still subject to
normal access checks on whatever resources you touch (which gets into
shared resource permissions vs normal NTFS permissions but that's another
story). Access denied can still occur IOW if you later touch a resource
you don't have access to (whereas access denied will occur right away if
you authenticate against the target resource from the outset, opposed to
IPC$).
Unfortunaly there is no .NET API for this, and if there was, you would have
to pass the credentials anyway (as per WNetAddConnecti on2), Sure, I agree
you shouldn't hard code credentials, but all depends on the security
constraints imposed.
Now I suppose that the OP is talking about a home like environment, so
security is IMO not an issue, he knows the password (guess it's even the
administrators pwd) required to access the other PC's resources, which
implies a non-secured environmant anyway.
In such scenario, storing a pwd in a batch file he owns (say in his user
profile) doesn't impose such a security risk. If it is, or if he cares about
security, he should prompt for the credentials interactively and pass them
to the API he calls whatever this API may be. As to spawning "net use", is
IMO not that ugly, the Process.Start api provides everything to run the
command without showing the command windows, so why you consider this to be
ugly is beyond me, given the fact that there is no .NET API to connect to a
shared resource.
Willy.