Jump to content
Sign in to follow this  
Darien

Script Does Not Run as Administrator from the Network

Recommended Posts

Hi,

 

If I run the script below from the network on an ordinary user, it does not run the program as administrator (not displaying the "Ok" message):

 

If IsAdmin () Then
    MsgBox (0,"","ok")
Else
    RunAs  ( "administrator" , @ComputerName , "<administrator password>" , 0 , @ScriptName , @ScriptDir , @SW_HIDE )
EndIf

 

I have to copy the script to a non-network drive and run it from there to display the "Ok" message.
 
Is there any way around this?

Share this post


Link to post
Share on other sites

Does the script run at all when runas the administrator?


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

Share this post


Link to post
Share on other sites
18 hours ago, BrewManNH said:

Does the script run at all when runas the administrator?

Did you mean to right click on the script and choose to run as administrator?

In this case, it also does not display the "OK" message.

If I hold down the SHIFT key, right-click the script, choose to run as a different user and authenticate with the user "administrator", it says that the system can not find the specified drive (since a local account does not see a drive network).

 

To discard the possibility of not running the script as administrator because it does not see the network drive, I changed the script to:

 

If IsAdmin () Then
    MsgBox   (0,"","running with administrator right")
Else
    MsgBox   (0,"","running without administrator right")
    FileCopy ( @ScriptFullPath , "C:\TEMP\" & @ScriptName , 9 )
    RunAs    ( "administrador" , @ComputerName , $admin_password , 0 , @ScriptName , "C:\TEMP\" , @SW_HIDE )
EndIf

 

But the results are the same (only shows the message "running without administrator right"). Already if I run the script from "C: \ TEMP", it displays both "running without administrator right" and "running with administrator right" messages).

Share this post


Link to post
Share on other sites

Why don't you just use #RequireAdmin in the script and forget all this legerdemaine? If you're an admin, it will just run, if you're not it will ask for Admin credentials, and if you don't have them, won't run at all.

Putting the admin username and password in the script is generally a bad idea. 


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

Share this post


Link to post
Share on other sites
32 minutes ago, BrewManNH said:

Why don't you just use #RequireAdmin in the script and forget all this legerdemaine? If you're an admin, it will just run, if you're not it will ask for Admin credentials, and if you don't have them, won't run at all.

Putting the admin username and password in the script is generally a bad idea.  

This script is to be run by regular users to install certain programs that require administrator privileges.

Share this post


Link to post
Share on other sites

One other thing to consider: Does the local administrator account have network access? I know that on our network where I work, I can only run local files as a local admin.


Who lied and told you life would EVER be fair?

Share this post


Link to post
Share on other sites
34 minutes ago, benched42 said:

One other thing to consider: Does the local administrator account have network access? I know that on our network where I work, I can only run local files as a local admin.

With the last script I sent (below), it does not matter, because the script copies itself to the HD and then runs from there:

 

If IsAdmin () Then
    MsgBox   (0,"","running with administrator right")
Else
    MsgBox   (0,"","running without administrator right")
    FileCopy ( @ScriptFullPath , "C:\TEMP\" & @ScriptName , 9 )
    RunAs    ( "administrador" , @ComputerName , $admin_password , 0 , @ScriptName , "C:\TEMP\" , @SW_HIDE )
EndIf

Share this post


Link to post
Share on other sites

 

17 hours ago, Darien said:


    RunAs    ( "administrador" , @ComputerName , $admin_password , 0 , @ScriptName , "C:\TEMP\" , @SW_HIDE )
 

Make sure the administraTor account is spelled correctly.

 

Edit: Didn't know that was the spanish spelling, whoops. Thanks @BrewManNH

Edited by Davidowicza
Didn't know spanish!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
3 hours ago, Davidowicza said:

 

Make sure the administraTor account is spelled correctly.

 

Edit: Didn't know that was the spanish spelling, whoops. Thanks @BrewManNH

In my language (Portuguese) the account name is "administrador". I forgot to translate into English ("administrator") when I copied the script for this topic.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...