Option Explicit
Const INFINITE = &HFFFF
Const STARTF_USESHOWWINDOW = &H1
Public Enum LType
Explicit = 1
Hidden = 0
UD = 2
End Enum
Public Enum enSW
SW_HIDE = 0
SW_NORMAL = 1
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
End Enum
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
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 Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Public Enum enPriority_Class
NORMAL_PRIORITY_CLASS = &H20
IDLE_PRIORITY_CLASS = &H40
HIGH_PRIORITY_CLASS = &H80
End Enum
Public Enum DType
DefaultDesktopStation = 0
CurrentUserDesktopStation = 1
End Enum
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Function CP_Advanced(FileName As String, _
WorkDir As String, _
DesktopType As DType, _
Visibility As enSW, _
PriorityClass As enPriority_Class, _
Trace As Boolean, _
Optional WaitForCompletion As Boolean) As Boolean
Dim pclass As Long
Dim sinfo As STARTUPINFO
Dim pinfo As PROCESS_INFORMATION
'Setting Security Attributes
Dim sec1 As SECURITY_ATTRIBUTES
Dim sec2 As SECURITY_ATTRIBUTES
If Trace = True Then
If Right(App.Path, 1) <> "\" Then
FileName = App.Path & "\" & FileName
End If
End If
'Setting the structure size
sec1.nLength = Len(sec1)
sec2.nLength = Len(sec2)
sinfo.cb = Len(sinfo)
'Setting the Desktop Station Type
'==================================
If DesktopType = CurrentUserDesktopStation Then
sinfo.lpDesktop = ""
Else
sinfo.lpDesktop = "WinSta0\Default"
End If
'==================================
'Set the flags
sinfo.dwFlags = STARTF_USESHOWWINDOW
'Set the window's startup position
sinfo.wShowWindow = Visibility
'Starting the process
Dim ret As Long
ret = CreateProcess(vbNullString, FileName, sec1, sec1, False, PriorityClass, 1&, WorkDir, sinfo, pinfo)
If ret <> 0 Then CP_Advanced = True
If WaitForCompletion = True Then
ret& = WaitForSingleObject(pinfo.hProcess, INFINITE)
End If
End Function
CodeName33 писал(а):Sebas, чё реально эту фишку уберут? Просто мне иногода нужны права system, у admin'а прав нет чтобы системному процессу изменить приоритет например. Я прогу накатал, чтобы TaskManager по хоткею запускал с правами System и интерфейс нормально работет, все кнопки нормально нажимаются - ничего не глючит. Придётся, видимо, мне оставаться на XP.
CodeName33 писал(а):Sebas Ну создавать клиент-сервер это лишний гемор. К тому же это не дыра в системе безопасности. Чтобы этим воспользоваться нужно установить сначала программу как сервис с взаймодействием с рабочим столом, а у пользователя нет на это прав. Только у админа - а админ знает, что делает. Зачем уж так прямо брать и запрещать.
Сейчас этот форум просматривают: SemrushBot, Yandex-бот и гости: 41