Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Izlazak iz Windowsa

[es] :: Visual Basic 6 :: Izlazak iz Windowsa

[ Pregleda: 6385 | Odgovora: 8 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

GMC
Selo Veselo

Član broj: 11492
Poruke: 338
*.as54.tz.bih.net.ba.



Profil

icon Izlazak iz Windowsa28.01.2004. u 23:23 - pre 245 meseci
Dali mi neko moze posalit kod pomocu kojeg bi moga da izadjem iz windowsa (shut down). u stvari da pomocu njega ugasim racunar?!!
Ajd Zdravo
 
Odgovor na temu

mladenovicz
Zeljko Mladenovic
Xoran Technologies, Inc., Ann Arbor, MI,
USA / Software Engineer
Ann Arbor, MI, USA

Član broj: 6598
Poruke: 2065
*.yubc.net

Jabber: mladenovicz@elitesecurity.org
ICQ: 95144142
Sajt: yubc.net/~mz


Profil

icon Re: Izlazak iz Windowsa29.01.2004. u 09:43 - pre 245 meseci
Ajde malo koristi pretragu, to pitanje je vec postavljano.
 
Odgovor na temu

GMC
Selo Veselo

Član broj: 11492
Poruke: 338
*.as54.tz.bih.net.ba.



Profil

icon Re: Izlazak iz Windowsa29.01.2004. u 15:58 - pre 245 meseci
koristio sam pretragu i nasao jednu temu ali nisam nista razumio sta je sta. U stvari kad sam probao taj kod kod mene nije ni radio, pa sam mislio dali bi neko mogao malo da mi to objasni...
Ajd Zdravo
 
Odgovor na temu

mladenovicz
Zeljko Mladenovic
Xoran Technologies, Inc., Ann Arbor, MI,
USA / Software Engineer
Ann Arbor, MI, USA

Član broj: 6598
Poruke: 2065
*.yubc.net

Jabber: mladenovicz@elitesecurity.org
ICQ: 95144142
Sajt: yubc.net/~mz


Profil

icon Re: Izlazak iz Windowsa29.01.2004. u 16:39 - pre 245 meseci
Radi taj kod, nego aplikacija nema privilegije da ugasi masinu. Ovo bi trebalo da radi na svim verzijama windowsa.

Code:

'In a module
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
        
'Detect if the program is running under Windows NT
Public Function IsWinNT() As Boolean
    Dim myOS As OSVERSIONINFO
    myOS.dwOSVersionInfoSize = Len(myOS)
    GetVersionEx myOS
    IsWinNT = (myOS.dwPlatformId = VER_PLATFORM_WIN32_NT)
End Function

'set the shut down privilege for the current application
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
    ' enable shutdown privilege for the current application
    AdjustTokenPrivileges hToken, _
                          False, _
                          mPriv, _
                          4 + (12 * mPriv.PrivilegeCount), _
                          mNewPriv, _
                          4 + (12 * mNewPriv.PrivilegeCount)
End Sub

' Shut Down NT
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

'Restart NT
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

'Log off the current user
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

'In a form
'This project needs a form with three command buttons
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

 
Odgovor na temu

Sasa Vitorovic
Beograd

Član broj: 11629
Poruke: 193
*.ptt.yu

Sajt: www.ptt.yu/korisnici/s/a/..


Profil

icon Re: Izlazak iz Windowsa07.07.2004. u 13:54 - pre 240 meseci
Onaj kod ih prethodnih tema radi na 98ici,ali ne i na xp-u.
Ja sam probao na 2 racunara sa pomenutim winXP-om,ni na jednom nije radio.Ovaj kod je nesto bolji,ali na xpu dodje do poruke "It's now safe to turn off ..." i zaledi se.
Racunar se inace gasi normalno(ne moram nista da pritisnem nakon turn off)
Molim vas,pomagajte!
P.S.Voleo bih da dobijem sto univerzalnije resenje da ne bih na svakom kompu gde budem instalirao program morao da budzim po registry-ju.
U fudbalu je vazno jedno:a to su dve stvari:rad ,red i disciplina.
 
Odgovor na temu

Sasa Vitorovic
Beograd

Član broj: 11629
Poruke: 193
*.ptt.yu

Sajt: www.ptt.yu/korisnici/s/a/..


Profil

icon Re: Izlazak iz Windowsa09.07.2004. u 12:52 - pre 240 meseci
Dobro,hajde da još malo pojasnim problem.
Kao sto rekoh,na WinXP sa ovim kodom isključivanje dodje do čuvene poruke "It's now safe...".
Probao sam i iz terminala:
1.Na
Code:

rundll32.exe shell32.dll,SHExitWindowsEx

kaze "Mising entry:SHExitWindowsEx"
2.Na
Code:

c:\windows\system32\rundll32.exe user.exe,exitwindows

ili
Code:

c:\windows\system32\rundll32.exe user.exe,exitwindowsex

kaze "The aplication or dll c:\windows\system32\user.exe is not a valid windows image.Please check this against your instalation diskette."
Za putanje sam siguran da su OK.

U kontekstnom meniju user.exe nema QuickView,pa ne znam kako da pogledam spisak api funkcija.
Što je najčudnije,RESTART radi savršeno!
Sta da radim,POMAGAJTE!
U fudbalu je vazno jedno:a to su dve stvari:rad ,red i disciplina.
 
Odgovor na temu

Charli

Član broj: 28921
Poruke: 25
*.crnagora.net



Profil

icon Re: Izlazak iz Windowsa10.07.2004. u 19:07 - pre 240 meseci
Evo cod za gasenje win xp-a..
ps: Ako ima neko kod za hibernaciju xp neka ga okaci ovdje
Private Sub Stay Cool()

Code:

    Option Explicit

Private Const TOKEN_ADJUST_PRIVILEGES As Long = &H20
Private Const TOKEN_QUERY As Long = &H8
Private Const SE_PRIVILEGE_ENABLED As Long = &H2

Private Const EWX_LOGOFF As Long = &H0
Private Const EWX_SHUTDOWN As Long = &H1
Private Const EWX_REBOOT As Long = &H2
Private Const EWX_FORCE As Long = &H4
Private Const EWX_POWEROFF As Long = &H8

Private Const VER_PLATFORM_WIN32_NT As Long = 2

Private Type OSVERSIONINFO
  OSVSize         As Long
  dwVerMajor      As Long
  dwVerMinor      As Long
  dwBuildNumber   As Long
  PlatformID      As Long
  szCSDVersion    As String * 128
End Type

Private Type LUID
   dwLowPart As Long
   dwHighPart As Long
End Type

Private Type LUID_AND_ATTRIBUTES
   udtLUID As LUID
   dwAttributes As Long
End Type

Private Type TOKEN_PRIVILEGES
   PrivilegeCount As Long
   laa As LUID_AND_ATTRIBUTES
End Type
      
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 Any, _
   ReturnLength As Long) As Long

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

