Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Lock Windows Device


  • Please log in to reply
10 replies to this topic

#1 antmar904

antmar904

    Wayfarer

  • Active Members
  • Pip
  • 63 posts

Posted 25 February 2013 - 10:05 PM

hi all,

i am currently creating a gui has three buttons:

1) Lock
2) Hibernate
3) Shutdown

buttons 2 and 3 to work i just cant figure out how to lock windows.

any help would be much appreciated.







#2 DOTCOMmunications

DOTCOMmunications

    Seeker

  • Active Members
  • 43 posts

Posted 25 February 2013 - 10:24 PM

Hi

You should be able to call the following command but not sure how well it will work in AutoIT:

rundll32.exe user32.dll,LockWorkStation

Hope that helps

Adam

#3 wraithdu

wraithdu

    this noise inside my head

  • MVPs
  • 2,396 posts

Posted 25 February 2013 - 10:59 PM

rundll32.exe user32.dll,LockWorkStation

Yup. You can either use the Run() command with the above, or direct DllCall.
DllCall("user32.dll", "bool", "LockWorkStation")


#4 antmar904

antmar904

    Wayfarer

  • Active Members
  • Pip
  • 63 posts

Posted 26 February 2013 - 12:19 AM

thank you all for your quick response.

one more question.

i cant get a yes or no button to work when the user presses the shutdown button.

here is my code, i know that it can use some fine tuning but hey that's why i am here.

thank you all again.

Plain Text         
#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $formMain = GUICreate("Actions", 177, 122, -1, -1) $btnHibernate = GUICtrlCreateButton("Hibernate", 39, 16, 99, 25) $btnLock = GUICtrlCreateButton("Lock", 39, 48, 99, 25) $btnShutdown = GUICtrlCreateButton("Shutdown", 39, 80, 99, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Dim $Hibernate, $Lock, $Shutdown, $answer While 1 WEnd $nMsg = GUIGetMsg() Switch $nMsg   Case $GUI_EVENT_CLOSE    Exit   Case $btnHibernate    Shutdown (64)   Case $btnLock    DllCall("user32.dll", "int", "LockWorkStation")   Case $btnShutdown    $answer = MsgBox(4, "Message", "Are you sure you want to Shutdown your device?")    Switch $answer     Case 2     Else      Case 1      Shutdown (9)    EndSwitch EndSwitch WEnd


#5 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 10,022 posts

Posted 26 February 2013 - 12:32 AM

There are many errors with that code. First, you have an else in the middle of the second Switch statement that doesn't apply to anything so this script won't even run as is.
Second, you're not reading the buttons at all because you have the code for it after the While loop, so it's never run.
Third, look at the help file for what MsgBox returns when various buttons are pressed because your switch statements for the return from that aren't right.

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 an XP machine, 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!

 

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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips. Latin Square password generator

 

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.


#6 antmar904

antmar904

    Wayfarer

  • Active Members
  • Pip
  • 63 posts

Posted 26 February 2013 - 01:49 AM

after changing some things i still cant get it to work, now the gui just opens and then closes.

Plain Text         
#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $formMain = GUICreate("Actions", 177, 122, -1, -1) $btnHibernate = GUICtrlCreateButton("Hibernate", 39, 16, 99, 25) $btnLock = GUICtrlCreateButton("Lock", 39, 48, 99, 25) $btnShutdown = GUICtrlCreateButton("Shutdown", 39, 80, 99, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Dim $Hibernate, $Lock, $Shutdown, $answer $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnHibernate Shutdown (64) Case $btnLock DllCall("user32.dll", "int", "LockWorkStation") Case $btnShutdown $answer = MsgBox(4, "Message", "Are you sure you want to Shutdown your device?") Switch $answer Case 6      Shutdown(9) Case 7      MsgBox(0, "Message", "You pressed no") EndSwitch EndSwitch

Edited by antmar904, 26 February 2013 - 01:51 AM.


#7 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 10,022 posts

Posted 26 February 2013 - 02:06 AM

You removed the While loop, there's nothing to keep the script running. Wrap the section that checks the buttons inside a While loop, look at the help file for GUICreate and you'll see what I am referring to.

Also, try to avoid using the Dim keyword, you should use Global/Local instead.

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 an XP machine, 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!

 

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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips. Latin Square password generator

 

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.


#8 antmar904

antmar904

    Wayfarer

  • Active Members
  • Pip
  • 63 posts

Posted 26 February 2013 - 02:12 AM

I will def look into it.

Ill post my finding tmrw.

#9 antmar904

antmar904

    Wayfarer

  • Active Members
  • Pip
  • 63 posts

Posted 26 February 2013 - 05:09 PM

i think i got it working.

how does this look?

Plain Text         
#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $formMain = GUICreate("Actions", 177, 122, -1, -1) $btnHibernate = GUICtrlCreateButton("Hibernate", 39, 16, 99, 25) $btnLock = GUICtrlCreateButton("Lock", 39, 48, 99, 25) $btnShutdown = GUICtrlCreateButton("Shutdown", 39, 80, 99, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $Hibernate, $Lock, $Shutdown, $answer While 1 $nMsg = GUIGetMsg() Switch $nMsg   Case $GUI_EVENT_CLOSE    Exit   Case $btnHibernate    Shutdown (64)   Case $btnLock    DllCall("user32.dll", "int", "LockWorkStation")   Case $btnShutdown    $answer = MsgBox(4, "Message", "Are you sure you want to Shutdown your device?")    Switch $answer     Case 6      Shutdown(9)     Case 7    EndSwitch EndSwitch WEnd


#10 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 10,022 posts

Posted 26 February 2013 - 05:28 PM

Looks ok now, although the Case 7 isn't really needed unless you're planning on using it for something later. Other than that it works as it should.
  • antmar904 likes this

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 an XP machine, 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!

 

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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips. Latin Square password generator

 

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.


#11 antmar904

antmar904

    Wayfarer

  • Active Members
  • Pip
  • 63 posts

Posted 26 February 2013 - 05:49 PM

ill remove it thanks again :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users