Map Windows drives with Ruby

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 `’

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?

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 )