Gå til innhold

Hvordan bruke CreateDesktop API


Anbefalte innlegg

noen som vett hvordan jeg kan lage ett nyt "desktop" og kjore ett nytt programm inni?

 

koden min forelopig er dette:

 

Private Const strDesktop = "Teesting"

Private Type SECURITY_ATTRIBUTES
   nLength As Long
   lpSecurityDescriptor As Long
   bInheritHandle As Long
End Type

Private 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

Private Type PROCESS_INFORMATION
  hProcess As Long
  hThread As Long
  dwProcessId As Long
  dwThreadId As Long
End Type

Private Type STARTUPINFOW
  cbSize As Long
  lpReserved As Long
  lpDesktop As Long
  lpTitle As Long
  dwX As Long
  dwY As Long
  dwXSize As Long
  dwYSize As Long
  dwXCountChars As Long
  dwYCountChars As Long
  dwFillAttribute As Long
  dwFlags As Long
  wShowWindow As Integer
  cbReserved2 As Integer
  lpReserved2 As Long
  hStdInput As Long
  hStdOutput As Long
  hStdError As Long
End Type

Private Declare Function CreateDesktop Lib "user32.dll" Alias "CreateDesktopA" (ByVal lpszDesktop As String, ByVal lpszDevice As String, ByRef pDevmode As DEVMODE, ByVal dwFlags As Long, ByVal dwDesiredAccess As Long, ByRef lpsa As SECURITY_ATTRIBUTES) As Long
Private Declare Function CloseDesktop Lib "user32.dll" (ByVal hDesktop As Long) As Long
Private Declare Function SwitchDesktop Lib "user32.dll" (ByVal hDesktop As Long) As Long
Private Declare Function GetProcessWindowStation Lib "user32.dll" () As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long
Private Declare Function EnumDesktops Lib "user32.dll" Alias "EnumDesktopsA" (ByVal hwinsta As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessW" (ByVal lpApplicationName As Long, ByVal lpCommandLine As Long, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFOW, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetLastError Lib "kernel32.dll" () As Long

Private Const DESKTOP_CREATEMENU As Long = &H4&
Private Const DESKTOP_CREATEWINDOW As Long = &H2&
Private Const DESKTOP_ENUMERATE As Long = &H40&
Private Const DESKTOP_HOOKCONTROL As Long = &H8&
Private Const DESKTOP_JOURNALPLAYBACK As Long = &H20&
Private Const DESKTOP_JOURNALRECORD As Long = &H10&
Private Const DESKTOP_READOBJECTS As Long = &H1&
Private Const DESKTOP_SWITCHDESKTOP As Long = &H100&
Private Const DESKTOP_WRITEOBJECTS As Long = &H80&
Private Const DF_ALLOWOTHERACCOUNTHOOK As Long = &H1&
Private Const GENERIC_ALL = &H10000000
Private Const UOI_FLAGS = 1
Private Const UOI_NAME = 2
Private Const UOI_TYPE = 3
Private Const UOI_USER_SID = 4
Private Const INFINITE As Long = &HFFFFFFFF

Public Function Kiosk(Exec As String) As Boolean
'Create the desktop
Dim hDesktop As Long, lRet As Long, lFlags As Long, lAccess As Long, lErr As Long
Dim SA As SECURITY_ATTRIBUTES, DM As DEVMODE, SI As STARTUPINFOW, PI As PROCESS_INFORMATION

SetSecurityAttributes SA
lFlags = 0 'Do not allow hooks
lAccess = SetAccess



lRet = CreateDesktop(strDesktop, 0, DM, lFlags, lAccess, SA)
If lRet <> 0 Then
   'Successfuly created desktop!
   SwitchDesktop lRet
   hDesktop = lRet
   
   'Set Startup Information
   SetStartupInfo SI
   
   'Load the process
   lRet = CreateProcess(StrPtr(Exec), 0, 0, 0, 2, 0, 0, 0, SI, PI)
   
   If lRet <> 0 Then
       'Wait for the application to terminate
       WaitForSingleObject PI.hProcess, INFINITE
       
       'Start cleaning up...
       CleanUp
       
       'All successfull(belive it or not;) )
       Kiosk = True
   Else
       lRet = GetLastError
       Debug.Print lRet, "Error when creating process"
       Kiosk = False
   End If
Else
   lRet = GetLastError
   Debug.Print lRet, "Error when creating desktop"
   Kiosk = False
End If

End Function

Private Function CleanUp()

CloseHandle PI.hProcess
CloseHandle PI.hThread

CloseDesktop hDesktop
End Function

Private Function SetSecurityAttributes(SA As SECURITY_ATTRIBUTES) As Boolean
With SA
   .nLength = Len(SA) 'To identify version and control.
   .lpSecurityDescriptor = 0 'Not used on 9x system, advanced control for NT systems
   .bInheritHandle = True
End With
End Function

Private Function SetAccess() As Long
Dim lAccess As Long
lAccess = DESKTOP_CREATEMENU Or DESKTOP_CREATEWINDOW Or DESKTOP_READOBJECTS Or DESKTOP_WRITEOBJECTS Or DESKTOP_SWITCHDESKTOP
SetAccess = lAccess
End Function

Private Function SetStartupInfo(SI As STARTUPINFOW) As Boolean
With SI
   .cbSize = Len(SI)
   .lpTitle = StrPtr(strDesktop)
   .lpDesktop = StrPtr(strDesktop)
End With
End Function

Lenke til kommentar
Videoannonse
Annonse

Hva med å endre destinasjonsvinduets parent slik at den befinner seg innenfor et vindu etter ditt valg (det være seg en form eller et vindu du har skapt med CreateWindowEx-APIet). Da skulle du oppnå akkurat det samme. SetParent-APIet er som følger:

 

Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Lenke til kommentar

Jeg vet ikke om du skjonner helt va du mener. jeg vil lage ett nytt desktop(du har sikkert lagt merke til "Windows Security" desktopet nar du trykker Ctrl+Alt+Del)

 

Jeg kaller kiosk "explorer.exe" , og sa skal dette programmet kjore opp i ett nytt desktop, dvs desktop "Teeesting".

 

Hoved poenget her er at da blir Ctrl+Alt+Del disablet(Tilogme i NT baserte systemer) og jeg kan enkelt lage et "sikkert" system.

 

Jeg tror problemet ligger i SetStartupInformation, men jeg har INGEN ide...

 

her er en tutorial som handler om CreateDesktop API en... vbAccelerator)

