Hi Leute,
war jetzt lange zeit nicht mehr hier im Forum, hatte jetzt leider mein Passwort und Useraccount vergessen und deshalb nun neu dabei.
Ich stehe aktuell vor folgendem Problem.
Es soll aus einem Windows Service ein Prozess gestartet werden mit zusätzlichen Argumenten. folgenden Code habe ich (dieser geht auch schon)
leider weiß ich nicht wo ich die Argumente unterbringen kann, zum testen habe ich version>>version.txt verwendet, dabei sollte openssl eigentlich die version in eine txt datei schreiben.
Zum Hintergrund: der Dienst schaut in einem Ordner und verschlüsselt eine bestimmte Datei mit openssl und sendet diese an einen weiteren Prozess, dies nur als Hintergrund.
Die Verschlüsselung per cmd funktioniert schon, nun möchte ich dies halt in dem Dienst umsetzen.
WindowsAPI Class
Bin über jede Hilfe Dankbar
war jetzt lange zeit nicht mehr hier im Forum, hatte jetzt leider mein Passwort und Useraccount vergessen und deshalb nun neu dabei.
Ich stehe aktuell vor folgendem Problem.
Es soll aus einem Windows Service ein Prozess gestartet werden mit zusätzlichen Argumenten. folgenden Code habe ich (dieser geht auch schon)
Quellcode
- Dim UserTokenHandle As IntPtr = IntPtr.Zero
- WindowsApi.WTSQueryUserToken(WindowsApi.WTSGetActiveConsoleSessionId, UserTokenHandle)
- Dim ProcInfo As New WindowsApi.PROCESS_INFORMATION
- Dim StartInfo As New WindowsApi.STARTUPINFOW
- StartInfo.cb = CUInt(Runtime.InteropServices.Marshal.SizeOf(StartInfo))
- WindowsApi.CreateProcessAsUser(UserTokenHandle, "C:\PROGRA~1\Openssl\openssl.exe", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, False, 0, IntPtr.Zero, Nothing, StartInfo, ProcInfo)
- If Not UserTokenHandle = IntPtr.Zero Then
- WindowsApi.CloseHandle(UserTokenHandle)
- End If
leider weiß ich nicht wo ich die Argumente unterbringen kann, zum testen habe ich version>>version.txt verwendet, dabei sollte openssl eigentlich die version in eine txt datei schreiben.
Zum Hintergrund: der Dienst schaut in einem Ordner und verschlüsselt eine bestimmte Datei mit openssl und sendet diese an einen weiteren Prozess, dies nur als Hintergrund.
Die Verschlüsselung per cmd funktioniert schon, nun möchte ich dies halt in dem Dienst umsetzen.
WindowsAPI Class
Quellcode
- Imports System.Runtime.InteropServices
- Public Class WindowsApi
- <DllImport("kernel32.dll", EntryPoint:="WTSGetActiveConsoleSessionId", SetLastError:=True)>
- Public Shared Function WTSGetActiveConsoleSessionId() As UInteger
- End Function
- <DllImport("Wtsapi32.dll", EntryPoint:="WTSQueryUserToken", SetLastError:=True)>
- Public Shared Function WTSQueryUserToken(ByVal SessionId As UInteger, ByRef phToken As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
- End Function
- <DllImport("kernel32.dll", EntryPoint:="CloseHandle", SetLastError:=True)>
- Public Shared Function CloseHandle(<InAttribute()> ByVal hObject As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
- End Function
- <DllImport("advapi32.dll", EntryPoint:="CreateProcessAsUserW", SetLastError:=True)>
- Public Shared Function CreateProcessAsUser(<InAttribute()> ByVal hToken As IntPtr,
- <InAttribute(), MarshalAs(UnmanagedType.LPWStr)> ByVal lpApplicationName As String,
- ByVal lpCommandLine As System.IntPtr,
- <InAttribute()> ByVal lpProcessAttributes As IntPtr,
- <InAttribute()> ByVal lpThreadAttributes As IntPtr,
- <MarshalAs(UnmanagedType.Bool)> ByVal bInheritHandles As Boolean,
- ByVal dwCreationFlags As UInteger,
- <InAttribute()> ByVal lpEnvironment As IntPtr,
- <InAttribute(), MarshalAsAttribute(UnmanagedType.LPWStr)> ByVal lpCurrentDirectory As String,
- <InAttribute()> ByRef lpStartupInfo As STARTUPINFOW,
- <OutAttribute()> ByRef lpProcessInformation As PROCESS_INFORMATION) As <MarshalAs(UnmanagedType.Bool)> Boolean
- End Function
- <StructLayout(LayoutKind.Sequential)>
- Public Structure SECURITY_ATTRIBUTES
- Public nLength As UInteger
- Public lpSecurityDescriptor As IntPtr
- <MarshalAs(UnmanagedType.Bool)>
- Public bInheritHandle As Boolean
- End Structure
- <StructLayout(LayoutKind.Sequential)>
- Public Structure STARTUPINFOW
- Public cb As UInteger
- <MarshalAs(UnmanagedType.LPWStr)>
- Public lpReserved As String
- <MarshalAs(UnmanagedType.LPWStr)>
- Public lpDesktop As String
- <MarshalAs(UnmanagedType.LPWStr)>
- Public lpTitle As String
- Public dwX As UInteger
- Public dwY As UInteger
- Public dwXSize As UInteger
- Public dwYSize As UInteger
- Public dwXCountChars As UInteger
- Public dwYCountChars As UInteger
- Public dwFillAttribute As UInteger
- Public dwFlags As UInteger
- Public wShowWindow As UShort
- Public cbReserved2 As UShort
- Public lpReserved2 As IntPtr
- Public hStdInput As IntPtr
- Public hStdOutput As IntPtr
- Public hStdError As IntPtr
- End Structure
- <StructLayout(LayoutKind.Sequential)>
- Public Structure PROCESS_INFORMATION
- Public hProcess As IntPtr
- Public hThread As IntPtr
- Public dwProcessId As UInteger
- Public dwThreadId As UInteger
- End Structure
- End Class
Bin über jede Hilfe Dankbar
If the facts don't fit the theory, change the facts. --Albert Einstein
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „p0150n“ ()