Jump to content
Sign in to follow this  
itye1970

runas command , run a windows command as administrator with parameters

Recommended Posts

itye1970

i need to run a program whilst a user is logged on who is not a local administartor.

I need to pass parameters to this program

EG : How can I run C:\Windows\System32\program.exe u  as local adminisatrator 

I need to compile the script as an .exe, note there are spaces in the above command also.

I have searched through help and looked at using cmdline but this doesnt work. If I run a program for example C:\Windows\System32\calc.exe with no arguments it runs fine but as soon as i want to pass argunments to the program it does not run

Many Thanks 

Edited by itye1970

Share this post


Link to post
Share on other sites
MikahS

Welcome to the Autoit Forums :bye:

Can you post your script so that we may have a look?


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
itye1970
Example()
 
Func Example()
    ; Change the username and password to the appropriate values for your system.
    Local $sUserName = "admin"
    Local $sPassword = "apassword"
 
 
 
   RunAs($sUserName, @ComputerName, $sPassword, 0, $iPID,  "C:\Windows\System32\bitlockerwizardelev.exe u", @SW_SHOWMAXIMIZED)
 
    
    WinWait("[CLASS:Notepad]", "", 10)
 
    ; Wait for 2 seconds.
    Sleep(20000)
 
 
    ;ProcessClose($iPID)
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites
itye1970

sorry is this one

Example()
 
Func Example()
    ; Change the username and password to the appropriate values for your system.
    Local $sUserName = "admin"
    Local $sPassword = "anypassword"
 
    
    Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 0, "bitlockerwizard.elev u", "", @SW_SHOWMAXIMIZED)
 
    ; Wait 10 seconds for the Notepad window to appear.
    WinWait("[CLASS:Notepad]", "", 10)
 
    ; Wait for 2 seconds.
    Sleep(2000)
 
    
    ProcessClose($iPID)
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites
Jos

try:

Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 0, 'bitlockerwizard.elev "\ u"', "", @SW_SHOWMAXIMIZED)

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
itye1970

:-( still no luck. If i go to windows command prompt and type in C:\Windows\System32\bitlockerwizardelev.exe u , it works fine but still not working with autoit

Example()
 
Func Example()
    ; Change the username and password to the appropriate values for your system.
    Local $sUserName = "123"
    Local $sPassword = "123"
 
    ; Run Notepad with the window maximized. Notepad is run under the user previously specified.
    ;Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 0, "calc.exe", "", @SW_SHOWMAXIMIZED)
Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 0, 'bitlockerwizard.elev " u"', "", @SW_SHOWMAXIMIZED)
    ; Wait 10 seconds for the Notepad window to appear.
    WinWait("[CLASS:Notepad]", "", 10)
 
    ; Wait for 2 seconds.
    Sleep(2000)
 
    ; Close the Notepad process using the PID returned by RunAs.
    ProcessClose($iPID)
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites
MikahS

Example()
 
Func Example()
    ; Change the username and password to the appropriate values for your system.
    Local $sUserName = "admin"
    Local $sPassword = "anypassword"
 
    
    Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 0,'bitlockerwizard.elev "\ u"', "", @SW_SHOWMAXIMIZED)
 
    sleep(2000)    

    ProcessClose($iPID)
EndFunc   ;==>Example

EDIT: Didn't see Jos' reply, this is the same thing :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
MikahS

slow down, it seems you are throwing things at the problem, which will not help. Give a try to the script provided in my post #7 and tell us if it works or not :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
Jos

 

:-( still no luck. If i go to windows command prompt and type in C:\Windows\System32\bitlockerwizardelev.exe u , it works fine but still not working with autoit

 

 

Why is the no space in this line in u and in your script you have a space?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
MikahS

Why is the no space in this line in u and in your script you have a space?

Jos

This could be why your script is not working :P


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
itye1970

sorry its odd i know but it needs the space, the command from the windows prompt is

c:windowssystem32bitlockerwizardelev.exe u

Its the bitlocker reset password screen, for some reason microsoft decided to have a space in this command

the space needs to be there , otherwise it wont work.

Edited by itye1970

Share this post


Link to post
Share on other sites
MikahS

Alright, so did you give the script provided in post #7 a try? If so, what were the results?


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
Jos

sorry its odd i know but it needs the space, the command from the windows prompt is

c:windowssystem32bitlockerwizardelev.exe u

Its the bitlocker reset password screen, for some reason microsoft decided to have a space in this command

the space needs to be there , otherwise it wont work.

Ok, then the next question: Why is the programname different in the script?

So you want:

Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 0, 'bitlockerwizardelev.exe "\ u"', "", @SW_SHOWMAXIMIZED)

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
itye1970

i tried post 7 and nothing happens.

there was a typing mistake earlier the command does need a space

it should be 

bitlockerwizardelev.exe u

this is in the windowssystem32 directory

Share this post


Link to post
Share on other sites
MikahS

Replace the line in your script with Jos' from post #13


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
itye1970

did that but nothing appears

Example()
 
Func Example()
    ; Change the username and password to the appropriate values for your system.
    Local $sUserName = "username"
    Local $sPassword = "password"
 
 
    Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 0, 'bitlockerwizardelev.exe " u"', "", @SW_SHOWMAXIMIZED)
 
    sleep(2000)
 
    ProcessClose($iPID)
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites
Jos

Try this so the CMD window stays open and remove the Processclose()

Local $iPID = RunAs($sUserName, @ComputerName, $sPassword, 0, @comspec & ' /k bitlockerwizardelev.exe "\ u"', "", @SW_SHOWMAXIMIZED)

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
itye1970

 ok now it opens a command window with the cursor at C:\Windows\System32\  and nothing happens

Share this post


Link to post
Share on other sites
Muzaiyan

did you try that

#RequireAdmin

direct from example

#include <MsgBoxConstants.au3>

#RequireAdmin

If IsAdmin() Then MsgBox($MB_SYSTEMMODAL, "", "The script is running with admin rights.")

build .exe of your program and run your C:windowssystem32????? with u parameter or what ever.

Share this post


Link to post
Share on other sites
Muzaiyan

try also

_RunDos()

direct from example:

#include <Process.au3>

Local $rc = _RunDos("start Http://www.autoitscript.com")

run your program on DOS prompt

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  

×