Jump to content

mapped network drives & admin rights


Recommended Posts

Hi,

I just want to report some kind of bug. Not really AutoIt but a strange combination with windows.

I tried to do some regwrite and ordered #require admin for my script. But the key simply doesnt appear in the registry.

I nearly lost all hope playing around with any combinations of regwrite, runas, shellexecute for an hour then I realised:

The scrip doesnt even run :)

Why?

My windows was reinstalled and I only mapped my networkdrives as standard user. Programs with admin rights cannot access those drives by default.

The script itself was stored on this network drive so the autoitWrapper couldnt access it.

My recommedation:

A small error message to the command window "Script not found" would have helped me a lot.

To me it seemed all the time as if the script was executed properly.

best regards

Blues

Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

Checking for any error conditions when the script is run would have told you that it couldn't open the script. You've learned a valuable lesson about checking for errors and not making assumptions that the code works all the time.

Although, I have no idea what AutoIt3Wrapper has to do with this, because it's not used after the script is compiled, and wouldn't have tried to access the other file if running in SciTE.

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

 

The scrip doesnt even run :)

.

.

.

A small error message to the command window "Script not found" would have helped me a lot.

To me it seemed all the time as if the script was executed properly.

 

beside of upvoting BrewManNH on error-checking and lesson-learning, your suggestion makes no sense: you'll never see an error message saying "hi, this is your script speaking, i did not execute.".

P.S it is both intended and well known, that mapped drives are user-specific. no bug there. hope you'll check yourself better for other issues, like UAC and permissions, etc.

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 have no idea what AutoIt3Wrapper has to do with this, because it's not used after the script is compiled

 

The scrip will not be compiled. I thought non-compiled scripts will get interpreted by this wrapper ( I am relativly new to autoIt ). 

And so when the wrapper gets elevated, it looses contact to the script ( if network drive is  not shared ).

I just proposed that the interpreter could throw a small error about that instead of just printing "Exit Code = 0" as any other working script does.

Not more and not less. No offend to autoIt itself. And if error messages are so important is I just learned from BrewManNH then this would also be a usefull one or am I wrong?

best regards

Blues

 

@orb: I guess 90% of any error causes are well known in the end, but an error message is always helpfull  :)

Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

If you compiled a script, and used that to run a second script, then AutoIt3Wrapper isn't used because it's not available for use in a compiled script.

You should check inside your main script for error conditions, the Run command for instance returns an error code if it can't find/run the program you're trying to run with it. So, you have your error message, you just didn't plan for the errors in your code. Every included function of AutoIt returns an error code if it doesn't work, or gets wrong input, which is why you should be checking, at the very least, the @error condition after trying to use one of the functions.

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

If you compiled a script, and used that to run a second script...

 

I think you missunderstood me. Its a normal script interpreted by the autoitWrapper.  And I guess #requireAdmin elevates  autoitWrapper.exe to adminrights.

But with adminrights the autoitWrapper.exe cannot access the network anymore and so it cannot access the script anymore ( which is  stored on this network drive )

This was it I wished the  autoitWrapper.exe would have told me. @error-checking is common sense but I was a bit lazzy at that moment :)

I tried to use runas for regedit.exe in the script maybe that caused the missunderstanding. I hope I expressed better now. For me the problem is solved, I just wanted provide some feedback to improve autoit

(or not if the problem is too specific)

regards

Blues

Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

The wrapper is only used when compiling or running from SciTE. If you are running one script from SciTE that uses #RequireAdmin to run another script, then the second script isn't running from Scite, but from your script so no wrapper and no error messages from it. Also, using #RequireAdmin will cause your first script to end and rerun itself using admin credentials so once again, no wrapper at that point.

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

Hello BrewManNH,

Sorry for expressing my self so unclear but: There is no second script!

I open one and only one script in scite. I press F5 it runs. Thats it.

When I modify it with #RequireAdmin and press F5 it seems to run, I get an exit code 0 but...nothing happened.

Because the autoitWrapper.exe gets the admin rights ( the script itself is no process and cant get any rights ).

And again: the moment autoitWrapper.exe gets the admin rights, it looses contact to the script ( stored on  the network drive )

