Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it L'avatar di lamers
    Registrato dal
    Mar 2003
    Messaggi
    14

    [VB6] # Spegnere il computer da VB...

    Salve a tutti.
    Di recente ho scaricato un ocx di nome WinControl in grado di poter spegnere, riavviare o disconnettere il computer.
    In WINXP questo OCX è in grado solo di disconnettermi e non di riavviare o spegnere.

    ORA STO CREANDO UN PROGRAMMA IN VB IN GRADO DI SPEGNERE O RIAVVIARE IL PC DOPO UN CERTO PERIODO.
    IL PROGRAMMA FUNZIONA ALLA PERFEZIONE, IL PROBLEMA E' CHE NON SO COME FARE ADESSO A SPEGNERE O RIAVVIARE IL PC.

    C'è QUALCHE COMANDO?

    Grazie di cuore a tutti...

  2. #2
    Utente di HTML.it L'avatar di lamers
    Registrato dal
    Mar 2003
    Messaggi
    14

    Potrei fare così ?.?.?.?.?.?...

    Ho scoperto che nella cartella di windows c'è un file, LOGOFF.EXE, che lanciandolo mi disconnette il pc.

    Esisteranno pure i file per spegnere o riavviare (tipo SHOUTDOWN.EXE o REBOOT.EXE) ???

    In modo da poter utilizzare il comando SHELL ???

    MA!!!

    GRAZIE ANCORA

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2003
    Messaggi
    106
    guarda qui nella 1^,3^ e 4^ pagina ci sono tre files ke si chiamao shtudownECC.zip .. al posto di ECC c'è un'altro nome, diverso x ognuno dei 3

  4. #4

  5. #5
    avevo il tuo stesso problema poi ho risolto trovando questo codice:
    fai attenzione perchè funziona veramente

    in command1 o nel controllo che spegnerà metti:
    Call ShutDown

    in un modulo invece:
    Private Type LUID
    UsedPart As Long
    IgnoredForNowHigh32BitPart As Long
    End Type

    Private Type TOKEN_PRIVILEGES
    PrivilegeCount As Long
    TheLuid As LUID
    Attributes As Long
    End Type

    Private Const EWX_SHUTDOWN As Long = 1
    Private Const EWX_FORCE As Long = 4
    Private Const EWX_REBOOT = 2

    Private Declare Function ExitWindowsEx Lib "user32" (ByVal _
    dwOptions As Long, ByVal dwReserved As Long) As Long

    Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    Private Declare Function OpenProcessToken Lib "advapi32" (ByVal _
    ProcessHandle As Long, _
    ByVal DesiredAccess As Long, TokenHandle As Long) As Long
    Private Declare Function LookupPrivilegeValue Lib "advapi32" _
    Alias "LookupPrivilegeValueA" _
    (ByVal lpSystemName As String, ByVal lpName As String, lpLuid _
    As LUID) As Long
    Private Declare Function AdjustTokenPrivileges Lib "advapi32" _
    (ByVal TokenHandle As Long, _
    ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES _
    , ByVal BufferLength As Long, _
    PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
    Private Sub AdjustToken()
    Const TOKEN_ADJUST_PRIVILEGES = &H20
    Const TOKEN_QUERY = &H8
    Const SE_PRIVILEGE_ENABLED = &H2
    Dim hdlProcessHandle As Long
    Dim hdlTokenHandle As Long
    Dim tmpLuid As LUID
    Dim tkp As TOKEN_PRIVILEGES
    Dim tkpNewButIgnored As TOKEN_PRIVILEGES
    Dim lBufferNeeded As Long

    hdlProcessHandle = GetCurrentProcess()
    OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or _
    TOKEN_QUERY), hdlTokenHandle

    ' Get the LUID for shutdown privilege.
    LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid

    tkp.PrivilegeCount = 1 ' One privilege to set
    tkp.TheLuid = tmpLuid
    tkp.Attributes = SE_PRIVILEGE_ENABLED

    ' Enable the shutdown privilege in the access token of this process.
    AdjustTokenPrivileges hdlTokenHandle, False, _
    tkp, Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded

    End Sub


    Public Sub ShutDown()
    AdjustToken
    ExitWindowsEx (EWX_SHUTDOWN), &HFFFF
    End Sub

  6. #6
    Utente di HTML.it L'avatar di lamers
    Registrato dal
    Mar 2003
    Messaggi
    14

    OK FUNZIONA !!!

    GRAZIE TANTE A TUTTI !!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.