Private Function IsWinNTPlus() As Boolean

#If Win32 Then
  
      Dim OSV As OSVERSIONINFO
   
      OSV.OSVSize = Len(OSV)
   
      If GetVersionEx(OSV) = 1 Then

         IsWinNTPlus = (OSV.PlatformID = VER_PLATFORM_WIN32_NT) And _
                       (OSV.dwVerMajor >= 4)
      End If

   #End If

End Function


Private Function EnableShutdownPrivledges() As Boolean

   Dim hProcessHandle As Long
   Dim hTokenHandle As Long
   Dim lpv_la As LUID
   Dim token As TOKEN_PRIVILEGES
   
   hProcessHandle = GetCurrentProcess()
   
   If hProcessHandle <> 0 Then

If OpenProcessToken(hProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hTokenHandle) <> 0 Then

If LookupPrivilegeValue(vbNullString, "SeShutdownPrivilege", lpv_la) <> 0 Then

With token
               .PrivilegeCount = 1
               .laa.udtLUID = lpv_la
               .laa.dwAttributes = SE_PRIVILEGE_ENABLED
            End With
   
If AdjustTokenPrivileges(hTokenHandle, False, token, ByVal 0&, ByVal 0&, ByVal 0&) <> 0 Then
                                    
EnableShutdownPrivledges = True
   
            End If
