473,322 Members | 1,398 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,322 software developers and data experts.

CreateProcess lpCommandLine with multiple parameters / spaces

I'm trying to run a DOS executable with CreateProcessWithLogon instead
of running it as a batch job.
It runs fine as a batch job but doesn't run when the workstation is
locked, that's why I wanna try the createprocess function

EXAMPLE Batch file
cd c:\WINEDISW
ALWAYSSW \CONCORDE\ 8711489112121 ALWAYS

EXAMPLE VB.NET CODE

Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form

#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

' you had this as a byte, but it is LPBYTE or byte*
' so should be an IntPtr
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
Private Sub DoYourThing()
Dim szApp As String = "ALWAYSSW.exe"
Dim szCmdLine As String = "'\concorde\ 8711489112121
ALWAYSSW'"
Dim IpCurDir As String
Dim szUser As String = "JOHN"
Dim szPass As String = "DOE"
Dim szDomain As String = "ALWAYS"
Dim siStartup As STARTUPINFO
Dim piProcess As PROCESS_INFORMATION

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

IpCurDir = "c:\winedisw"
Dim ret As Integer = CreateProcessWithLogon(szUser, szDomain,
szPass, LOGON_WITH_PROFILE, szApp, szCmdLine, _
NORMAL_PRIORITY_CLASS Or CREATE_DEFAULT_ERROR_MODE Or
CREATE_NEW_CONSOLE Or _
CREATE_NEW_PROCESS_GROUP, _
IntPtr.Zero, Marshal.StringToBSTR(IpCurDir), siStartup,
piProcess)
'IntPtr.Zero, IntPtr.Zero, siStartup, piProcess)

If ret = 0 Then
WriteToEventLog(New
System.ComponentModel.Win32Exception(Marshal.GetLa stWin32Error()).Message,
"DS Stealth Runner")
End If
WriteToEventLog("Proces naar behoren uitgevoerd!", "DS Stealth
Runner")
CloseHandle(piProcess.hProcess)
CloseHandle(piProcess.hThread)
Application.Exit()
End Sub

The problem is that the executable takes 3 parameters, I can get the
exe to run ,it notices that it's called with 3 parameters (because if
I don't send them the DOS program starts with a 'menu') but it doesn't
do a thing..
I could as wel use
Dim szCmdLine As String = "1 2 3" does pretty much the same thing
I've tried
Dim szCmdLine As String = "'\concorde\ 8711489112121 ALWAYSSW'"
Dim szCmdLine As String = "\concorde\ 8711489112121 ALWAYSSW"
Dim szCmdLine As String = "c:\concorde\ 8711489112121 ALWAYSSW'"
Dim szCmdLine As String = "c:\concorde 8711489112121 ALWAYSSW'"

I've searched for create process / lpCommandLine but I'm stuck for
now...
Do I have to do something with the spaces in between?
And uhh, the OS it has to run on is WIN2000

Please help me out here....
Thanks,

Michael
Nov 21 '05 #1
0 3258

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

Similar topics

2
by: cranker | last post by:
No matter how I fill in parameters for the CreateProcess API, I keep getting a NullReference exception thrown at me when my VB code executes It's driving me nuts! Can anyone help Just an...
0
by: ByteSize | last post by:
Would be grateful of advice please. I have code in VB6 working as follows: lngReply = CreateProcess(sNull, txtStart, ByVal 0&, ByVal 0&, 1&, _ NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo,...
1
by: DOT NET JIM | last post by:
in VB6 the api declares the createprocess lbEnv var as any. When converted to ..NET is change the type any to Object. The problem is, what kind of object. I can not get the env variables set when...
5
by: Stefano Camaiani | last post by:
Hello, please someone have the working code on how to call the CreateProcess API in Vb.Net? I need to call the CreateProcess API directly and i should not use the Vb.Net Process functions like dim...
1
by: cranker | last post by:
No matter how I fill in parameters for the CreateProcess API, I keep getting a NullReference exception thrown at me when my code executes It's driving me nuts! Can anyone help?
2
by: Paul Schenk | last post by:
Hi All :) Would be grateful of advice please. I have code in VB6 working as follows: lngReply = CreateProcess(sNull, txtStart, ByVal 0&, ByVal 0&, 1&, _ NORMAL_PRIORITY_CLASS, ByVal 0&,...
1
by: itmanager | last post by:
I am trying to create a process at a particular set of coordinates (for example 1,1) but the CreateProcess api seemingly ignores the settings in the dwX and dwY properties of the STARTUPINFO...
13
by: a.zeevi | last post by:
free() multiple allocation error in C ==================================== Hi! I have written a program in C on PC with Windows 2000 in a Visual C environment. I have an error in freeing...
1
by: Jai | last post by:
Please provide sample code for using Createprocess in VB.NET. The code I am using is given below. But I get "Error 91: Object referrence not set to an instance of the object" at CreateProcess...
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...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.