This is not a big deal. It just would be nice from the autoitWrapper.exe e to tell the user: "Cannot access the script" instead of suggesting a propper run.

But all in all: This is not such a big problem for loosing 1000 words about it. I just wanted to notify it shortly.

regards

Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

As I stated in the last line of my latest post, when you use #RequireAdmin the running script stops and reruns itself under admin credentials, the wrapper isn't used at that point, so you need to get the idea out of your head that it matters at this point.

The only thing running is AutoIt3.exe (or 64 bit version of it) and it is running your script. The wrapper will continue to run for a couple of seconds after the script reruns, but it's not interacting with the script at that point. Because it's not running, all error checking would need to be done in your script, and you shouldn't be relying on anything else to do it for you. That's all I'm trying to say.

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

Bit late, but to add or express different to what BrewmanNH is saying,

AutoIt3Wrapper does not get admin rights if you use #RequireAdmin in a script. AutoIt3Wrapper runs AutoIt3 to run your script, AutoIt3 sees #RequireAdmin and does a restart to elevate to admin. The makes AutoIt3Wrapper loose connection with the script as the launched process has ended on the restart and AutoIt3 has start a second elevated process. AutoIt3Wrapper can not alert you of "cannot access the script" as everything went fine as far as it knows.

If you want AutoIt3Wrapper to keep the connection to the script process then try starting Scite as admin so the elevation is inherited throughout the use of Scite and any spawned processes created by the tools launched by Scite.

Link to comment
Share on other sites

Good evening MHz and BrewManNh,

Ok I think I understood. I never thought very deep about the relationship between the wrapper and the interpreter. Thank you both for your patient explanations.

So in the end its:  scite > wrapper > interpreter > interpreter ends > wrapper ends and reports to console > interpreter restart elevated > interpreter couldnt access script

 

So far. But would it really be a bad idea if the interpreter popup a small msgbox  "script not found"?

I mean there could be other reasons like access policies or whatever. The current procedure is a bit confusing especialy for new users ( like me :P )

regards

Blues

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

Good evening Bluesmaster,

Have you ever seen a MsgBox shown from AutoIt3 while running a script through Scite? I expect a no unless you changed the configuration to allow it. If you look at Command Line Parameters in the help file then you may noticed a parameter known as /ErrorStdOut. This parameter is used to run scripts through Scite so you see the output in the console pane at the bottom of the editor. So if an error is to be seen then it will show in the console. Since you were running your script through scite and then automatically restarting as admin which broke the connection to the editor, then the error message could not be seen. This is no fault in Scite or in AutoIt3, but how it works and how you chose to work it.

A quick test at a cmd prompt with a file not existing for AutoIt3 to run

>AutoIt3.exe DoesNotExist.au3

I get a MsgBox with an error

---------------------------
AutoIt Error
---------------------------
Line 0  (File "C:\Programs\AutoIt3\DoesNotExist.au3"):

Error: Error opening the file.
---------------------------
OK   
---------------------------

There is your MsgBox that you wanted to see.

Now, try the /ErrorStdOut parameter so the error goes to the StdOut stream

>AutoIt3.exe /errorstdout DoesNotExist.au3 | more

I had to pipe to more as the cmd prompt is not as greedy as the scite console pane.

I get a return

C:\Programs\AutoIt3\DoesNotExist.au3 (0) : ==> Error opening the file.:

So that may be the error message you would see in the Scite output pane if you had ran Scite as admin as your script restarted as admin. If you tested the script without Scite then you may have expected the MsgBox with the error.

So from now on, you may need run scripts in different ways, to see why they may not run as expected. As you claim as being a new user, then it is upon you to learn and I hope this is a good lesson for you. :)

Link to comment
Share on other sites

It is a good lesson indeed and I am new to autoit. But I am not new to programming itself. And as a programmer I would continue arguing:

If I get a error-msg-box if the script is not found on a normal script execution it would just be consistent in the situation I described.

Run this script...

#RequireAdmin
MsgBox( 0 , "" , "" )

...and in the moment the UAC-Call appears: just delete it ( as an example for any timedelay- or user related access change ) and then confirm the UAC.

Nothing happens.

