majorstevie Posted November 8, 2010 Share Posted November 8, 2010 Hi there, I have a script that I use to map a network drive, and then run an exe off the remote share. I am using Windows 7 with UAC turned on. What I need to do is map the drive as myself, so that I can browse the share from time to time, but run the exe as admin. If I run the whole script as admin, I don't get to see the mapped drive (because it has been mapped for the administrator!). Any ideas how I can do this? What I have currently got works partially, the drive gets mapped and I can browse it, and the remote exe runs. But you can see that the script runs twice, which is not ideal, plus I wish to compile it so I need it all in the one script. Here is my script so far: expandcollapse popup; Disconnect drives if already connected DriveMapDel("X:") ;Disconnect the connection if it is not mapped to a drive DriveMapDel("\\server\express") ;Map Y: drive to \\server\express DriveMapAdd("X:", "\\server\express", 0, "admin", "password") Select Case @error = 0 MsgBox(48,"Success", "Drive(s) successfully mapped", 2) Case @error = 1 MsgBox(48,"Error", "Drive(s) not mapped" & @LF & "Undefined error", 2) Case @error = 2 MsgBox(48,"Error", "Access to the remote share was denied", 2) Case @error = 3 MsgBox(48,"Error", "The device is already assigned", 2) Case @error = 4 MsgBox(48,"Error", "Invalid device name", 2) Case @error = 5 MsgBox(48,"Error", "Invalid remote share", 2) Case @error = 6 MsgBox(48,"Error", "Invalid password", 2) EndSelect Main() Func Main() If Not IsAdmin() Then ShellExecute(@AutoItExe, '"' & @ScriptFullPath & '"', "", "runas") EndIf Run ("X:\eXpress.exe") WinWaitActive ("Altiris Deployment Server", "") ControlSend ("Altiris Deployment Server", "", "[CLASS:Edit; INSTANCE:1]", "user") ControlSend("Altiris Deployment Server", "", "[CLASS:Edit; INSTANCE:2]", "password") ControlClick("Altiris Deployment Server", "", "[CLASS:Button; INSTANCE:1]") EndFunc ;==>Main Link to comment Share on other sites More sharing options...
enaiman Posted November 8, 2010 Share Posted November 8, 2010 I've read your post several times and I'm still confused ... map the drive as myself, so that I can browse the share from time to time, but run the exe as adminIf I run the whole script as admin, I don't get to see the mapped drive (because it has been mapped for the administrator!) That is pretty confusing to me. What is preventing you to map the drive and execute the exe as admin? - once you compile the script you can chose "RunAs" from the right-click menu on the executable itself. You don't need any of this: If Not IsAdmin() Then ShellExecute(@AutoItExe, '"' & @ScriptFullPath & '"', "", "runas") EndIf SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
majorstevie Posted November 8, 2010 Author Share Posted November 8, 2010 I had tried to just run the script as admin, as you say, compile and choose run as administrator (without the ShellExecute section). The remote exe will run, but I can't browse the mapped drive becuase it isn't mapped for me, it is mapped as admin. No drive letter, and if I enter the UNC path, I am challenged for credentials, which is what I was trying to say in my post. I need the remote exe to run as admin, and I need the share to be mapped in my own user context. Link to comment Share on other sites More sharing options...
enaiman Posted November 9, 2010 Share Posted November 9, 2010 DriveMapAdd("X:", "\\server\express", 0, "admin", "password")You should use your credentials here. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
majorstevie Posted November 9, 2010 Author Share Posted November 9, 2010 Hmm, yes I see what you are getting at there, but unfortunately this server is on another domain, so I need to use another domain account to map that share. Just to complicate things a bit more! Link to comment Share on other sites More sharing options...
enaiman Posted November 9, 2010 Share Posted November 9, 2010 Try to use "domain\username" SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
majorstevie Posted November 9, 2010 Author Share Posted November 9, 2010 No, I got that bit, the problem is if I run the script as an administrator I am not mapping drives in MY user context, I am mapping them in the administrator's user context. I thought in your previous post you were saying to map the drives with my credentials to get the drives mapped in my user context, even though I am running the whole script as admin. I think that would work, if my logged on credentials could be used to map the drive on the other domain. So what happens is this, if I don't run the script as admin, I get the drive mapped in my context and I can browse the share, BUT, the remote exe will not run as it has to run as admin. If I run the script as admin, the remote exe will run and the drive will get mapped but the mapped drive will not show up in my user context because it has been mapped for the administrator, not me! Link to comment Share on other sites More sharing options...
enaiman Posted November 9, 2010 Share Posted November 9, 2010 Get the drive mapped for you and use RunAs for "eXpress.exe" with admin credentials. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
majorstevie Posted November 9, 2010 Author Share Posted November 9, 2010 Hi again, thanks for your help and patience with this. I tried that as well. The problem is the exe then needs a username and password and it seems if I do a runas for the remote exe, the window sits and waits, again I guess, due to it running in the admin context and the CONTROLSEND commands are not running in the admin context. This is just my guess, but when I try it everything works well, drive is mapped for me, I get a UAC prompt, click yes, then the remote exe runs, then sits there waiting for username and password, and the script pauses. Is there a way to run the final commands as admin? I did wonder about just having two scripts and running the second part of the script using #RequireAdmin, but I wanted to wrap it all up into a single compiled exe. Link to comment Share on other sites More sharing options...
enaiman Posted November 9, 2010 Share Posted November 9, 2010 You can do something smart Use an USB key with an autorun - you can set that an executable to be automatically run on connect; that one will map the drive. All you have to do next is to run your second part. You can have 2 executables this way but run only one Well - this is only a work-around, it is not a solution to your problem but an alternative. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
majorstevie Posted December 20, 2010 Author Share Posted December 20, 2010 Got the script to work by scrapping all the AutoIt #RequireAdmin palaver and just running the exe as admin. Used a regedit I found somewhere else that allows the admin and the logged in user to both see each other's mapped drives. Works a treat! Regedit: To resolve this problem, please try to configure the EnableLinkedConnections registry value: 1. Click Start, type regedit in the Start Search box, and then press ENTER. 2. Locate and then right-click the following registry subkey: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System 3. Point to New, and then click DWORD Value. 4. Type EnableLinkedConnections, and then press ENTER. 5. Right-click EnableLinkedConnections, and then click Modify. 6. In the Value data box, type 1, and then click OK. 7. Exit Registry Editor, and then restart the computer. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now