Page 1 of 3

Kiosk System

Posted: Wed Oct 11, 2006 11:12 pm
by PWS32
with this code (PB4.0) you can realize a kiosksystem
this sample start a new Desktop without taskbar or desktopicons, build a window with the new desktopname and start a external program,
the best is: you cant interupt or kill this desktop not with the taskmanager, you can kill this desktop only
you close the window with the new desktopname, have fun!

many thanks by this users to help me
srod <-- english forum
ts-soft <-- english and german forum
Trond <-- english forum
uweb <-- german forum
friedhelm <-- german forum
falko <-- german forum

Code: Select all

#WINSTA_ALL  = #WINSTA_ACCESSCLIPBOARD | #WINSTA_ACCESSGLOBALATOMS | #WINSTA_CREATEDESKTOP | #WINSTA_ENUMDESKTOPS | #WINSTA_ENUMERATE | #WINSTA_EXITWINDOWS | #WINSTA_READATTRIBUTES | #WINSTA_READSCREEN | #WINSTA_WRITEATTRIBUTES | #DELETE | #READ_CONTROL | #WRITE_DAC | #WRITE_OWNER 
#DESKTOP_ALL = #DESKTOP_READOBJECTS | #DESKTOP_CREATEWINDOW | #DESKTOP_CREATEMENU | #DESKTOP_HOOKCONTROL | #DESKTOP_JOURNALRECORD | #DESKTOP_JOURNALPLAYBACK | #DESKTOP_ENUMERATE | #DESKTOP_WRITEOBJECTS | #DESKTOP_SWITCHDESKTOP | #STANDARD_RIGHTS_REQUIRED 

#UOI_NAME = $2
Global m_sDesktop.s
m_sDesktop = Space(128)

Global cmdline$
cmdline$="C:\WINDOWS\system32\notepad.exe"

