Jump to content

Recommended Posts

Posted

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?
Posted

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!

  Reveal hidden contents

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

Posted
  On 6/4/2019 at 9:29 PM, BrewManNH said:

Does the script run at all when runas the administrator?

Expand  

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

Posted

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!

  Reveal hidden contents

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

Posted
  On 6/5/2019 at 6:03 PM, 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.  

Expand  

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

Posted

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?

Posted
  On 6/6/2019 at 7:44 PM, 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.

Expand  

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

Posted (edited)

 

  On 6/6/2019 at 8:20 PM, Darien said:


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

Expand  

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!
Posted

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!

  Reveal hidden contents

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

Posted
  On 6/7/2019 at 1:15 PM, Davidowicza said:

 

Make sure the administraTor account is spelled correctly.

 

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

Expand  

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

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
  • Recently Browsing   0 members

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