checlever Posted April 21, 2014 Share Posted April 21, 2014 Hi everyone, I have a .vb script that I would like to convert to .au3 It is to remotely force logoff an user in windows 7. Fast user switching is and must disabled. Other ways that worked on XP (like psexec) to do this do not work in windows 7. .vb strComputer= InputBox( "Enter Machine Name/IP Address here..." ) Set objWMI = GetObject("winmgmts:{(Shutdown)}" + strComputer + "rootcimv2") Set colOperatingSystems = objWMI.ExecQuery("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems ObjOperatingSystem.Win32Shutdown(0) Next my .au3 attempt that doesn't work Local $computername = "computername" Local $objWMI = ObjGet("winmgmts:{(Shutdown)}\\" & $computername & "\root\cimv2") Local $colOperatingSystems = $objWMI.ExecQuery("Select * from Win32_OperatingSystems") For $objOperatingSystem In $colOperatingSystems $objOperatingSystem.Win32Shutdown(4) Next Thanks!! Link to comment Share on other sites More sharing options...
FireFox Posted April 21, 2014 Share Posted April 21, 2014 Other ways that worked on XP (like psexec) to do this do not work in windows 7.To be clear what works in vb and what doesn't in autoit? Link to comment Share on other sites More sharing options...
Solution jguinch Posted April 21, 2014 Solution Share Posted April 21, 2014 It is Win32_OperatingSystem, not Win32_OperatingSystems... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 21, 2014 Moderators Share Posted April 21, 2014 I gave this to my helpdesk, works well on XP and WIN7, x86 or x64. It may help you get where you want to go. expandcollapse popup#include <Constants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("Remote PC Administration", 300, 200) GUISetFont(11, 400, Default, "Arial") $pclbl = GUICtrlCreateLabel("Machine Name or IP address", 40, 10, 220, 20) GUICtrlSetFont($pclbl, 11, 600, Default, "Arial") $pcinput = GUICtrlCreateInput("", 10, 40, 280, 30) $logoffrbtn = GUICtrlCreateRadio("Logoff current user", 10, 80, 145, 30) $rebootrbtn = GUICtrlCreateRadio("Reboot machine", 160, 80, 140, 30) $gobtn = GUICtrlCreateButton("Run", 10, 120, 80, 40) $exit = GUICtrlCreateButton("Exit", 200, 120, 80, 40) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $exit ExitLoop Case $gobtn $iPing = Ping(GUICtrlRead($pcinput)) If $iPing Then $WMI = ObjGet("winmgmts:{(Shutdown)}\\" & GUICtrlRead($pcinput) & "\root\cimv2") $aOS = $WMI.ExecQuery("Select * from Win32_OperatingSystem") If GUICtrlRead($logoffrbtn) = $GUI_CHECKED Then For $element In $aOS $element.Win32Shutdown($SD_LOGOFF) Next Else For $element In $aOS $element.Win32Shutdown($SD_REBOOT) Next ; EndIf Else MsgBox(0, "Remote PC Administration", "Remote Host Unreachable") EndIf EndSwitch WEnd GUIDelete() "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
checlever Posted April 21, 2014 Author Share Posted April 21, 2014 It is Win32_OperatingSystem, not Win32_OperatingSystems... I feel dumb now....I should have seen that sorry to bother you guys It was a loooooong day yesterday and this was the last thing I was working on. It is working now. Thanks Link to comment Share on other sites More sharing options...
checlever Posted April 21, 2014 Author Share Posted April 21, 2014 To be clear what works in vb and what doesn't in autoit? The vb code above works fine in win7 (have not tested on XP). I used autoit to run psexec and that doesn't work anymore nor does psshutdown on win7. I tried to convert the vb code above to autoit so I didn't have to use autoit to run a vb script but it wasn't working because I misspelled something but it is now working. Thanks Link to comment Share on other sites More sharing options...
checlever Posted April 21, 2014 Author Share Posted April 21, 2014 I gave this to my helpdesk, works well on XP and WIN7, x86 or x64. It may help you get where you want to go. expandcollapse popup#include <Constants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("Remote PC Administration", 300, 200) GUISetFont(11, 400, Default, "Arial") $pclbl = GUICtrlCreateLabel("Machine Name or IP address", 40, 10, 220, 20) GUICtrlSetFont($pclbl, 11, 600, Default, "Arial") $pcinput = GUICtrlCreateInput("", 10, 40, 280, 30) $logoffrbtn = GUICtrlCreateRadio("Logoff current user", 10, 80, 145, 30) $rebootrbtn = GUICtrlCreateRadio("Reboot machine", 160, 80, 140, 30) $gobtn = GUICtrlCreateButton("Run", 10, 120, 80, 40) $exit = GUICtrlCreateButton("Exit", 200, 120, 80, 40) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $exit ExitLoop Case $gobtn $iPing = Ping(GUICtrlRead($pcinput)) If $iPing Then $WMI = ObjGet("winmgmts:{(Shutdown)}\\" & GUICtrlRead($pcinput) & "\root\cimv2") $aOS = $WMI.ExecQuery("Select * from Win32_OperatingSystem") If GUICtrlRead($logoffrbtn) = $GUI_CHECKED Then For $element In $aOS $element.Win32Shutdown($SD_LOGOFF) Next Else For $element In $aOS $element.Win32Shutdown($SD_REBOOT) Next ; EndIf Else MsgBox(0, "Remote PC Administration", "Remote Host Unreachable") EndIf EndSwitch WEnd GUIDelete() It look like something I will use. Thanks for sharing!!! 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