|
| Calling CreateProcessWithLogonW in VB.NET |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.languages.vb.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Blurp! |
Hi all,
How do I use CreateProcessWithLogonW from advapi32.dll in Windows-2000 and Windows-XP? I have an routine calling a program as an other user (like RunAs) in VB6 and it works fine.
When I open the project in VB.Net however I am confronted with the fact that VB.Net not has StrPtr implemented. How do I translate the following VB6-code to VB.Net?
RetCode = CreateProcessWithLogonW(StrPtr(sUsername), StrPtr(sDomain), _ StrPtr(sPwd), LOGON_WITH_PROFILE, 0&, StrPtr(sCmd), 0&, ByVal 0&, _ StrPtr(sDir), SInfo, PInfo)
Any suggestion is welcome.
Greetings,
B
|
|
|
| |
|
| |
| |
| Patrick Steele [MVP] (VIP) |
In article <etIGdRd1BHA.948@tkmsftngp02> (from Blurp! <Click here to reveal e-mail address>), [Original message clipped]
Try passing the strings directly:
RetCode = CreateProcessWithLogonW(sUsername, sDomain, ...)
I think the marshalling code should take care of it for you. Also, how do you have the API declared?
-- Patrick Steele Microsoft .NET MVP
|
|
|
| |
|
|
| |
| |
| Blurp! |
Hi Patrick,
Thank you very much for your resonse. Your suggestion to just pass the strings directly does not work. The decleration states that it should be of a type "integer" ("long" in VB6). That is because in the VB6-source it used the StrPtr-function. I guess I got the declaration from www.allapi.net
I do not know how to translate the StrPtr to a VB.Net-syntax. The online-documentation says that there is no implementation for that function anymore. I am having trouble to translate all of my API-functions to VB.Net. They (the Microsoft-gang) made it quit hard to handle for a simple soul like me.
Any help is very welcome,
B
The API is declared as follows: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Public Structure STARTUPINFOW Dim cb As Integer Dim lpReserved As Integer Dim lpDesktop As Integer Dim lpTitle As Integer Dim dwX As Integer Dim dwY As Integer Dim dwXSize As Integer Dim dwYSize As Integer Dim dwXCountChars As Integer Dim dwYCountChars As Integer Dim dwFillAttribute As Integer Dim dwFlags As Integer Dim wShowWindow As Short Dim cbReserved2 As Short Dim lpReserved2 As Integer Dim hStdInput As Integer Dim hStdOutput As Integer Dim hStdError As Integer End Structure
Public Structure PROCESS_INFORMATION Dim hProcess As Integer Dim hThread As Integer Dim dwProcessId As Integer Dim dwThreadId As Integer End Structure
Public Const LOGON_WITH_PROFILE As Integer = &H1 Public Const LOGON_NETCREDENTIALS_ONLY As Integer = &H2 Public Const WAIT_TIMEOUT As Short = 258 Public Const FORMAT_MESSAGE_FROM_SYSTEM As Short = &H1000s
'UPGRADE_WARNING: Structure PROCESS_INFORMATION may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1050"' 'UPGRADE_WARNING: Structure STARTUPINFOW may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1050"' 'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1016"' Public Declare Function CreateProcessWithLogonW Lib "advapi32" (ByVal lpUsername As Integer, ByVal lpDomain As Integer, ByVal lpPassword As Integer, ByVal dwLogonFlags As Integer, ByVal lpApplicationName As Integer, ByVal lpCommandLine As Integer, ByVal dwCreationFlags As Integer, ByRef lpEnvironment As Any, ByVal lpCurrentDirectory As Integer, ByRef lpStartupInfo As STARTUPINFOW, ByRef lpProcessInfo As PROCESS_INFORMATION) As Integer <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[Original message clipped]
|
|
|
| |
|
|
| |
| |
| Patrick Steele [MVP] (VIP) |
In article <uAgJZuo1BHA.2748@tkmsftngp07> (from Blurp! <Click here to reveal e-mail address>), [Original message clipped]
Did you change the declaration to accept a string (and not an integer)? The PInvoke code is very good at marshalling .NET strings to null terminated character string pointers.
Also, in STARTUPINFOW and PROCESS_INFORMATION, anything that the Win32API declares as a "HANDLE" or "HWND" should be declared as "System.IntPtr".
-- Patrick Steele Microsoft .NET MVP
|
|
|
| |
|
|
| |
| | |
|
|
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|