473,503 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling CreateProcessWithLogonW

Hallo NG,
I have problems with calling the CreateProcessWithLogonW() function. I tried
converting an VB6 example
(http://support.microsoft.com/default...b;en-us;285879) and some
snippets i found around the web. but i cant get it to work. It tries to
start the application, but it fails. In my eventlog i can see a new info
message, everytime i execute my code. i try to translate it, cause i have a
german windows installed, so it maybe wont be the exact words of the
original english info message.

Application popup: some.exe - Error in application: the application couldnt
be initialized properly (0xc0000142). Click "OK" to exit.
event-id: 26

I tried launching notepad.exe, cmd.exe, cscript.exe but everytime the same
error. What im tryin to achieve is, to execute the vbscript file
makew3site.vbs from IIS > AdminScripts.

This is my code:

Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices

Public Class WebForm2
Inherits System.Web.UI.Page

Protected WithEvents lblTest As System.Web.UI.WebControls.Label

#Region "Structs"
<StructLayout(LayoutKind.Sequential)> _
Public Structure PROCESS_INFORMATION
Dim hProcess As System.IntPtr
Dim hThread As System.IntPtr
Dim dwProcessId As Integer
Dim dwThreadId As Integer
End Structure

<StructLayout(LayoutKind.Sequential)> _
Public Structure STARTUPINFO
Dim cb As Integer
Dim lpReserved As System.IntPtr
Dim lpDesktop As System.IntPtr
Dim lpTitle As System.IntPtr
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 System.IntPtr
Dim hStdInput As System.IntPtr
Dim hStdOutput As System.IntPtr
Dim hStdError As System.IntPtr
End Structure

#End Region

#Region "APIINFO"
Private Const LOGON_NETCREDENTIALS_ONLY As Integer = &H2
Private Const NORMAL_PRIORITY_CLASS As Integer = &H20
Private Const CREATE_DEFAULT_ERROR_MODE As Integer = &H4000000
Private Const CREATE_NEW_CONSOLE As Integer = &H10
Private Const CREATE_NEW_PROCESS_GROUP As Integer = &H200
Private Const LOGON_WITH_PROFILE As Integer = &H1

Private Declare Unicode Function CreateProcessWithLogon Lib "Advapi32"
Alias "CreateProcessWithLogonW" _
(ByVal lpUsername As String, _
ByVal lpDomain As String, _
ByVal lpPassword As String, _
ByVal dwLogonFlags As Integer, _
ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByVal dwCreationFlags As Integer, _
ByVal lpEnvironment As System.IntPtr, _
ByVal lpCurrentDirectory As System.IntPtr, _
ByRef lpStartupInfo As STARTUPINFO, _
ByRef lpProcessInfo As PROCESS_INFORMATION) As Integer

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
System.IntPtr) As Integer
#End Region

#Region " Vom Web Form Designer generierter Code "

'Dieser Aufruf ist für den Web Form-Designer erforderlich.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: Diese Methode ist für den Web Form-Designer erforderlich
'Verwenden Sie nicht den Code-Editor zur Bearbeitung.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim szApp As String = "C:\winnt\notepad.exe"
Dim szCmdLine As String = ""
Dim szUser As String = "user"
Dim szPass As String = "password"
Dim szDomain As String = "TEST"
Dim siStartup As STARTUPINFO
Dim piProcess As PROCESS_INFORMATION

siStartup.cb = Marshal.SizeOf(siStartup)
siStartup.dwFlags = 0

Dim ret As Integer = CreateProcessWithLogon(szUser, szDomain,
szPass, LOGON_WITH_PROFILE, szApp, szCmdLine, _
CREATE_DEFAULT_ERROR_MODE, _
IntPtr.Zero, IntPtr.Zero, siStartup, piProcess)

If ret = 0 Then
lblTest.Text = New
System.ComponentModel.Win32Exception(Marshal.GetLa stWin32Error()).Message
End If

CloseHandle(piProcess.hProcess)
CloseHandle(piProcess.hThread)
End Sub

End Class

I tried many combinations for szApp and szCmdLine, like tryin to give szApp
a reference to the exe, and szCmdLine the arguments, or leaving szApp empty
and passing everything woth szCmdLine like this:

Dim szCmdLine As String = "C:\Winnt\notepad.exe /put params here"

Also i tried to pass 0& as an integer in szApp, and szCmdLine like the above
one.
What i want to do is:

