Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. API functions

API functions

Scheduled Pinned Locked Moved Visual Basic
helpjsonquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bjwoodburn
    wrote on last edited by
    #1

    Help Please...! I'm trying to add a shutdown routine to a program using the ExitWindowsEx API function. I'm running on Windows XP. The problem is that the LookUpPrivilegeValue function keeps crashing out saying : Instance of an object is not set. As far as I know I'm not referencing an object merely calling a function. Can anyone help? Here is the code I am using: Option Explicit On Imports System Imports System.Runtime.InteropServices Public Class ShutDownAPI Private Const EWX_LogOff As Long = 0 Private Const EWX_SHUTDOWN As Long = 1 Private Const EWX_REBOOT As Long = 2 Private Const EWX_FORCE As Long = 4 Private Const EWX_POWEROFF As Long = 8 Public Shared Function ExitWindowsEx(ByVal dwOptions As Long, ByVal dwReserved As Long) As Long End Function Public Shared Function GetLastError() As Long End Function Public Shared Function GetVersion() As Long End Function Public Shared Function GetCurrentProcess() As Long End Function Public Shared Function OpenProcessToken(ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, ByVal TokenHandle As Long) As Long End Function Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, ByVal lpLuid As LUID) As Long Public Shared Function AdjustTokenPrivileges(ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, ByVal NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, ByVal PreviousState As TOKEN_PRIVILEGES, ByVal ReturnLength As Long) As Long End Function Public Shared Sub SetLastError(ByVal dwErrCode As Long) End Sub Private Const mlngWindows95 = 0 Private Const mlngWindowsNT = 1 Private glngWhichWindows32 As Long Public Structure LUID Public UsedPart As Long Public IgnoredForNowHigh32BitPart As Long End Structure Public Structure LUID_AND_ATTRIBUTES Public TheLuid As LUID Public Attributes As Long End Structure Public Structure TOKEN_PRIVILEGES Public PrivilegeCount As Long Public TheLuid As LUID Public Attributes As Long End Structure Public Enum sdAction Reboot = 1 Shutdown = 2 Logoff = 3 End Enum

    P 1 Reply Last reply
    0
    • B bjwoodburn

      Help Please...! I'm trying to add a shutdown routine to a program using the ExitWindowsEx API function. I'm running on Windows XP. The problem is that the LookUpPrivilegeValue function keeps crashing out saying : Instance of an object is not set. As far as I know I'm not referencing an object merely calling a function. Can anyone help? Here is the code I am using: Option Explicit On Imports System Imports System.Runtime.InteropServices Public Class ShutDownAPI Private Const EWX_LogOff As Long = 0 Private Const EWX_SHUTDOWN As Long = 1 Private Const EWX_REBOOT As Long = 2 Private Const EWX_FORCE As Long = 4 Private Const EWX_POWEROFF As Long = 8 Public Shared Function ExitWindowsEx(ByVal dwOptions As Long, ByVal dwReserved As Long) As Long End Function Public Shared Function GetLastError() As Long End Function Public Shared Function GetVersion() As Long End Function Public Shared Function GetCurrentProcess() As Long End Function Public Shared Function OpenProcessToken(ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, ByVal TokenHandle As Long) As Long End Function Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, ByVal lpLuid As LUID) As Long Public Shared Function AdjustTokenPrivileges(ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, ByVal NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, ByVal PreviousState As TOKEN_PRIVILEGES, ByVal ReturnLength As Long) As Long End Function Public Shared Sub SetLastError(ByVal dwErrCode As Long) End Sub Private Const mlngWindows95 = 0 Private Const mlngWindowsNT = 1 Private glngWhichWindows32 As Long Public Structure LUID Public UsedPart As Long Public IgnoredForNowHigh32BitPart As Long End Structure Public Structure LUID_AND_ATTRIBUTES Public TheLuid As LUID Public Attributes As Long End Structure Public Structure TOKEN_PRIVILEGES Public PrivilegeCount As Long Public TheLuid As LUID Public Attributes As Long End Structure Public Enum sdAction Reboot = 1 Shutdown = 2 Logoff = 3 End Enum

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      Change your definition of LookupPrivilegeValue to this:

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

      and LARGE_INTEGER is declared liek this:

      Public Type LARGE_INTEGER
      lowpart As Long
      highpart As Long
      End Type

      Use the APIViewer tool in VB to create these function declarations for you. Good luck.


      Build a man a fire, and he will be warm for a day
      Light a man on fire, and he will be warm for the rest of his life!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups