banjalukaforum.com https://banjalukaforum.com/ |
|
Win32 Api with vb.net? https://banjalukaforum.com/viewtopic.php?f=18&t=15487 |
Stranica 1 od 1 |
Autoru: | RAbbit [ 30 Avg 2005, 12:42 ] |
Tema posta: | Win32 Api with vb.net? |
Vertigo, i ostali da nemate slucajno neku knjigu o pozivanju api funkcija windowsa tj. o opisu sta koja api funkcija radi.Ja znam kako pozvati api funkciju u vb.net-u al neznam sta koja api funkcija radi.I po mogucnosti da je knjiga za vb.net al moze i za neki dr. jezik ako nemate bas tu?Hvala ![]() Naprimer treba mi api funkcija za gasenje racunara, stavim timer i da korisnik moze u opcijama namjestiti da mu se racunar ugasi nakon toliko i toliko vremena.Treba mi neka api funkcija a neznam koja? I slicno, znaci treba mi opis svih api funkcija windowsa sta koja radi tacno? |
Autoru: | Vertygo [ 30 Avg 2005, 17:21 ] |
Tema posta: | |
Ako vec zelis da uputis pitanje direktno meni posalji mi privatnu poruku, bezveze je otvarati temu za ovako nesto. Sto se tice API-ja sa time se slabo susrecem u .net frameworku, jedino ako je u pitanju unmanaged code. http://msdn.microsoft.com http://msdn.microsoft.com/library/defau ... erence.asp Api viewer: http://www.activevb.de/rubriken/apiview ... ml#anchor3 i jos jedan http://www.mentalis.org/agnet/apiguide.shtml Shutdown: http://www.mentalis.org/apilist/Initiat ... down.shtml http://msdn.microsoft.com/library/defau ... ctions.asp Previse api funkcija ima da bi to jedna knjiga porkila ... moze samo dio. |
Autoru: | RAbbit [ 30 Avg 2005, 22:15 ] |
Tema posta: | Odgovor |
Sto se mene tice obrisi temu.Mnogo su mi pomogli oni programi al i oni su stari ima jedan iz 2004 al nema spisak konstanti al ja sam nabavio konstante za shutdown i opet nemogu pokrenuti shutdown iz vb.net-a, nesto neradi nekontam, a nejavlja nikakvu gresku. Da ima par primera u vb.net-u bilo bi dobro. Ako ti znas iz namespace vb.net-a kako pokrenuti shutdown recimo ako postoji bilo bi korisno. |
Autoru: | RAbbit [ 30 Avg 2005, 23:17 ] |
Tema posta: | Odgovor |
Oni iz microsofta su ludi evo vec 2 sata trazim na netu api funkciju za vb.net, ima za vb.6 neka gasi windows al i to pitanje ali za vb.net nema. Imam ja kod za vb.net ali neradi kao nemam privilegije administratora,to valjda uveli zbog hakera nesto, nema uputstva na MSDN kaze idi na privileges ja tamo a odatle link idi na api ![]() Vrti me u krug ![]() Ima li ko ista sto radi? Evo par kodova za vb6 i nekih dr. Class Module: ' Shutdown Flags Private Const EWX_LOGOFF = 0 Private Const EWX_SHUTDOWN = 1 Private Const EWX_REBOOT = 2 Private Const EWX_FORCE = 4 Private Const SE_PRIVILEGE_ENABLED = &H2 Private Const TokenPrivileges = 3 Private Const TOKEN_ASSIGN_PRIMARY = &H1 Private Const TOKEN_DUPLICATE = &H2 Private Const TOKEN_IMPERSONATE = &H4 Private Const TOKEN_QUERY = &H8 Private Const TOKEN_QUERY_SOURCE = &H10 Private Const TOKEN_ADJUST_PRIVILEGES = &H20 Private Const TOKEN_ADJUST_GROUPS = &H40 Private Const TOKEN_ADJUST_DEFAULT = &H80 Private Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege" Private Const ANYSIZE_ARRAY = 1 Private Type LARGE_INTEGER lowpart As Long highpart As Long End Type Private Type Luid lowpart As Long highpart As Long End Type Private Type LUID_AND_ATTRIBUTES 'pLuid As Luid pLuid As LARGE_INTEGER Attributes As Long End Type Private Type TOKEN_PRIVILEGES PrivilegeCount As Long Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES End Type Private Declare Function InitiateSystemShutdown Lib "advapi32.dll" Alias "InitiateSystemShutdownA" (ByVal lpMachineName As String, ByVal lpMessage As String, ByVal dwTimeout As Long, ByVal bForceAppsClosed As Long, ByVal bRebootAfterShutdown As Long) As Long Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long Private Declare Function GetCurrentProcess Lib "kernel32" () As Long Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LARGE_INTEGER) As Long Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (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 GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Declare Function GetLastError Lib "kernel32" () As Long Public Function InitiateShutdownMachine(ByVal Machine As String, Optional Force As Variant, Optional Restart As Variant, Optional AllowLocalShutdown As Variant, Optional Delay As Variant, Optional Message As Variant) As Boolean Dim hProc As Long Dim OldTokenStuff As TOKEN_PRIVILEGES Dim OldTokenStuffLen As Long Dim NewTokenStuff As TOKEN_PRIVILEGES Dim NewTokenStuffLen As Long Dim pSize As Long If IsMissing(Force) Then Force = False If IsMissing(Restart) Then Restart = True If IsMissing(AllowLocalShutdown) Then AllowLocalShutdown = False If IsMissing(Delay) Then Delay = 0 If IsMissing(Message) Then Message = "" 'Make sure the Machine-name doesn't start with '' If InStr(Machine, "") = 1 Then Machine = Right(Machine, Len(Machine) - 2) End If 'check if it's the local machine that's going to be shutdown If (LCase(GetMyMachineName) = LCase(Machine)) Then 'may we shut this computer down? If AllowLocalShutdown = False Then Exit Function 'open access token If OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hProc) = 0 Then MsgBox "OpenProcessToken Error: " & GetLastError() Exit Function End If 'retrieve the locally unique identifier to represent the Shutdown-privilege name If LookupPrivilegeValue(vbNullString, SE_SHUTDOWN_NAME, OldTokenStuff.Privileges(0).pLuid) = 0 Then MsgBox "LookupPrivilegeValue Error: " & GetLastError() Exit Function End If NewTokenStuff = OldTokenStuff NewTokenStuff.PrivilegeCount = 1 NewTokenStuff.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED NewTokenStuffLen = Len(NewTokenStuff) pSize = Len(NewTokenStuff) 'Enable shutdown-privilege If AdjustTokenPrivileges(hProc, False, NewTokenStuff, NewTokenStuffLen, OldTokenStuff, OldTokenStuffLen) = 0 Then MsgBox "AdjustTokenPrivileges Error: " & GetLastError() Exit Function End If 'initiate the system shutdown If InitiateSystemShutdown("" & Machine, Message, Delay, Force, Restart) = 0 Then Exit Function End If NewTokenStuff.Privileges(0).Attributes = 0 'Disable shutdown-privilege If AdjustTokenPrivileges(hProc, False, NewTokenStuff, Len(NewTokenStuff), OldTokenStuff, Len(OldTokenStuff)) = 0 Then Exit Function End If Else 'initiate the system shutdown If InitiateSystemShutdown("" & Machine, Message, Delay, Force, Restart) = 0 Then Exit Function End If End If InitiateShutdownMachine = True End Function Private Function GetMyMachineName() As String Dim sLen As Long 'create a buffer GetMyMachineName = Space(100) sLen = 100 'retrieve the computer name If GetComputerName(GetMyMachineName, sLen) Then GetMyMachineName = Left(GetMyMachineName, sLen) End If End Function Module (any routine really): Option Explicit Private Sub Main() Dim Shutdown As New CShutdown Set Shutdown = New CShutdown Shutdown.InitiateShutdownMachine "Computer Name", True, True, True, 60, "You initiated a system shutdown..." Set Shutdown = Nothing End ' It's a delay, so terminate the program End Sub It's not that hard to put it to work: '---start---' 'Put this code at the top of the forms general section' Const EWX_LOGOFF = 0 Const EWX_SHUTDOWN = 1 Const EWX_REBOOT = 2 Const EWX_FORCE = 4 Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long 'Add a command button (Command1): Private Sub Command1_Click() 'reboot the computer ExitWindowsEx EWX_FORCE Or EWX_REBOOT, 0 End Sub '---end---' 2) ' Shutdown Flags Const EWX_LOGOFF = 0 Const EWX_SHUTDOWN = 1 Const EWX_REBOOT = 2 Const EWX_FORCE = 4 Const SE_PRIVILEGE_ENABLED = &H2 Const TokenPrivileges = 3 Const TOKEN_ASSIGN_PRIMARY = &H1 Const TOKEN_DUPLICATE = &H2 Const TOKEN_IMPERSONATE = &H4 Const TOKEN_QUERY = &H8 Const TOKEN_QUERY_SOURCE = &H10 Const TOKEN_ADJUST_PRIVILEGES = &H20 Const TOKEN_ADJUST_GROUPS = &H40 Const TOKEN_ADJUST_DEFAULT = &H80 Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege" Const ANYSIZE_ARRAY = 1 Private Type LARGE_INTEGER lowpart As Long highpart As Long End Type Private Type Luid lowpart As Long highpart As Long End Type Private Type LUID_AND_ATTRIBUTES 'pLuid As Luid pLuid As LARGE_INTEGER Attributes As Long End Type Private Type TOKEN_PRIVILEGES PrivilegeCount As Long Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES End Type Private Declare Function InitiateSystemShutdown Lib "advapi32.dll" Alias "InitiateSystemShutdownA" (ByVal lpMachineName As String, ByVal lpMessage As String, ByVal dwTimeout As Long, ByVal bForceAppsClosed As Long, ByVal bRebootAfterShutdown As Long) As Long Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long Private Declare Function GetCurrentProcess Lib "kernel32" () As Long Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LARGE_INTEGER) As Long Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (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 GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Declare Function GetLastError Lib "kernel32" () As Long Public Function InitiateShutdownMachine(ByVal Machine As String, Optional Force As Variant, Optional Restart As Variant, Optional AllowLocalShutdown As Variant, Optional Delay As Variant, Optional Message As Variant) As Boolean Dim hProc As Long Dim OldTokenStuff As TOKEN_PRIVILEGES Dim OldTokenStuffLen As Long Dim NewTokenStuff As TOKEN_PRIVILEGES Dim NewTokenStuffLen As Long Dim pSize As Long If IsMissing(Force) Then Force = False If IsMissing(Restart) Then Restart = True If IsMissing(AllowLocalShutdown) Then AllowLocalShutdown = False If IsMissing(Delay) Then Delay = 0 If IsMissing(Message) Then Message = "" 'Make sure the Machine-name doesn't start with '\\' If InStr(Machine, "\\") = 1 Then Machine = Right(Machine, Len(Machine) - 2) End If 'check if it's the local machine that's going to be shutdown If (LCase(GetMyMachineName) = LCase(Machine)) Then 'may we shut this computer down? If AllowLocalShutdown = False Then Exit Function 'open access token If OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hProc) = 0 Then MsgBox "OpenProcessToken Error: " & GetLastError() Exit Function End If 'retrieve the locally unique identifier to represent the Shutdown-privilege name If LookupPrivilegeValue(vbNullString, SE_SHUTDOWN_NAME, OldTokenStuff.Privileges(0).pLuid) = 0 Then MsgBox "LookupPrivilegeValue Error: " & GetLastError() Exit Function End If NewTokenStuff = OldTokenStuff NewTokenStuff.PrivilegeCount = 1 NewTokenStuff.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED NewTokenStuffLen = Len(NewTokenStuff) pSize = Len(NewTokenStuff) 'Enable shutdown-privilege If AdjustTokenPrivileges(hProc, False, NewTokenStuff, NewTokenStuffLen, OldTokenStuff, OldTokenStuffLen) = 0 Then MsgBox "AdjustTokenPrivileges Error: " & GetLastError() Exit Function End If 'initiate the system shutdown If InitiateSystemShutdown("\\" & Machine, Message, Delay, Force, Restart) = 0 Then Exit Function End If NewTokenStuff.Privileges(0).Attributes = 0 'Disable shutdown-privilege If AdjustTokenPrivileges(hProc, False, NewTokenStuff, Len(NewTokenStuff), OldTokenStuff, Len(OldTokenStuff)) = 0 Then Exit Function End If Else 'initiate the system shutdown If InitiateSystemShutdown("\\" & Machine, Message, Delay, Force, Restart) = 0 Then Exit Function End If End If InitiateShutdownMachine = True End Function Function GetMyMachineName() As String Dim sLen As Long 'create a buffer GetMyMachineName = Space(100) sLen = 100 'retrieve the computer name If GetComputerName(GetMyMachineName, sLen) Then GetMyMachineName = Left(GetMyMachineName, sLen) End If End Function Private Sub Command1_Click() InitiateShutdownMachine GetMyMachineName, True, True, True, 60, "You initiated a system shutdown..." End Sub in one line And This is the easy way to shutdown your pc from xp Shutdown, log off, Restart of windows XP in one line. Shutdown : Shell "shutdown -s -t 0", vbHide log off : Shell "shutdown -l -t 0", vbHide Restart : Shell "shutdown -r -t 0", vbHide 3) Private Declare Function InitiateSystemShutdown Lib "advapi32.dll" Alias "InitiateSystemShutdownA" (ByVal lpMachineName As String, ByVal lpMessage As String, ByVal dwTimeout As Long, ByVal bForceAppsClosed As Long, ByVal bRebootAfterShutdown As Long) As Long Public Function InitiateShutdownMachine(ByVal Machine As String, Optional Force As Boolean, Optional Restart As Boolean, Optional Delay As Long, Optional Message As String) As Boolean Dim RetVal As Long RetVal = InitiateSystemShutdown("\\" & Machine, Message, Delay, Force, Restart) If RetVal = 0 Then InitiateShutdownMachine = False Else InitiateShutdownMachine = True End Function |
Autoru: | Vertygo [ 08 Sep 2005, 19:48 ] |
Tema posta: | |
Naisao sam na veoma dobar site za win32 api http://www.pinvoke.net/ |
Autoru: | RAbbit [ 10 Sep 2005, 16:02 ] |
Tema posta: | |
Shutdown : Shell "shutdown -s -t 0", vbHide log off : Shell "shutdown -l -t 0", vbHide Restart : Shell "shutdown -r -t 0", vbHide Ovo pozivanje shell-a radi u jednom redu koda i radi perfektno ko jebe api ![]() Pogledacu tu web stranu |
Autoru: | Vertygo [ 10 Sep 2005, 23:37 ] |
Tema posta: | |
Da ali to samo pali na win XP ![]() |
Stranica 1 od 1 | Sva vremena su u UTC [ DST ] |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |