Sign in to follow this  
Followers 0
maxwellsmart

Attempting To Run V3 Script While Pc Locked

5 posts in this topic

I have a script (to install a piece of software) which works fine while logged in as a user with Administrator priviledges. The same script doesn't work when that user has locked (not logged off) the PC. AutoIT acts as though it doesn't 'see' the initial setup window and the script pauses. Unlocking the PC doesn't cause the script to continue. Other scripts designed to install software have worked while the PC is locked.

Any ideas as to why this is occuring?

Thanks!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

this is an example on how you can restart the script in Admin mode.

You need to compile it first for it to work...

AutoItSetOption ( "RunErrorsFatal", 0) 
AutoItSetOption ( "TrayIconHide", 1) 
; variable definition
$username="?????"                  ; local admin account name
$Password="????????"              ; local admin account psw
$run = 0                          ; run indicator 1=first cycle uninstall   2=install new
; retrieve commandline parameter
If $CmdLine[0] = 1 then $run = $CmdLine[1]
; 
If $run = 0 then
   if isadmin() then
      Writelog("Already admin mode skipping to setp 2")
      $run = 1
   else
    ; *** Changing credentials..
    RunAsSet ($Username, @Computername, $Password)
    ; start the script program (itself) again but now in Adminmode...so all done tasks will run in Adminmode
      Run('"' & @ScriptFullPath & '" " 1"' ) 
  ; if fails then exits because username & passsword is not correct
      if @error = 1 then
         msgbox(48,"Error","cannot start the installation because you are not in Admin mode ")    
         exit
      endif
      exit
   endif
EndIf
; do the stuff you need to do in admin mode
Edited by JdeB

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

Share this post


Link to post
Share on other sites

Thanks for the response but the user is already a member of the Admin group. The script works when the user is logged in but doesn't when that same user locks the PC (I assume the user is still logged on but the PC is simply locked). Perhaps locking the PC disables keyboard input (except for Ctrl-Alt-Del for unlocking purposes) and therefore scripts cannot send keyboard commands successfully?

Share this post


Link to post
Share on other sites

You are correct, keystrokes are limited to CTRL-ALT-DEL when locked, also if your script relies on sending mouse clicks to active windows it cannot work as a locked PC does not open windows "behind the scene".

One way around the problem could be to:

1. Create a script that sets AutoAdminLogon, Username and Password and that puts an entry in the HKLM\soft\Mic\Win\CV\RunOnce as to execute the third script upon reboot and forces a reboot.

2. Create the script to install the software and include the removal of AutoAdminLogon and reboot.

Script 1.

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon", "REG_SZ", "1")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName", "REG_SZ", "USERNAME")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", "REG_SZ", "PASSWORD")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomainName", "REG_SZ", "DOMAIN")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce", "MYSCRIPT", "REG_SZ", "PATH\SCRIPTNAME")

Shutdown(6)

Don't forget to reset Autoadminlogon to "0" as part of the install script.

Cheers


CheersNobby

Share this post


Link to post
Share on other sites

Turns out I can use the ControlSend function to have the script run successfully when the user is logged in but has locked the PC.

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  
Followers 0