Jump to content

Mapping X: drive using a button


Recommended Posts

Hey there, I am brand new to the forum. I have done some significant searching to see if anyone can re-create my particular issue.

What I have scripted in AutoIT is a program that points to a slew of .CMD files to launch application installs. What is happening sometimes is that the X: drive mapping does not always work if the support specialist navigates to the server where the AutoIT application is hosted. Seems that if Windows explorer is already navigated to the same location, it will not map a drive to that location. A button would be the perfect solution.

What I am trying to accomplish is creating a button that maps the X: drive to the server using a RunAs command to run as the local Administrator (the work around is the right click the app and Run As admin). These are my attempts so far:

As the application is launched, not always working:

DriveMapAdd("X:", "\\Server\Store", 0, "Domain\UserName", "password")

SplashTextOn("Software Installer", "POST RIS Software Installer.", 350, 30, 200, 200, 0, "", 12)

Button to be launched:

;$MapDrive = GUICtrlCreateButton("Map Drive", 340, 392, 73, 33, 0)

;GUICtrlSetFont(-1, 8.5, 800, 0, "MS Sans Serif")

;GUICtrlSetColor(-1, 0x000080)

This is in my While 1 script:

;Case $MapDrive

;MapDrive()

This is the function that is not working properly (have also tried RunAsSet):

;Func MapDrive()

;RUNAS("Administrator", "%COMPUTERNAME%", "%COMPUTERNAME%12345", 0,

;DriveMapAdd("X:", "\\Server\Store")

;EndFunc

Additionally, our local administrator password is a numbering convention after the computer name. How is that scripted?

Any and all help would be much appreciated, thank you!

Edited by ibanezfreak4
Link to comment
Share on other sites

That environment variable is only going to expand if you have Opt("ExpandEnvStrings", 1).

Just use the AutoIt macro instead. Use RunAsWait() so you can get the return code. Also, you can't pass RunAs() an AutoIt function, so use NET USE:

$iRET = RunAsWait("Administrator", @ComputerName, @ComputerName & "12345", 0, "NET USE X: \\Server\Store")

:D

P.S. Technically, you can run a native AutoIt function with this (see help file):

AutoIt3.exe [/ErrorStdOut] /AutoIt3ExecuteLine "command line"

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

As the application is launched, not always working:

DriveMapAdd("X:", "\\Server\Store", 0, "Domain\UserName", "password")

SplashTextOn("Software Installer", "POST RIS Software Installer.", 350, 30, 200, 200, 0, "", 12)

This is the function that is not working properly (have also tried RunAsSet):

;Func MapDrive()

;RUNAS("Administrator", "%COMPUTERNAME%", "%COMPUTERNAME%12345", 0,

;DriveMapAdd("X:", "\\Server\Store", "Domain\UserName", "password")

;EndFunc

I may be wrong, but I think to fix your current function you would have to script it like this:

Func MapDrive()
DriveMapAdd("X:", "\\Server\Store", 0, "Domain\UserName", "password")
RunAs("Administrator", %COMPUTERNAME%, %COMPUTERNAME% & "12345", 0, "your_program_location")
EndFunc

Then, eliminate the DriveMapAdd at the beginning of your script, because once you click the Map Drive button on your GUI, it will map the drive for you then. Also, make sure that you remove your semi-colons as well that are before each line, otherwise the compiler will skip those lines all together,

As for your numbering convention for your password, I am not sure exactly what you mean.

Spoiler

 

"...Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like.My crime is that of outsmarting you, something that you will never forgive me for." --The Mentor

"Mess with the best, die like the rest!!" -Hackers

"This above all to thine own self be true." -William Shakespeare

"Corruption is only as corrupted as the individual makes it out to be." -i386

 

style7,AutoIt.png

 

 

Link to comment
Share on other sites

I may be wrong, but I think to fix your current function you would have to script it like this:

Func MapDrive()
DriveMapAdd("X:", "\\Server\Store", 0, "Domain\UserName", "password")
RunAs("Administrator", %COMPUTERNAME%, %COMPUTERNAME% & "12345", 0, "your_program_location")
EndFunc

Then, eliminate the DriveMapAdd at the beginning of your script, because once you click the Map Drive button on your GUI, it will map the drive for you then. Also, make sure that you remove your semi-colons as well that are before each line, otherwise the compiler will skip those lines all together,

As for your numbering convention for your password, I am not sure exactly what you mean.

Thanks for the replies, I will give these a try.

The numbering convention is the name of the machine PLUS 12345. So if your PC name was AUTOIT the local admin password would be AUTOIT12345.

Thanks again.

Link to comment
Share on other sites

The numbering convention is the name of the machine PLUS 12345. So if your PC name was AUTOIT the local admin password would be AUTOIT12345.

You know that's a phenomenally BAD idea, right...?

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

That environment variable is only going to expand if you have Opt("ExpandEnvStrings", 1).

Just use the AutoIt macro instead. Use RunAsWait() so you can get the return code. Also, you can't pass RunAs() an AutoIt function, so use NET USE:

$iRET = RunAsWait("Administrator", @ComputerName, @ComputerName & "12345", 0, "NET USE X: \\Server\Store")

:D

P.S. Technically, you can run a native AutoIt function with this (see help file):

AutoIt3.exe [/ErrorStdOut] /AutoIt3ExecuteLine "command line"

I tried this approach to map through NET USE, but it prompts for a user name for the server? Attached picture.

Posted Image

Should it be scripted a little differently?

Edited by ibanezfreak4
Link to comment
Share on other sites

Try adding the credentials to the NET USE command line:

$iRET = RunAsWait("Administrator", @ComputerName, @ComputerName & "12345", 0, "NET USE X: \\Server\Store " & @ComputerName & "12345 /u:" & @ComputerName & "\Administrator")

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

That "partially" worked. I didn't necessarily read into what the error was actually giving me...

I don't think this button is going to perform what we need it to. What I really need is for the entire application to re-launch and be "RunAs". This sounds like it is too complex to complete.

Maybe I have this button prompt the support specialist for their ID and PW? Is that possible with a RunAsWait? Or is that another function?

Thanks.

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...