Visual basic 6 commande ???

Signaler
Messages postés
2
Date d'inscription
vendredi 28 janvier 2005
Statut
Membre
Dernière intervention
1 mars 2006
-
Messages postés
89
Date d'inscription
dimanche 21 septembre 2008
Statut
Membre
Dernière intervention
26 avril 2016
-
svp est ce que quek'un coné la command quit pe etteindre le pc sur visual basic 6 ( j ve dire quan on clique sur un bouton le pc s'etein
Merci

5 réponses

Messages postés
289
Date d'inscription
dimanche 10 août 2003
Statut
Membre
Dernière intervention
28 février 2009
2
Option Explicit



'Detecte si le système est WinNT ou Win2k/XP, et donc si on a besoin de privilèges

Public Function IsWinNT() As Boolean

Dim myOS As OSVERSIONINFO

myOS.dwOSVersionInfoSize = Len(myOS)

GetVersionEx myOS

IsWinNT (myOS.dwPlatformId VER_PLATFORM_WIN32_NT)

End Function

'Permet d'avoir le privilège d'arrêter Windows

Private Sub EnableShutDown()

Dim hProc As Long

Dim hToken As Long

Dim mLUID As LUID

Dim mPriv As TOKEN_PRIVILEGES

Dim mNewPriv As TOKEN_PRIVILEGES

hProc = GetCurrentProcess()

OpenProcessToken hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken

LookupPrivilegeValue "", "SeShutdownPrivilege", mLUID

mPriv.PrivilegeCount = 1

mPriv.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED

mPriv.Privileges(0).pLuid = mLUID

AdjustTokenPrivileges hToken, False, mPriv, 4 + (12
* mPriv.PrivilegeCount), mNewPriv, 4 + (12 * mNewPriv.PrivilegeCount)

End Sub

' Arrêter Windows

Public Sub ShutDownNT(Force As Boolean)

Dim ret As Long

Dim Flags As Long

Flags = EWX_SHUTDOWN

If Force Then Flags = Flags Or EWX_FORCE

If IsWinNT Then EnableShutDown

ExitWindowsEx Flags, 0

End Sub

' Redémarrer Windows

Public Sub RebootNT(Force As Boolean)

Dim ret As Long

Dim Flags As Long

Flags = EWX_REBOOT

If Force Then Flags = Flags Or EWX_FORCE

If IsWinNT Then EnableShutDown

ExitWindowsEx Flags, 0

End Sub

' Déconnexion

Public Sub LogOffNT(Force As Boolean)

Dim ret As Long

Dim Flags As Long

Flags = EWX_LOGOFF

If Force Then Flags = Flags Or EWX_FORCE

ExitWindowsEx Flags, 0

End Sub



Ta juste à chercher les api a déclarer parce que je l'ai ai mis sur un module a part mais j'ai la flemme de filtrer :





Option Explicit



Public Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As
String, ByVal nShowCmd As Long) As Long

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Declare Function RegCreateKey Lib "advapi32.dll" Alias
"RegCreateKeyA" (ByVal HKey As Long, ByVal lpSubKey As String,
phkResult As Long) As Long

Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias
"RegDeleteKeyA" (ByVal HKey As Long, ByVal lpSubKey As String) As Long

Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias
"RegDeleteValueA" (ByVal HKey As Long, ByVal lpSubKey As String) As Long

Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias
"RegQueryValueExA" (ByVal HKey As Long, ByVal lpValueName As String,
ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As
Long) As Long

Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias
"RegSetValueExA" (ByVal HKey As Long, ByVal lpValueName As String,
ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As Any,
ByVal cbData As Long) As Long

Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

Public Declare Function GetCurrentProcess Lib "kernel32" () As Long

Public Declare Function OpenProcessToken Lib "advapi32" (ByVal
ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As
Long) As Long

Public Declare Function LookupPrivilegeValue Lib "advapi32" Alias
"LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As
String, lpLuid As LUID) As Long

Public 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

Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

Public Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long

