Sign in to follow this  
Followers 0
checlever

Help converting .vb to .au3

7 posts in this topic

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!!

 

Share this post


Link to post
Share on other sites



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?

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

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.

#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()

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

 

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.

#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!!!

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