473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to use structs in a call to an unmanaged funtion

Hi,

i need to create a .NET class that will provide the same functionality as
the windows 'run as' command.
it seems that this code is not available in the .NET framework.

I have found an example that will logon he desired creadentials to get a
security token.

the only thing i need to do now is to import the function

BOOL CreateProcessAsUser(
HANDLE hToken,
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);

i know how to pass simple things like integers, handles etc, but that
function call uses a number of pointers to win32 structures to set and get
information. how do i need to pass those? i assume that i have to create
equivalent structs?

I have lookde into the .NET framework, but it does not seem to support
strting a process as another user?
I know i can impersonate another user, but would that not affect the
application that i am starting the new process from?
Nov 15 '05 #1
2 1149
Bruno,

Starting a process as another is not going to affect your current
process. It will affect the process being run.

For the call to CreateProcessAsUser, you can declare the
LPSECURITY_ATTRIBUTES as IntPtr and pass along IntPtr.Zero to represent
null. I say that only because I don't typically see people use these
attributes.

However, the last structure needs marshaling. The structure would be
declared like this:

[StructLayout(LayoutKind.Sequential)]
public struct PROCESS_INFORMATION
{
public IntPtr hProcess;
public IntPtr hThread;
[MarshalAs(UnmanagedType.U4)]
public int dwProcessId;
[MarshalAs(UnmanagedType.U4)]
public int dwThreadId;
}

You could then declare the last parameter as a "ref" parameter of this
type.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com
"Bruno van Dooren" <mi******@hotmail.com> wrote in message
news:u1*************@TK2MSFTNGP10.phx.gbl...
Hi,

i need to create a .NET class that will provide the same functionality as
the windows 'run as' command.
it seems that this code is not available in the .NET framework.

I have found an example that will logon he desired creadentials to get a
security token.

the only thing i need to do now is to import the function

BOOL CreateProcessAsUser(
HANDLE hToken,
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);

i know how to pass simple things like integers, handles etc, but that
function call uses a number of pointers to win32 structures to set and get
information. how do i need to pass those? i assume that i have to create
equivalent structs?

I have lookde into the .NET framework, but it does not seem to support
strting a process as another user?
I know i can impersonate another user, but would that not affect the
application that i am starting the new process from?

Nov 15 '05 #2
Starting a process as another is not going to affect your current
process. It will affect the process being run.


and if i use impersonation to impersonate another user?
does impersonation mean that everything i do in code until i undo the
impersonation
is executed with the impersonized credentials? i ask this because in that
case i could use
Process.Start() to start a new process, which would be easier that doing an
unmanaged call.

this also brings back my question about the credentials of secondary threads
in my current process.
(i an relatively new to windows security. you might have guessed :-) )

anyway i really appreciate the code that you sent me. i will give it a try.

kind regards,
Bruno.
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: codymanix | last post by:
Last night I had several thought about RAII and want to discuss a bit. Why doesn't CSharp support destructors in structs? Wouldn't that make RAII possible like in C++? When the struct goes out of...
1
by: Claire | last post by:
I don't understand the following error I'm getting when I call the DoOpen function of my unmanaged dll. Can someone explain please public static extern int DoOpen(ref sRDetails RDetails); ...
8
by: Mas L via DotNetMonster.com | last post by:
Hi, I have a c++ source code which I can compile to be a DLL (in VS.NET 2003). And I need to use it in a C# program. After I compiled/build the C++ code to a DLL, I add it as a Reference in my...
16
by: Michi Henning | last post by:
Below is a bit of code that creates a delegate. The delegate invokes a member function of a struct. The code compiles, but has surprising behavior: using System; namespace ConsoleApplication1...
6
by: DaTurk | last post by:
Hi, I'm coding a layer into my application using CLI, between a unmanaged and a c# layer. So, I have to marshal some unmanaged c++ structures to structures usable in c#. My solution was to...
6
by: =?Utf-8?B?QWxleGFuZGVyZmU=?= | last post by:
Hi, I have a C# program that uses an unmanaged dll that has a function similar to the signature below : void f(out MyStruct arr, out int num); // num = actual array length returned The array...
2
by: jonpb | last post by:
Using .NET 3.5, I need to pass an array of structs as parameter to a C++ unmanaged function. The C++ dll stores some data in an unmanaged cache, the function writes the values into the array of...
1
by: =?Utf-8?B?RGFya3Jpc2Vy?= | last post by:
Mates, the problem is pretty simple, but I'm unable to manage it... Therefore asking you for help. Situation: Have managed code in C# and unamanged code in C++ DLL. I need to make a call from...
1
by: Saad | last post by:
Hi, I have a MC++dll, whose functions i want to use in unmanaged c++. I read that one of the ways to use the managed functions in unmanaged world is by exposing the managed api as flat api. I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.