Bert Posted April 6, 2006 Share Posted April 6, 2006 Your running Windows XP You have 2 people who have user accounts on the PC Both are logged in on the PC, and you can switch back and forth between them. Question: How can you tell who is currrently the active user? I have a script that will change the resolution of the screen. The problem is my wife likes one resolution, and I like a different resolution. Currently, I just click on the exe on the desktop. I like to have it so when we switch between users, it will change resolution on the fly. This is the code for changing the resolution. I didn't write this, but it is good code CODEDisplayChangeRes(1280, 1024, 32, 75) Func DisplayChangeRes($WIDTH, $HEIGHT, $BPP, $FREQ) $DM_PELSWIDTH = 0x00080000 $DM_PELSHEIGHT = 0x00100000 $DM_BITSPERPEL = 0x00040000 $DM_DISPLAYFREQUENCY = 0x00400000 $CDS_TEST = 0x00000002 $CDS_UPDATEREGISTRY = 0x00000001 $DISP_CHANGE_RESTART = 1 $DISP_CHANGE_SUCCESSFUL = 0 $HWND_BROADCAST = 0xffff $WM_DISPLAYCHANGE = 0x007E $DEVMODE = DLLStructCreate ("byte[32];int[10];byte[32];int[6]") $B = DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DLLStructGetPtr ($DEVMODE)) If @error Then $B = 0 Else $B = $B[0] EndIf If $B <> 0 Then DllStructSetData ($DEVMODE, 2, BitOR($DM_PELSWIDTH, $DM_PELSHEIGHT, $DM_BITSPERPEL, $DM_DISPLAYFREQUENCY), 5) DllStructSetData ($DEVMODE, 4, $WIDTH, 2) DllStructSetData ($DEVMODE, 4, $HEIGHT, 3) DllStructSetData ($DEVMODE, 4, $BPP, 1) DllStructSetData ($DEVMODE, 4, $FREQ, 5) $B = DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DLLStructGetPtr ($DEVMODE), "int", $CDS_TEST) If @error Then $B = -1 Else $B = $B[0] EndIf Select Case $B = $DISP_CHANGE_RESTART $DEVMODE = "" Return 2 Case $B = $DISP_CHANGE_SUCCESSFUL DllCall("user32.dll", "int", "ChangeDisplaySettings", "ptr", DLLStructGetPtr ($DEVMODE), "int", $CDS_UPDATEREGISTRY) DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_DISPLAYCHANGE, _ "int", $BPP, "int", $HEIGHT * 2 ^ 16 + $WIDTH) $DEVMODE = "" Return 1 Case Else $DEVMODE = "" Return $B EndSelect EndIf EndFunc ;==>DisplayChangeRes The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
nfwu Posted April 6, 2006 Share Posted April 6, 2006 Errm... use @UserName? #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Infinitex0 Posted April 6, 2006 Share Posted April 6, 2006 D@/\/\N. I actually knew the answer to this one. The below statement is False.The above statement is True.a lesson I learned from Greenmachine; give a man a code and he'll solve one problem. Teach a man to code and he'll solve all his problems.P.S please don't use autoIt as a virus creator/spyware maker(keyLogger especially)Cick this and help me[center]My Scripts:[/center][center]Port Scanner[/center] Link to comment Share on other sites More sharing options...
Bert Posted April 6, 2006 Author Share Posted April 6, 2006 I should have put this question a different way. (I haven't had my morning coffee yet) I could use @UserName to see who is active, but how would one make a script run when the switch is made? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
nfwu Posted April 6, 2006 Share Posted April 6, 2006 Have a script that is something like this: while 1 $title = WinGetTitle("") while $title == WinGetTitle("") Sleep(1000) wend If /*Resolution is not appropriate for this user*/ Then ;;Change the resolution EndIf wend If the active window changes, then the script assumes that the current user is active. The script will then change the resolution if it is not the appropriate resolution. #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Bert Posted April 6, 2006 Author Share Posted April 6, 2006 I would need it to run as a service. I found that microsoft's srvany.exe may help in this aspect. Also, I would need to get the resolution of the screen. I know user32.dll can do this, but not sure how. Your on the right track in making a simple check to see who is logged on and check every so often to see what the resolution is. Does anyone know how to check the resolution using user32.dll? I googled it, and not having much luck. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
MHz Posted April 6, 2006 Share Posted April 6, 2006 I would need it to run as a service. I found that microsoft's srvany.exe may help in this aspect. Also, I would need to get the resolution of the screen. I know user32.dll can do this, but not sure how. Your on the right track in making a simple check to see who is logged on and check every so often to see what the resolution is. Does anyone know how to check the resolution using user32.dll? I googled it, and not having much luck.DllCall(...) = @DesktopHeight @DesktopWidthPerhaps AutoIt Macro's will do it. Link to comment Share on other sites More sharing options...
Bert Posted April 6, 2006 Author Share Posted April 6, 2006 In the script I found dllcall being used like this:DllCall("user32.dll", "int", "EnumDisplaySettings", "ptr", 0, "long", 0, "ptr", DLLStructGetPtr ($DEVMODE))Your code line is DllCall(...) = @DesktopHeight @DesktopWidth.The part I need a answer to is where you put "(...)" When I look for examples, I can find things in Dotnet, VB6 and other stuff. I have no clue on how to read those languages. If I had a example of a function on how to capture the screen size, I could put the script together. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted April 6, 2006 Author Share Posted April 6, 2006 I was looking at nfwu's code, and he may be on to something. I used the active window tool, and I noticed if you click on the desktop, I get this information back: >>>>>>>>>>>> Window Details <<<<<<<<<<<<< Title: Program Manager Class: Progman Size: X: 0 Y: 0 W: 2048 H: 768 This gives me the size of the screen, so I could get what I need by using WinGetPos In thinking about this, I thought there could be 2 different ways to go about it as far as usefulness in a resolution configuration tool. 1 -The first way would make a GUI that would allow for someone to set their preferences, and could have like settings for 6 users. Simple to use and configure. The GUI could look like the following example. Note: This doesn't include the fact that I would need to make a tray icon menu so it could be accessed at any time the user wanted to make a change. CODE#include <GuiConstants.au3> GuiCreate("Profile Resolution Tool", 407, 299,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Input_1 = GuiCtrlCreateInput("User 1", 40, 50, 100, 20) $Input_2 = GuiCtrlCreateInput("", 40, 80, 100, 20) $Input_3 = GuiCtrlCreateInput("", 40, 110, 100, 20) $Input_4 = GuiCtrlCreateInput("", 40, 140, 100, 20) $Input_5 = GuiCtrlCreateInput("", 40, 170, 100, 20) $Input_6 = GuiCtrlCreateInput("", 40, 200, 100, 20) $Checkbox_7 = GuiCtrlCreateCheckbox("", 20, 50, 20, 20) $Checkbox_8 = GuiCtrlCreateCheckbox("", 20, 80, 20, 20) $Checkbox_9 = GuiCtrlCreateCheckbox("", 20, 110, 20, 20) $Checkbox_10 = GuiCtrlCreateCheckbox("", 20, 140, 20, 20) $Checkbox_11 = GuiCtrlCreateCheckbox("", 20, 170, 20, 20) $Checkbox_12 = GuiCtrlCreateCheckbox("", 20, 200, 20, 20) $Combo_14 = GuiCtrlCreateCombo("1024 X 768", 160, 50, 160, 21) $Combo_15 = GuiCtrlCreateCombo("", 160, 80, 160, 21) $Combo_16 = GuiCtrlCreateCombo("", 160, 110, 160, 21) $Combo_17 = GuiCtrlCreateCombo("", 160, 140, 160, 21) $Combo_18 = GuiCtrlCreateCombo("", 160, 170, 160, 21) $Combo_19 = GuiCtrlCreateCombo("", 160, 200, 160, 21) $Label_20 = GuiCtrlCreateLabel("Profile resolution configuration tool by Volly", 20, 20, 300, 20) $Button_21 = GuiCtrlCreateButton("Ok", 40, 240, 80, 30) $Button_22 = GuiCtrlCreateButton("Cancel", 140, 240, 80, 30) $Button_23 = GuiCtrlCreateButton("Exit", 250, 240, 70, 30) $combo_20 = GuiCtrlCreateCombo("60 Hertz", 330, 50, 70, 21) $combo_21 = GuiCtrlCreateCombo("", 330, 80, 70, 21) $combo_22 = GuiCtrlCreateCombo("", 330, 110, 70, 21) $combo_23 = GuiCtrlCreateCombo("", 330, 140, 70, 21) $combo_24 = GuiCtrlCreateCombo("", 330, 170, 70, 21) $combo_25 = GuiCtrlCreateCombo("", 330, 200, 70, 21) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect WEnd Exit 2. The second way would have the icon in the system tray, but a small GUI that looks like this: GuiCreate("MyGUI", 254, 135,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $List_1 = GuiCtrlCreateList("List1", 10, 40, 230, 45) $Button_2 = GuiCtrlCreateButton("Add User", 10, 90, 60, 20) $Button_3 = GuiCtrlCreateButton("Delete User", 90, 90, 80, 20) $Button_4 = GuiCtrlCreateButton("Exit", 190, 90, 50, 20) $Label_5 = GuiCtrlCreateLabel("Profile resolution configuration tool by Volly", 20, 10, 210, 20) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect WEnd Exit With this one, you could do unlimited users, but some may find it somewhat more difficult to use. I would have it so each new user that wanted to have a custon size could enter it, but also have a default in case someone else logged in. Thoughts? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
CyberSlug Posted April 6, 2006 Share Posted April 6, 2006 (edited) Look at the following:http://perso.wanadoo.fr/sto41/en/My%20Tool...laySettings.htm( The following might also come in handy if the computer insists on using a crappy refresh rate when you switch resolutions: http://www.pagehosting.co.uk/rl/ ) Edited April 6, 2006 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
Bert Posted April 6, 2006 Author Share Posted April 6, 2006 This would solve the problem. I did have another thought on how to handle the problem. It would involve no GUI at all, but simply monitor when the system is switched betwen users. A check is ran, and all the settings are saved to a ini file, or a registry entry. When the user switches back, the entry is checked, and the screen reset if needed. No need to bug the user with a GUI, and it would work for anyone as well as new users. The script runs as a service. @cyberslug: The link you found looks good. I'm going to try it and see how it performs. It still would be fun to make a Autoit script to do this. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted April 12, 2006 Author Share Posted April 12, 2006 Forgot to reply on this. It works like a charm! The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now