tags:

views:

226

answers:

3

I'm finally set up to be able to work from home via VPN (using Shrew as a client), and I only have one annoyance. We use some batch files to upload config files to a network drive. Works fine from work, and from my team lead's laptop, but both of those machines are on the domain. My home system is not, and won't be, so when I run the batch file, I get a ton of "invalid drive" errors because I'm not a domain user.

The solution I've found so far is to make a batch file with the following:

explorer \\MACHINE1
explorer \\MACHINE2
explorer \\MACHINE3

Then manually login to each machine using my domain credentials as they pop up. Unfortunately, there are around 10 machines I may need to use, and it's a pain to keep entering the password if I missed one that a batch file requires.

I'm looking into using the answer to this question to make a little C# app that'll take the login info once and login programmatically. Will the authentication be shared automatically with Explorer, or is there anything special I need to do? If it does work, how long are the credentials cached?

Is there an app that does something like this automatically?

Unfortunately, domain authentication via the VPN isn't an option, according to our admin.

EDIT: If there's a way to pass login info to Explorer via the command line, that would be even easier using Ruby and highline.

EDIT: In case anyone else has the same problem, here's the solution I wound up using. It requires Ruby and the Highline gem.

require "highline/import"

domain = ask("Domain: ")
username = ask("Username: ")
password = ask("Password: ") { |q| q.echo = false }

machines = [
    '\\MACHINE1\SHARE', 
    '\\MACHINE2\SHARE', 
    '\\MACHINE3\SHARE', 
    '\\MACHINE4\SHARE', 
    '\\MACHINE5\SHARE'
]
drives = ('f'..'z').to_a[-machines.length..-1]

drives.each{|d| system("net use #{d}: /delete >nul 2>nul"); }

machines.zip(drives).each{|machine, drive| system("net use #{drive}: #{machine} #{password} /user:#{domain}\\#{username} >nul 2>nul")}

It'll figure out how many mapped drives I need, then start mapping them to the requested shares. In this case, it maps them from V: to Z:, and assumes I don't have anything shared with those drive letters.

If you already have an Explorer window open to one of the shares, it may give an error, so before I ran the Ruby script, I ran:

net use * /delete

That cleared up the "multiple connections to a share not permitted" error, and allowed me to connect with no problems.

+1  A: 

to pass credential by command line to the explorer you should take a look into the command net use

Oliver
I was looking into that, too. I don't want to map the drive, though. I'm trying "net use z: \\MACHINE1 password /USER:DOMAIN\username /SAVECRED", and I'm getting "A command was used with conflicting switches". Any ideas? Can that be done without mapping a drive?
Chris Doggett
A: 

Use API WNetAddConnection2() via P/Invoke.

Seva Alekseyev
+1  A: 

You could create a batch file that uses "NET USE" to connect to your shares. You'd need to use a drive letter for each share, but it'd be super simple to implement.

Your batch file would look like this:

net use h: \\MACHINE1 <password> /user:<domain>\<user>
net use i: \\MACHINE2 <password> /user:<domain>\<user>
net use j: \\MACHINE3 <password> /user:<domain>\<user>

UPDATE

Whether the connection remains or not depends upon what you specified for the /persistent switch. If you specified yes, then it will attempt to reconnect upon your next logon. If you specified no then it won't. The worrying this is the documentation says that it defaults to the value that you used last!

If you specified no, the connection will remain until you next reboot. If you drop your VPN connection the drive would be unavailable (but if you reconnect to the VPN the drive should be available as long as you haven't removed it).

I don't know of a way to use it without mapping to a drive letter, the documentation would lead you to believe that it isn't possible.

I understand your problem, that you're just trying to give explorer the correct credentials so it stops nagging you with login boxes. Using mapped drives though not perfect will at least alleviate your pain.

DoctaJonez
See my comment to Oliver below. Is there a way to not have to map a drive? Removing "/SAVECRED" let it map the drive, so technically, it works, but how long will it retain the credentials? If I drop the VPN connection to the domain, will it hang, or will they just be inaccessible?
Chris Doggett