Koji kod za shutdown

Koji kod za shutdown

offline
  • Gama  Male
  • Zaslužni građanin
  • istoričar
  • Pridružio: 14 Jun 2004
  • Poruke: 691
  • Gde živiš: Niš, Srbija

Pravim aplikaciju u VB.Potreban mi je kod za shutdown ili restart.
Kod zelim da ubacim u formu.



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
offline
  • Đuro Glumac
  • dipl. ing. informatike
  • Pridružio: 08 Feb 2004
  • Poruke: 3640
  • Gde živiš: ApAtIn

Google mi je nasao brdo VB kodova za ShutDown...
http://visualbasic.ittoolbox.com/code/d.asp?d=1888&a=s



offline
  • Gama  Male
  • Zaslužni građanin
  • istoričar
  • Pridružio: 14 Jun 2004
  • Poruke: 691
  • Gde živiš: Niš, Srbija

Hvala Null

offline
  • Pridružio: 29 Maj 2004
  • Poruke: 33

Ovo stavi u Moduel:

Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4
Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const ANYSIZE_ARRAY = 1
Private Const VER_PLATFORM_WIN32_NT = 2
Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Type LUID
LowPart As Long
HighPart As Long
End Type
Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type

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 Declare Function ExitWindowsEx Lib "user32" _
(ByVal uFlags As Long, ByVal dwReserved As Long) As Long

Private Declare Function GetVersionEx Lib "kernel32" Alias _
"GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long

Public Function IsWinNT() As Boolean
Dim myOS As OSVERSIONINFO
myOS.dwOSVersionInfoSize = Len(myOS)
GetVersionEx myOS
IsWinNT = (myOS.dwPlatformId = VER_PLATFORM_WIN32_NT)
End Function

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

Public Sub ShutDownNT(Force As Boolean)
Dim ret As Long
Dim Flags As Long
Flags = EWX_SHUTDOWN
If Force Then Flags = Flags + EWX_FORCE
If IsWinNT Then EnableShutDown
ExitWindowsEx Flags, 0
End Sub

Public Sub RebootNT(Force As Boolean)
Dim ret As Long
Dim Flags As Long
Flags = EWX_REBOOT
If Force Then Flags = Flags + EWX_FORCE
If IsWinNT Then EnableShutDown
ExitWindowsEx Flags, 0
End Sub

Public Sub LogOffNT(Force As Boolean)
Dim ret As Long
Dim Flags As Long
Flags = EWX_LOGOFF
If Force Then Flags = Flags + EWX_FORCE
ExitWindowsEx Flags, 0
End Sub

Private Sub Command1_Click()
LogOffNT True
End Sub

Private Sub Command2_Click()
RebootNT True
End Sub

Private Sub Command3_Click()
ShutDownNT True
End Sub

Private Sub Form_Load()
Command1.Caption = "Log Off NT"
Command2.Caption = "Reboot NT"
Command3.Caption = "Shutdown NT"
End Sub






I onda stavi 3 dugmeta i onda npr.
Private Sub Command1_Click()
On Error Resume Next
LogOffNT True
End Sub

offline
  • Pridružio: 18 Apr 2003
  • Poruke: 8134
  • Gde živiš: U kesici gumenih bombona...

ja sam nasao gomilu kodova koji su radili na win9x, ali ne i na XPu...

offline
  • Pridružio: 18 Jul 2003
  • Poruke: 4204
  • Gde živiš: U zlatnom kavezu

Jes da je tema zastarela, ali da dopisem u XP -u kao sto svi znamo posao odradju je jedan red code-a

Private Sub Form_Load()     Shell "shutdown -s -t00" end sub a za restart Private Sub Form_Load()     Shell "shutdown -r -t00" end sub

Preporucljivoje imati instaliran SP1 ili 2 u suprotnom ovo mozda nece raditi.

offline
  • Pridružio: 11 Nov 2004
  • Poruke: 5
  • Gde živiš: Cicevac

Javljam se za zakasnjenjem, ali VB nije privilegovan u XP-u. Kod koji je poslao =Vrky= nalazi se u helpu VB 6.0. Potrazis proceduru: AdjustToken. Kod radi, provereno.

Ko je trenutno na forumu
 

Ukupno su 1115 korisnika na forumu :: 45 registrovanih, 3 sakrivenih i 1067 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: 8u47, AC-DC, aleksmajstor, Alibaba1981, bigfoot, bojank, bokisha253, brundo65, cikadeda, darios, djordje92sm, DonRumataEstorski, doom83, dragoljub11987, Koridor, krkalon, Kubovac, Litostroton, ljuba, mackenzie, Magistar78, maiden6657, manda87, mercedesamg, milenko crazy north, MiroslavD, mrav pesadinac, nazgul75, Nemanja.M, oldtimer, Panter, Povratak1912, radionica1, Raso75, Romibrat, shlauf, styg, theNedjeljko, Tvrtko I, vaso1, vathra, Vatreni Zmaj, VJ, Vlad000, vladaa012