Dim szApp As String = "C:\Inetpub\AdminScripts\mkw3site.vbs"
Dim szCmdLine As String = "-r C:\Inetpub\wwwroot\client -t client.test.de -o
8080"

Could plz someone help me, im stuck with this for quite some days now, and
its drivin me nuts.
thx in advance
regards benni
Nov 18 '05 #1
3 2307
Hallo Alstersjo
"Alstersjo" <Al*******@discussions.microsoft.com> schrieb im Newsbeitrag
news:C1**********************************@microsof t.com...
Hello Benjamin
Thanks for your answer regarding my case.
I have got it to work running under w2k workstation but not under w3k server. There I get the same error as you
Can it have something with rights to do.
If I find out this I'll post it here, will you do the same?
Regards Henrik

yeah for sure.
regards benni
Nov 18 '05 #2
Hallo Alstersjo
"Alstersjo" <Al*******@discussions.microsoft.com> schrieb im Newsbeitrag
news:C1**********************************@microsof t.com...

im startin to belive, that theres some kind of bug or something like that.
because as you say it works on a w2k workstation, but doesnt work on a win2k
server. i searched through many forums and other every resource i could
think of (msdn,kb,newsgroups). everytime the CreateProcessWithLogonW
function is called the same (some little differences, but i tried them all).
You see people thanking the author for his great job and posting how
incredebly well the code works (little sarcastic sorry), but it wont work
for us. so i assume theres something wrong with the systems were running.
but im out of ideas and resources. is there any microsoft email adress or
other resource i could post to?

regards benni
Nov 18 '05 #3
Hello Bittner
I'm starting to believe that to. And I am starting to run out of ideas. Do you have any ideas about workarounds?
Are you in an AD environment?
Regards Alstersjo

"Benjamin Bittner" wrote:
Hallo Alstersjo
"Alstersjo" <Al*******@discussions.microsoft.com> schrieb im Newsbeitrag
news:C1**********************************@microsof t.com...

im startin to belive, that theres some kind of bug or something like that.
because as you say it works on a w2k workstation, but doesnt work on a win2k
server. i searched through many forums and other every resource i could
think of (msdn,kb,newsgroups). everytime the CreateProcessWithLogonW
function is called the same (some little differences, but i tried them all).
You see people thanking the author for his great job and posting how
incredebly well the code works (little sarcastic sorry), but it wont work
for us. so i assume theres something wrong with the systems were running.
but im out of ideas and resources. is there any microsoft email adress or
other resource i could post to?

regards benni

Nov 18 '05 #4

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

Similar topics

1
3396
by: Arne | last post by:
Hi, I'm working on an asp.net application that reads a users username and password, and starts a process with the username read. The problem is that the program returns value...
2
2357
by: jerry | last post by:
I'm trying to run an application under another user within a winform app writen in C#. I have tried a number of different things, but it seems that the CreateProcessWithLogonW function should work...
2
9331
by: Bilal Dinc | last post by:
Hey, I have a question concerning the CreateProcessWithLogonW function imported from the advapi32 dll. For some reason I cant get the appName and cmdLine paramters to work together. For example,...
1
5785
by: Bucky Pollard | last post by:
I have a web service that needs to create a batch file and call it (since there are no APIs for the functionality I am looking for). I am using the Process and ProcessStartInfo objects. When I try...
10
5349
by: David Davidson | last post by:
I am attempting to use CreateProcessWithLogonW from the server-side code of a web page (yes, I want to create a process on the server) and not having much luck. I am attempting to run VPScan, an...
6
1947
by: Matthew Wieder | last post by:
I have an ASPNET app that is running as the ASPNET machine user. It makes a call to the API CreateProcessWithLogonW. On Windows XP it executes without a problem, but on Windows 2000, I get an...
1
2063
by: ashu.nitc | last post by:
Hi, I am trying to create a process with the API: CreateProcessWithLogonW. The process (say, CMD.EXE) which gets created doesnt have the environment variables which I have explicitly passed into...
1
4523
by: ashu.nitc | last post by:
Hi , I am trying to create process using CreateProcessWithLogonW() API. This works fine on Win2000 and NT, but in Vista it gives a UAC popup before the process (say, notepad, calc, etc) kicks...
2
2878
by: None | last post by:
What's the difference between StartInteractiveClientProcess in http://msdn.microsoft.com/en-us/library/aa379608(VS.85).aspx, and CreateProcessWithLogonW?...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.