Jump to content

Map network drive on remote machine


Go to solution Solved by confuseis,

Recommended Posts

Hi all

To Map a network drive on remote machine is difficult as you must run it under their user session, psexec can run under your own creds which does not work for this scenario as we dont have their password.

I dont have access to group policy hence looking to AutoIT.

Im looking at sending copying the AutoIT script onto their desktop and running it from there.

The script will interact with start > computer > [map net work drive]

Problem is the window finder application cannot see that explorer button, so then how do I get Auto IT to click it?

I could note the mouse cursor position and click it that way but then Im thinking the screen resolution could be different on the remote machine and the x,y coordinates for the mouse will be off?

Any pointers on how to detect and click the windows explorer buttons or how to accomplish this in general?

Thanks for reading

Confuseis

Link to comment
Share on other sites

DriveMapAdd

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Looks good

To executive this remotely Im thinking that I would compile the script with the drivemap adding to an exe then launch this exe from a bat file on the remote users system using psexec, any one know a more dirtect way let me know

Ill report back my outcome

Thanks

Link to comment
Share on other sites

Hi all

To Map a network drive on remote machine is difficult as you must run it under their user session,

 

put a net use... command in the registry HKLMSOFTWAREMicrosoftWindowsCurrentVersionRun

this can be done remotely with your admin credentials.

the drive will be mapped at next logon for any user.

when you are done with whatever operation this is required, remove the registry entry.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

I'll give that a shot.   I was thinking an alternative would be to put a .bat file in the startup folder of the user of windows as this would would map the drive on boot.

I want this to be more automatic so I would execute the script just once the volume of machines makes it diffulct, also these machines are laptops and move around frequently so its likely I wouldnt be able to track and clean all of them.

In that case I would need the registry entry to be removed automatically as I dont want to remember to remove it from 100 or so machines,

perhaps the regedit command for the reg method or the if exist bat file x delete bat file x from the doat file in the startup folder method

The command prompt is disabled by policy on the remote machines so the bat file from the startup folder may not run.

I was'nt aware the the reg method so this is useful

Thanks

Confuseis

Link to comment
Share on other sites

I've tried the "DriveMapAdd" command, It works aginst your own logon but executing it remotely dosent seem to map the drive for the remote user.  If the remote user clicks it then it works.

I've been trying to launch the DriveMapAdd command compiled as an exe on the remote machine and psexec reoprts the exe ran successfully but the drive did not map.

I can use a bat file to map the drive in the same way as drivemap add but this is not remotely.

I could map it remotely with the users creds with psexec but I dont want to know their creds.

Is there a way to map the drive without user intervention and without needing a reeboot?

Thanks

Confuseis

Link to comment
Share on other sites

I would suggest downloading psexec.exe (part of Microsoft PSTools package), and save the PSTools folder onto C:

The following lines will remotely map a drive to a network share, then wait 2 seconds, then remove the share. One thing I noticed is that on the remote PC the share shows up as "Disconnected" but I was still able to browse the share.

Hope this helps:

;~ The -s switch runs the command as system, the y: can be substituted for any letter, and if you switch the @SW_Hide to @SW_SHOW, you can see the output.
Run(@ComSpec & ' /k C:\PSTools\psexec.exe -s \\remotecomputer net use y: \\networkshare /user:domain\user password', '', @SW_HIDE)
Sleep(2000)
Run(@ComSpec & ' /k C:\PSTools\psexec.exe -s \\remotecomputer -e net use y: /delete /y', '', @SW_HIDE)

Thanks

Grimm

Link to comment
Share on other sites

  • Solution

Thats the concusion I came to also all be in a different way got it working today -Hurrah.   Maps in realtime on remote system.  Online so many nay sayers saying it was impossible.  -i is for interact

psexec -i -u .LocalPCaccountname -p LocalPCPassword  PChostname   c:mapnetdrive.exe(created in autoIT)

Main thing here was with the exe I used sending keypressing to travese the windows explorer to do the work, which is some up front effort.  The program interacts with windows explorer on the current users session.

The executable needs to be copied over to the remote machine in advance and will run against which ever account is logged on at the time of running.

The psexec command is run from you local PC against the remote PC.

Your way looks much less labour intensive polymath so I'll give it a test does it require knowing the remote users creds? assuming the remote user is a domain user.

Could you give me the laymans skinny on comspec /k

Thanks

Confuseis

Edited by confuseis
Link to comment
Share on other sites

@compsec is a way to run a dos prompt in the background which give more flexibility (for me anyways). Just as a suggestion if your replace

-u .\LocalPCaccountname -p LocalPCPassword

With

-s

It will run as the local system (which has admin permissions, most of the time) and you will not be passing any credentials.

Here is a link to @comspec

http://www.autoitscript.com/wiki/Snippets_%28_CMD_%29

Thanks,

Edited by grimmlock

Thanks

Grimm

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...