Global FontID1 
FontID1 = LoadFont(1, "Arial", 22, #PB_Font_Bold) 

Global startupinfo.STARTUPINFO
startupinfo\cb=SizeOf(STARTUPINFO)
startupinfo\lpReserved=#NUL
startupinfo\lpDesktop=#NUL
startupinfo\lpTitle=#NUL
startupinfo\dwX=#NUL
startupinfo\dwY=#NUL
startupinfo\dwXSize=#NUL
startupinfo\dwYSize=#NUL
startupinfo\dwXCountChars=#NUL
startupinfo\dwYCountChars=#NUL
startupinfo\dwFillAttribute=#NUL
startupinfo\dwFlags=#STARTF_USESHOWWINDOW
startupinfo\wShowWindow=#SW_SHOW
startupinfo\cbReserved2=#NUL
startupinfo\lpReserved2=#NUL
startupinfo\hStdInput=#NUL
startupinfo\hStdOutput=#NUL
startupinfo\hStdError=#NUL

Global process_information.PROCESS_INFORMATION
process_information\hProcess=#NUL
process_information\hThread=#NUL
process_information\dwProcessId=#NUL
process_information\dwThreadId=#NUL

;Global tSi.STARTUPINFO


;Show an error 
Procedure Abort(s.s) 
  MessageRequester("", "Error: "+s.s) 
  Debug "Error: "+s.s 
  End 
EndProcedure 



Procedure.s GetDesktopName()
  Protected hDesktop, lR, lSize, sBuff.s, iPos
  hDesktop = OpenInputDesktop_(0, #False, #DESKTOP_READOBJECTS)
  If hDesktop
    lSize = (Len(m_sDesktop) + 1) * 2
    sBuff=Space(lSize+1)
    lR = GetUserObjectInformation_(hDesktop, #UOI_NAME, @sBuff, lSize, @lSize)
    CloseHandle_(hDesktop)  ; Should this be CloseDesktop_() ?
  EndIf
  ProcedureReturn sBuff
EndProcedure 

;Check a result and ev. abort 
Procedure Chk(a.l, s.s) 
  
  ;If a is false, abort. 
  ;If a is false and s contains an error message, show it before abort. 
  If Not(a) 
    If s.s 
      Abort(s.s) 
    Else 
      End 
    EndIf 
  EndIf 
EndProcedure 

hWinSta = OpenWindowStation_("WinSta0", 0, #WINSTA_ALL) 
Chk( SetProcessWindowStation_(hWinSta) , "Failed to set window station") 

hDefaultDesk = OpenDesktop_("Default", #DF_ALLOWOTHERACCOUNTHOOK, 0, #DESKTOP_SWITCHDESKTOP) 
Chk(hDefaultDesk, "Failed to open default desktop") 

hDesk = CreateDesktop_("My Desktop 2", 0, 0, #DF_ALLOWOTHERACCOUNTHOOK, #DESKTOP_ALL, 0) 
Chk( hDesk, "Failed to create desktop") 

SetThreadDesktop_(hDesk)  ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 

Chk( SwitchDesktop_(hDesk), "Failed to switch desktop") 



If OpenWindow(1, 216, 0, 255, 165, "Test",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar ) 
  If CreateGadgetList(WindowID(1)) 
    TextGadget(1, 20, 70, 210, 30, "Test", #PB_Text_Center) 
    SetGadgetFont(1, FontID1) 
  EndIf 
EndIf 

m_sDesktop = GetDesktopName()
SetGadgetText(1,m_sDesktop)

tSi.STARTUPINFO
tSi\lpTitle = @m_sDesktop
tSi\lpDesktop = @m_sDesktop

tPi.PROCESS_INFORMATION

ret=createprocess_(#NUL,@cmdline$,#NUL,#NUL,#False,0,#NUL,#NUL,@tSi,@tPi)

Repeat 
  Event = WaitWindowEvent() 
  WindowID = EventWindow() 
  GadgetID = EventGadget() 
  EventType = EventType() 
  If Event = #PB_Event_Gadget 
  EndIf 
Until Event = #PB_Event_CloseWindow 

;Delay(2000) 

Chk( SwitchDesktop_(hDefaultDesk), "Failed to switch desktop") 
SetThreadDesktop_(hDefaultDesk)  ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 

CloseDesktop_(hDesk) 
CloseDesktop_(hDefaultDesk) 
CloseWindowStation_(hWinSta)

Posted: Wed Oct 11, 2006 11:48 pm
by oldBear
Pretty impressive.

Didn't realize you could lock out taskmanager like that.

cheers

Posted: Wed Oct 11, 2006 11:54 pm
by srod
Cool. 8)

Nice one.

Posted: Thu Oct 12, 2006 1:39 am
by va!n
nice!

Posted: Thu Oct 12, 2006 2:27 am
by netmaestro
Very fine tip, thanks for posting!

Posted: Thu Oct 12, 2006 2:31 am
by Dare
Neat. Thanks for sharing.

Posted: Thu Oct 12, 2006 4:02 am
by Intrigued
Most Excellent! Thanks!

Posted: Thu Oct 12, 2006 6:40 am
by benny
Cool. 8)

Maybe you should add to disable the Task Manager (although just popping up
in background).

Nevertheless, great work and thanks for sharing :!:

Posted: Tue Oct 17, 2006 1:12 am
by ricardo
Is there any way to show taskbar, systray, icons, etc on this new desktop?

Posted: Fri Oct 20, 2006 12:53 am
by naw
Oooh! now that has all sorts of possibilities...
- perhaps time to revisit my poor mans Set Top Box project ;-)
- thats so cool its positively chilly. Thanks for sharing...

Posted: Fri Oct 20, 2006 3:37 am
by CadeX
Whoa, awesome.

Do you know of a way to make runprogram work inside of it?

Appart from that, Great work!

Posted: Fri Oct 20, 2006 3:36 pm
by Pantcho!!
Very nice!
But it could be really really cool if we could disable the task manager and also running explorer.exe

because for example if you lock the task manager and run notepad and use the save as / load dialog you can just browse to windows directory and right click the "explorer.exe" -> open
and there you go you have all the icons and start toolbar + icons.

So first of all great start but to make it a really kiosk it need more features!.

I am willing to help (altough i don't really can understand the code ).

Posted: Fri Oct 20, 2006 5:08 pm
by ricardo
CadeX wrote: Do you know of a way to make runprogram work inside of it?

Code: Select all

cmdline$ = c:/myexe.exe
ret=CreateProcess_(#NUL,@cmdline$,#NUL,#NUL,#False,0,#NUL,#NUL,@tSi,@tPi) 

;find handle of created proccess
If ret
   ProcessID.l =tPi\dwProcessId 
   Repeat 
      win=FindWindow_(0,0) 
      While win<>0 And quit=0 
         GetWindowThreadProcessId_(win, @pid.l) 
         If pid=ProcessID 
            WinHandle=win 
            quit=1 
         EndIf 
         win=GetWindow_(win, #GW_HWNDNEXT)          
      Wend 
   Until WinHandle 
EndIf 
;Now in Winhandle you have the handle of process

Posted: Sat Oct 21, 2006 3:32 am
by CadeX
Ohh, i see. All i needed was createprocess. Thanks for that!

Posted: Mon Oct 23, 2006 7:40 pm
by GeoTrail
Nice one.

I made a simple Kiosk thing too. Not very impressive though, it just uses the Kiosk feature of Opera. By using the program parameter sent to Opera, many of the features such as file download, right-click menu etc are removed.

Code: Select all

; Opera Kiosk Mode
; Written by Robert Olsen.

RunProgram("J:\Opera Kiosk\KillTask.exe", "", "") ; Run a small extra program I made with a button that kills the Opera program and the Opera Kiosk Mode program and sends a force log off message to Windows.

ProgramName.s      = "D:\Program Files\Opera\Opera.exe"
Parameter.s        = "/KioskMode /kioskbuttons /nodownload /noexit /nomenu /kioskwindows /noprint /nosave"
WorkingDirectory.s = ""
RunProgram(ProgramName.s, Parameter.s, WorkingDirectory.s)