Recent

Author Topic: Run as a different user  (Read 2170 times)

d2010

  • Sr. Member
  • ****
  • Posts: 251
Re: Run as a different user
« Reply #15 on: December 21, 2025, 06:30:23 am »
Here you see, same code ofn Registry very nice.
Line26  purpose more interesting facts.
Code: Pascal  [Select][+][-]
  1. [HKEY_CLASSES_ROOT\exefile\shell\open]
  2. "EditFlags"=hex:00,00,00,00
  3.  
  4. [HKEY_CLASSES_ROOT\exefile\shell\open\command]
  5. @="\"%1\" %*"
  6. "IsolatedCommand"="\"%1\" %*"
  7.  
  8. [HKEY_CLASSES_ROOT\exefile\shell\runas]
  9. "HasLUAShield"=""
  10.  
  11. [HKEY_CLASSES_ROOT\exefile\shell\runas\command]
  12. @="\"%1\" %*"
  13. "IsolatedCommand"="\"%1\" %*"
  14.  
  15. [HKEY_CLASSES_ROOT\exefile\shell\runasuser]
  16. @="@shell32.dll,-50944"
  17. "Extended"=""
  18. "SuppressionPolicyEx"="{F211AA05-D4DF-4370-A2A0-9F19C09756A7}"
  19.  
  20. [HKEY_CLASSES_ROOT\exefile\shell\runasuser\command]
  21. "DelegateExecute"="{ea72d00e-4960-42fa-ba92-7792a7944c1d}"
  22.  
  23. Windows Registry Editor Version 5.00
  24.  
  25. [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{ea72d00e-4960-42fa-ba92-7792a7944c1d}]
  26. @="Run as different user context menu handler"
  27.  
  28. [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{ea72d00e-4960-42fa-ba92-7792a7944c1d}\InProcServer32]
  29. @=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  30.   00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,65,00,78,00,\
  31.   70,00,6c,00,6f,00,72,00,65,00,72,00,66,00,72,00,61,00,6d,00,65,00,2e,00,64,\
  32.   00,6c,00,6c,00,00,00
  33. "ThreadingModel"="Apartment"
  34.  
  35.  
« Last Edit: December 21, 2025, 06:34:22 am by d2010 »

LemonParty

  • Sr. Member
  • ****
  • Posts: 393
Re: Run as a different user
« Reply #16 on: December 21, 2025, 02:32:36 pm »
d2010, that is nice. But the idea was to run something as a different user from code where you can directly specify username, password. And CreateProcessWithLogonW do the trick on Windows.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Raskaton

  • New Member
  • *
  • Posts: 22
Re: Run as a different user
« Reply #17 on: December 23, 2025, 07:18:48 pm »
I think this is an architectural issue.
It's better to split the application into two parts:
1. A service/daemon running under a specific user/group
2. A GUI that gives any user access to manage the service via IPC or edit its configuration files.
Changing permissions at runtime contradicts the very idea of ​​permissions in the OS. This is a bad idea. OS administrators will hate you.

If you need access to a serial port or USB in Linux, then "udev rules" are simply added (TAG+="uaccess"). Or service added to stanard "dialout" user group.

myisjwj

  • Jr. Member
  • **
  • Posts: 91
Re: Run as a different user
« Reply #18 on: December 26, 2025, 03:11:25 am »
You can refer to the following website to obtain the user name
https://www.cnblogs.com/jwjss/p/17914594.html

 

TinyPortal © 2005-2018