Public Declare Function EnumDisplaySettings Lib "user32" Alias
"EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As
Long, lpDevMode As Any) As Boolean

Public Declare Function ChangeDisplaySettings Lib "user32" Alias
"ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags As Long) As
Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam
As Any) As Long

Public Declare Function waveOutSetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long

Public Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long

Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, NSize As Long) As Long



Public Type DEVMODE

dmDeviceName As String * 32

dmSpecVersion As Integer

dmDriverVersion As Integer

dmSize As Integer

dmDriverExtra As Integer

dmFields As Long

dmOrientation As Integer

dmPaperSize As Integer

dmPaperLength As Integer

dmPaperWidth As Integer

dmScale As Integer

dmCopies As Integer

dmDefaultSource As Integer

dmPrintQuality As Integer

dmColor As Integer

dmDuplex As Integer

dmYResolution As Integer

dmTTOption As Integer

dmCollate As Integer

dmFormName As String * 32

dmUnusedPadding As Integer

dmBitsPerPel As Integer

dmPelsWidth As Long

dmPelsHeight As Long

dmDisplayFlags As Long

dmDisplayFrequency As Long

End Type



Public Enum EnumSetRes

SUCCES = 0

ECHEC = -2

End Enum



Public Const EWX_LOGOFF = 0

Public Const EWX_SHUTDOWN = 1

Public Const EWX_REBOOT = 2

Public Const EWX_FORCE = 4

Public Const TOKEN_ADJUST_PRIVILEGES = &H20

Public Const TOKEN_QUERY = &H8

Public Const SE_PRIVILEGE_ENABLED = &H2

Public Const ANYSIZE_ARRAY = 1



Public Const VER_PLATFORM_WIN32s = 0

Public Const VER_PLATFORM_WIN32_WINDOWS = 1

Public Const VER_PLATFORM_WIN32_NT = 2



Public Const SND_ASYNC = &H1

Public Const SND_NODEFAULT = &H2

Public Const SND_NOWAIT = &H2000



Public Type LUID

LowPart As Long

HighPart As Long

End Type



Public Type LUID_AND_ATTRIBUTES

pLuid As LUID

Attributes As Long

End Type



Public Type TOKEN_PRIVILEGES

PrivilegeCount As Long

Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES

End Type



Public Type OSVERSIONINFO

dwOSVersionInfoSize As Long

dwMajorVersion As Long

dwMinorVersion As Long

dwBuildNumber As Long

dwPlatformId As Long

szCSDVersion As String * 128

wSPMajor As Integer

End Type



Public Enum HCle

HKeyLocalMachine = 0

HKeyCurrentUser = 1

HKeyClassesRoot = 2

HKeyUsers = 3

HKeyDynamicData = 4

End Enum



++
-=Ar$£nik=-
Messages postés
1423
Date d'inscription
mardi 14 décembre 2004
Statut
Membre
Dernière intervention
29 décembre 2012
4
euh c est pas plus simple de faire du sendkeys ?
genre alt+F4
puis T pour xp ...?
Messages postés
147
Date d'inscription
lundi 13 mai 2002
Statut
Membre
Dernière intervention
15 février 2010

Sur XP :

pour arrêter
Shell ("shutdown.exe -t 00 -s")

pour redémarrer
Shell ("shutdown.exe -t 00 -r")



<HR>

Life is Too Short ...
Enjoy Your Life ...
Messages postés
289
Date d'inscription
dimanche 10 août 2003
Statut
Membre
Dernière intervention
28 février 2009
2
Oui mais bon, la première astuce n'est que du bidouillage et pour la 2ème elle n'est valable que sur XP.



La mienne marchera tout le temps avec un code propre ( Même si volumineux, se devrai effrayer personne )
-=Ar$£nik=-
Messages postés
89
Date d'inscription
dimanche 21 septembre 2008
Statut
Membre
Dernière intervention
26 avril 2016

Je dis non la deuxieme methode celle avec "Shell ("shutdown.exe -t 00 -s")"
marchera sur tout les pc ayant shutdown.exe =)