End If
End If
End If

End Function



Private Sub Command1_Click()
   Dim uflags As Long
   Dim success As Long
   'force shutdown
uflags = EWX_FORCE
If IsWinNTPlus() Then
   
      success = EnableShutdownPrivledges()
      If success Then Call ExitWindowsEx(uflags, 0&)
         
   Else

Call ExitWindowsEx(uflags, 0&)
      
   End If
End Sub

Private Sub Command2_Click()
   Dim uflags As Long
   Dim success As Long
   'log off
uflags = EWX_LOGOFF
If IsWinNTPlus() Then
   
      success = EnableShutdownPrivledges()
      If success Then Call ExitWindowsEx(uflags, 0&)
         
   Else

Call ExitWindowsEx(uflags, 0&)
      
   End If
End Sub

Private Sub Command3_Click()
   Dim uflags As Long
   Dim success As Long
    'shut down
uflags = EWX_SHUTDOWN
If IsWinNTPlus() Then
   
      success = EnableShutdownPrivledges()
      If success Then Call ExitWindowsEx(uflags, 0&)
         
   Else

Call ExitWindowsEx(uflags, 0&)
      
   End If

End Sub

Private Sub Command4_Click()
   Dim uflags As Long
   Dim success As Long
   'reboot
uflags = EWX_REBOOT
If IsWinNTPlus() Then
   
      success = EnableShutdownPrivledges()
      If success Then Call ExitWindowsEx(uflags, 0&)
         
   Else

Call ExitWindowsEx(uflags, 0&)
      
   End If
End Sub

Private Sub Command5_Click()
   Dim uflags As Long
   Dim success As Long
   'power off za gasenje windowsa
uflags = EWX_POWEROFF
If IsWinNTPlus() Then
   
      success = EnableShutdownPrivledges()
      If success Then Call ExitWindowsEx(uflags, 0&)
         
   Else

Call ExitWindowsEx(uflags, 0&)
      
   End If

End Sub


Charli
 
Odgovor na temu

Sasa Vitorovic
Beograd

Član broj: 11629
Poruke: 193
*.ptt.yu

Sajt: www.ptt.yu/korisnici/s/a/..


Profil

icon Re: Izlazak iz Windowsa11.07.2004. u 18:56 - pre 239 meseci
Hvala Charlii,to je to!
Suštinska razlika je u redu koda:
Code:

Private Const EWX_POWEROFF As Long = &H8

WinXP se samo tako može ugasiti.To ne radi u Win98(on se tada ponovo loguje).Medjutim,iznenadilo me je to što su win32api.txt isti u Win98 i u WinXP.Znam da je to nemoguće.
U čemu je problem?Tako ne mogu da vidim da li su u XP definisane (drugačije) neke api funkcije iz win98.
U fudbalu je vazno jedno:a to su dve stvari:rad ,red i disciplina.
 
Odgovor na temu

HUNer
Nezaposlen (jos se školujem)
Cyber World

Član broj: 33014
Poruke: 26
*.ptt.yu.



Profil

icon Re: Izlazak iz Windowsa27.10.2004. u 00:19 - pre 236 meseci
Evo po mom mišljenju bolji kod za Windows XP.
Dobro nije baš bolji ali je kratak i dosta je prost.
1.Na početku ubaciti jedan Command Button sa nazivom Command1
2.Ubaciti jedan Command Button sa nazivom Command1
Code:


Private Sub Form_Load()
Command1.Caption="Gašenje kompa"
Command1.Caption="Restart kompa"
End Sub


Private Sub Command1_Click()
Shell ("shutdows -f -s -t 0") 'Ovim ste ugasili računar
End Sub

Private Sub Command2_Click()
Shell ("shutdows -f -r -t 0") 'Ovim ste restartovali računar
End Sub

 
Odgovor na temu

[es] :: Visual Basic 6 :: Izlazak iz Windowsa

[ Pregleda: 6385 | Odgovora: 8 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.