Imagine the following situation: You are an administrator at a company and create a script for the employes to backup some files in network after they finished work.

They finish work > click the script > get UAC prompt click ok > continue work fast as they have a lot of work to do (they dont really understand what the script does ) > after some months a harddisk crashes  > they search for the backups > And it turns out they are no backups as this user forgot to map his network drives

as shared drives ( which is a registry change for exerienced users )

You could argue: The user should have checked the backups from time to time but we all know:

- users will never act rational :)

- a good automation tool should always inform the user about ANY thing that might have gone wrong

Of course I described some kind of worst case, but as an experienced programmer I also know such cases happen more often than we can imagine,

So the question is:

Are there serious reasons agains a second check if the script exists when the interpreter restarts elevated (rather than just assuming)?

So I think, I have described my point of view. You as developers and MVPs know best about any technical backgrounds and can decide better than me

if it is a relevant point or not.

best regards

Blues

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

So people in a company are going to run a script in a programming editor with #RequireAdmin in the script as a backup script. That is not an wise at all. What if one of the employees deletes all the code in the script and saves the file. This example is just insane.

As your claim as an experienced programmer then you should understand how UAC works. You said you were a new user but it seems you are changing your position as your complaints change. If one complaint fails, change and the try another. You have repeatedly ignored advice given in the thread. AFAIK, your issues have been debunked. I am guessing that your script is not explicit in mapping the network drive and thus causing failure. If so, that is a flaw in your script. Look it up at MSDN about mapped drives and they will mention it like this blog. I would try and find a better page about it but I notice a lot of the C++ pages are being removed of late and I am not going to put time in searching at present.

As for 2nd check, this is about running the script only in the editor? So why are you not running Scite as admin and then running the script for testing? Run the scripts outside the editor for production usage. As I mentioned before, /ErrorStdOut stopped you seeing the MsgBox on the restart so a 2nd check was there, just you did not see it show.

AutoIt3Wrapper could check for the presence of #RequireAdmin and write a message to console alerting the user if not admin if it does not do it already. Take that up with the Scite4AutoIt3 thread in the Dev Chat forum if interested.

I may sound frustrated and I guess I am some while writing this. I do not set the rules that the OS sets, I just follow the rules set (regarding UAC, mapped drives, etc). You may find UNC paths as more reliable to use in scripts. This is all part of the learning process. I have been going through the learning process as well, perhaps a bit bruised now with the experience of it all. -_-

Link to comment
Share on other sites

I may sound frustrated and I guess I am some while writing this

 

Well I did not forced you to answer. But "debunked" and "changing your position as your complaints change" is a bit offending and not very constructive.

I did not even ask for help, I just gave an example how I discovered "the problem" . Instead of teaching me about OS basics why not focus on the basic issue I try to advert:

AutoIt.exe makes the assumption that it has the same access rights to the script it should run as user as it has as admin. This assumption simply cannot be made.

The script will not run without any feedback. And this can cause trouble. And this is not a question of error-checking as not only programmers are involved but users too.

 

PS:

My example is not "insane", I am an engineer in bigger company and all the employes execute scripts ( compiled ones, *.bat and others) for different purposes ( nobody said something about an editor )

and yes some of them require admin-rights as we tend to trust our adminstrators. So please be a bit more reflected with such judgements.

Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

Anyone that knows Windows should know that when you use different credentials to run a program that you'll lose connections to the mapped drives and printers of the current user. If I open, for example, Notepad as a different user on Windows 7, I can't see the mapped drives I have for my regular user account any longer.

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

  • Anyone knows that regwrite( "testest" ) will cause an error in autoIt                                           >> But there is a feedback for that ( @error )
  • If I open notepad elevated and try to open a file on a non-mapped drive                                   >> I get a feedback ( dont see drives )
  • If I run an autoIt-script ( double-click ) on a non-shared network drive, that needs adminrights  >> I think it has run but it didnt, without any feedback

 

But at some point I agree with MHz: it starts getting a discussion for the discussion itself. I accept that it is not that important and that the users/ coders should take care of this problem themselfs.

regards

My UDF: [topic='156155']_shellExecuteHidden[/topic]

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