Endret av Richard87
Lenke til kommentar

Det finnes metoder for å i hvert fall gjøre Task Manager utilgjengelig for brukeren, blant annet med følgende kode (som fungerer i både 9x og NT):

 

Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long

Private Declare Function GetVersion Lib "kernel32" () As Long

 

Public Sub DisableTaskManager(Optional bDisabled As Boolean = True)

 

    Dim objWSH As Object

 

    ' Sjekk hvorvidt vi eksekverer under NT eller ikke

    If GetVersion() And &HC0000000 Then

   

        ' Nei, vi er i 9x - benytt således normalmetoden

        SystemParametersInfo 97, bDisabled, CStr(1), 0

   

    Else

       

        ' I NT derimot, må vi endre en registernøkkel for å få ønskede effekt

        Set objWSH = CreateObject("WScript.Shell")

 

        ' Endre nøkkel

        objWSH.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\" & _

        "System\DisableTaskMgr", IIf(bDisabled, 1, 0), "REG_DWORD"

   

    End If

 

End Sub

 

Uansett hva jeg gjør, får jeg likevel ikke programmet til å bli eksekvert. Merkelig nok fungerer ikke CreateProcess i det hele tatt etterpå, dersom jeg kjører en liknenden (fungerende!) kode i annetsteds. Det må sågar en omstart til før det ordner seg. Saktens tror jeg nok det beste ville være å forkaste den gjeldende eksekveringsprosedyren - dsv. alt utenom koden som lager desktopen, og erstatte det med dette eksempelet.

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...