Forum: Ruby Map Windows drives with Ruby

Posted by Charlie B. (charlie_b84)
on 2012-12-28 22:41
Have ruby scripts running on Windows and I'm having an issue with
mapping network drives. Yes, I need to do this with Ruby for a couple
reasons.

No matter what my method or syntax is, I always get an error that the
network name can not be found.  I've quadruple checked spelling and I
can manually browse and map the path in my script.  But running the
script it says it can't find the path.  Here is some code I tried:

require 'win32ole'
net = WIN32OLE.new('WScript.Network')
user_name = 'some_user_name'
password = 'top-secret-password'

net.MapNetworkDrive( 'X:', '\\server\share', nil,  user_name, password )

I get:

OLE error code:80070043 in WSHNetwork.MapNetworkDrive
  The network name cannot be found.

HRESULT error code:0x80020009
  Exception occurred.
    from test.rb:7:in `<main>'

If I use back ticks and enclose the command, I get a System 87 error
which is Windows telling me it can't find the path.

Any idea what is going on?  Or is there better syntax I can be using?
Posted by Jon Forums (jonm)
on 2012-12-29 02:36
> require 'win32ole'
> net = WIN32OLE.new('WScript.Network')
> user_name = 'some_user_name'
> password = 'top-secret-password'
>
> net.MapNetworkDrive( 'X:', '\\server\share', nil,  user_name, password )

What happens when you double up the backslashes?

  net.MapNetworkDrive( 'X:', '\\\\server\\share', nil,  user_name,
password )
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.