Jump to content
Sign in to follow this  
VirtMcPolygon

Map Drive to Server on Different Domain

Recommended Posts

VirtMcPolygon

Hi folks,

I've only just become aware of AutoIT and the power of its scripting so please be gentle with me. :)

I have a situation where some client machines which are connected to a different companies corporate domain than our own, need access to data on one of our file servers. Local usernames have been setup for security passthru and this all works as they currently use batch files with the net use commmands to map the drives.

I would like to do something a little more eligant if possible and it seems AutoIT is the way forward for this and so much more.

So far I am using the following script compiled as an .exe and when executed it prompts a windows dialogue box to Joe Bloggs for the his local account password that is setup on the "servername" and then maps the drives.

DriveMapDel("H:")
DriveMapDel("S:")
DriveMapAdd("H:", "\\servername\Shared", 8, "servername\joe.bloggs")
DriveMapAdd("S:", "\\servername\Home", 8, "servername\joe.bloggs")

Seen as we have quite a few users accessing the data and a high staff turnover, I'd like to create an easier option to lighten the workload requests so essentially I would like the same windows prompt but this time for the username as well as the passwords to be entered and the "servername" to be predefined as the server validating the account information.

I've tried this but without any luck.

DriveMapDel("H:")
DriveMapDel("S:")
DriveMapAdd("H:", "\\servername\Shared", 8, "servername\", & $user, $passwd)
DriveMapAdd("S:", "\\servername\Home", 8, "servername\", & $user, $passwd)

Any help would be much appreciated.

Thanks

Share this post


Link to post
Share on other sites
computergroove

#include <MagBoxConstants.au3>

DriveMapDel("H:")
DriveMapDel("S:")
$temp1 = DriveMapAdd("H:", "\\servername\Shared", 8, "servername\", & $user, $passwd)
MsgBox(0,"DriveMap H Syntax",$temp1)
$temp2 = DriveMapAdd("S:", "\\servername\Home", 8, "servername\", & $user, $passwd)
MsgBox(0,"DriveMap S Syntax",$temp2)

My guess is that you need to add a space between $user and $passwd. Try the above and see if the spacing is correct.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
VirtMcPolygon
#include <MagBoxConstants.au3>

DriveMapDel("H:")
DriveMapDel("S:")
$temp1 = DriveMapAdd("H:", "\\servername\Shared", 8, "servername\", & $user, $passwd)
MsgBox(0,"DriveMap H Syntax",$temp1)
$temp2 = DriveMapAdd("S:", "\\servername\Home", 8, "servername\", & $user, $passwd)
MsgBox(0,"DriveMap S Syntax",$temp2)

My guess is that you need to add a space between $user and $passwd. Try the above and see if the spacing is correct.

Hi there,

Thanks for the response.

I presume the #include <MagBoxConstants.au3> should be #include <MsgBoxConstants.au3>. When I run the script I get Error: Variable used without being declared in line 5.

Share this post


Link to post
Share on other sites
spudw2k

Hi there,

Thanks for the response.

I presume the #include <MagBoxConstants.au3> should be #include <MsgBoxConstants.au3>. When I run the script I get Error: Variable used without being declared in line 5.

 

Correct, but I think it's eroneous in this example anyways as you aren't using any MsgBox constants.

edit:

On a side note...that comma ampersand sticks out to me.  I'm not sure it should be like that.

Correct as pointed out by misiooo below.  The comma was/is erroneous.

Edited by spudw2k

Share this post


Link to post
Share on other sites
misioooo

Correct, but I think it's eroneous in this example anyways as you aren't using any MsgBox constants.

On a side nite...that comma ampersand sticks out to me.  I'm not sure it should be like that.

 

;& $user $temp1 = DriveMapAdd("H:", "servernameShared", 8, "servername", & $user, $passwd) ;just $user $temp1 = DriveMapAdd("H:", "servernameShared", 8, "servername", $user, $passwd)

Looking at DriveMapAdd help file shouldnt it be like:

$temp1 = DriveMapAdd("H:", "\\servername\Shared", 8, "servername\"&$user, $passwd)

"domain"&$user = "domainusername" where username is a variable.

Taken from example in help file: https://www.autoitscript.com/autoit3/docs/functions/DriveMapAdd.htm

Share this post


Link to post
Share on other sites
spudw2k

Um, yea...you're right.  I should've looked at the Func instead of assuming the servername and username were separate parameters.  Sorry for the confusion.

Share this post


Link to post
Share on other sites
VirtMcPolygon

Guys, I appreciate the feedback.

Evertime I try one of your examples though I getting an Error: Variable used without being declared message.

Currently I have been using the following and converted to an .exe.

DriveMapDel("X:")
DriveMapDel("Y:")
DriveMapAdd("X:", "\\servername\home\user.name", 8, "servername\user.name")
DriveMapAdd("Y:", "\\servername\Shared", 8, "servername\user.name")

When using this the user is prompted with a Windows login box before proceeding to map the drives.

I am however having some issues where the program won't work for no apparent reason and I have to resort to the old net use batch file to complete the mapping so still on the hunt for a working reliable solution.

Share this post


Link to post
Share on other sites
spudw2k

Try inspecting @error after each DriveMapAdd to see if there is a reason why it isn't working.

Return Value

Success: 1. (See Remarks)

Failure: 0 if a new mapping could not be created and sets the @error flag to non-zero.

@error:

1 = Undefined / Other error. @extended set with Windows API return
2 = Access to the remote share was denied
3 = The device is already assigned
4 = Invalid device name
5 = Invalid remote share
6 = Invalid password

DriveMapDel("X:")
DriveMapDel("Y:")
If Not DriveMapAdd("X:", "\\servername\home\user.name", 8, "servername\user.name") Then Msgbox(0,"DriveMapAdd(X:) failed", @error)
If Not DriveMapAdd("Y:", "\\servername\Shared", 8, "servername\user.name") Then Msgbox(0,"DriveMapAdd(Y:) failed", @error)
Edited by spudw2k

Share this post


Link to post
Share on other sites
VirtMcPolygon

 

Try inspecting @error after each DriveMapAdd to see if there is a reason why it isn't working.

Return Value

Success: 1. (See Remarks)

Failure: 0 if a new mapping could not be created and sets the @error flag to non-zero.

@error:

1 = Undefined / Other error. @extended set with Windows API return

2 = Access to the remote share was denied

3 = The device is already assigned

4 = Invalid device name

5 = Invalid remote share

6 = Invalid password

DriveMapDel("X:")
DriveMapDel("Y:")
If Not DriveMapAdd("X:", "\\servername\home\user.name", 8, "servername\user.name") Then Msgbox(0,"DriveMapAdd(X:) failed", @error)
If Not DriveMapAdd("Y:", "\\servername\Shared", 8, "servername\user.name") Then Msgbox(0,"DriveMapAdd(Y:) failed", @error)

 

Get error 1 mainly.

It's weird, the permissions have been granted as going to the server via unc path works and the permissions work in granting share access. Just sometimes it fails to add the drive to Widows explorer.

Edited by VirtMcPolygon

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×