By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,079 Members | 1,315 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,079 IT Pros & Developers. It's quick & easy.

Command-line restrictions

P: n/a
Hi

i've got a little problem using the createprocesswithlogon api.

It seems that the API has changed from Windows 2000 to WIndows XP.

Because only on Windows xp i can use more 256 characters as Arguments.

On Windows 2000 SP4 i get the win32 error 87, "wrong parameters", when
trying
to call a programm with more than 256 characters.

Even using the process class causes the same behaviour.

Are there any massive changes within the process communication between 2k
and xp?

thanks a lot

chris
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi Christian,

I can not reproduce the problem.
I can run the code below on both Windows 2000+SP4 and Windows XP+SP1.
Can you show me your code for me to reproduce the problem?

Here is my code you may have a test.(The Commandline argument is 259
characters)

#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 Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim szApp As String = "c:\windows\notepad.exe"
Dim szCmdLine As String = "
c:\kKKKKKKKKKKKKKKKKKKKKKKKKKKKKKNOTEpadqweritlkjg lkjfspvnmcvjhdfuyogfhjkhgk
jxhvjskjdhfwerkhfjsdnvkjhdsfiuyewkjfhjsdvbkjsdhfui weyfkjshfjknsdvkcjsdhfuies
hfjsdnfkjsdhfsiudhfskdjfhjskdnkjcnskjdncjksndckjsd fuisdhfskjdfhjdsncjsncjksn
dkjncsiudcnskjdnc.EXEfffff.xml" 'String.Empty"
Dim szUser As String = "user"
Dim szPass As String = "pass"
Dim szDomain As String = "domain"
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, _
NORMAL_PRIORITY_CLASS Or CREATE_DEFAULT_ERROR_MODE Or
CREATE_NEW_CONSOLE Or CREATE_NEW_PROCESS_GROUP, _
IntPtr.Zero, IntPtr.Zero, siStartup, piProcess)

If ret = 0 Then
MessageBox.Show(New
System.ComponentModel.Win32Exception(Marshal.GetLa stWin32Error()).Message)
End If
CloseHandle(piProcess.hProcess)
CloseHandle(piProcess.hThread)
End Sub

If you have concern on this issue,please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #2

P: n/a
Hi Christian,

And I do not think there is much change about the IPC between windowsXP and
windows2000.
Interprocess Communications
http://msdn.microsoft.com/library/de...us/ipc/base/in
terprocess_communications.asp

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #3

P: n/a
Hi Peter

here's my code

#Region "API Deklarationen"
Declare Unicode Function CreateProcessWithLogon Lib "Advapi32" Alias "CreateProcessWithLogonW" (ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonFlags As Integer, ByVal applicationName As String, ByVal commandLine As String, ByVal creationFlags As Integer, ByVal environment As IntPtr, ByVal currentDirectory As String, ByRef startupinfo As STARTUPINFO, ByRef processInfo As PROCESS_INFORMATION) As Boolean

Public Declare Function CloseHandle Lib "kernel32" (ByVal handle As IntPtr)
#End Region

#Region "Structures für API"
<StructLayout(LayoutKind.Sequential)> Public Structure STARTUPINFO
Dim cb As Integer
<MarshalAs(UnmanagedType.LPTStr)> Dim lpReserved As String
<MarshalAs(UnmanagedType.LPTStr)> Dim lpDesktop As String
<MarshalAs(UnmanagedType.LPTStr)> Dim lpTitle As String
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 IntPtr
Dim hStdInput As IntPtr
Dim hStdOutput As IntPtr
Dim hStdError As IntPtr
End Structure
<StructLayout(LayoutKind.Sequential)> Public Structure PROCESS_INFORMATION
Dim hProcess As IntPtr
Dim hThread As IntPtr
Dim dwProcessId As Integer
Dim dwThreadId As Integer
End Structure
#End Region

#Region "Flags für Logon"
'//dwLogonFlags Specifies the logon option
Public Const LOGON_WITH_PROFILE As Integer = 1
Public Const LOGON_NETCREDENTIALS_ONLY As Integer = 2
#End Region

#Region "Flags für Process Create"
'//dwCreationFlags - Specifies how the process is created
Public Const CREATE_SUSPENDED As Integer = &H4

Public Const CREATE_NEW_CONSOLE As Integer = &H10
Public Const CREATE_NEW_PROCESS_GROUP As Integer = &H200
Public Const CREATE_SEPARATE_WOW_VDM As Integer = &H800
Public Const CREATE_UNICODE_ENVIRONMENT As Integer = &H400
Public Const CREATE_DEFAULT_ERROR_MODE As Integer = &H4000000
#End Region

#Region "Flags für Process Prio"
'//dwCreationFlags parameter controls the new process's priority class
Public Const NORMAL_PRIORITY_CLASS As Integer = &H20
Public Const IDLE_PRIORITY_CLASS As Integer = &H40
Public Const HIGH_PRIORITY_CLASS As Integer = &H80
Public Const REALTIME_PRIORITY_CLASS As Integer = &H100
Public Const BELOW_NORMAL_PRIORITY_CLASS As Integer = &H4000
Public Const ABOVE_NORMAL_PRIORITY_CLASS As Integer = &H8000
#End Region

#Region "Flags für StartupInfo"
'//dwFlags
'// This is a bit field that determines whether certain STARTUPINFO
'// members are used when the process creates a window.
'// Any combination of the following values can be specified:
Public Const STARTF_USESHOWWINDOW As Integer = &H0
Public Const STARTF_USESIZE As Integer = &H2
Public Const STARTF_USEPOSITION As Integer = &H4
Public Const STARTF_USECOUNTCHARS As Integer = &H8
Public Const STARTF_USEFILLATTRIBUTE As Integer = &H10
Public Const STARTF_FORCEONFEEDBACK As Integer = &H40
Public Const STARTF_FORCEOFFFEEDBACK As Integer = &H80
Public Const STARTF_USESTDHANDLES As Integer = &H100
Public Const STARTF_USEHOTKEY As Integer = &H200
#End Region

#Region "Variabeln für API Call"
'Public slogonName As String = &H0& '// some user
'Public sdomain As String = &H0& '// local machine account
'Public spassword As String = &H0&
Public sApplicationName As String = &H0&
Public sEnviroment As String = &H0&
Public sDirectory As String = &H0&
Public sb As String
#End Region

#Region "Process Information Strukturen für interne Verarbeitung"
Public Process_Init_Status As Boolean
Public Process_Init_ErrorID As Integer
Public Process_Init_Error_MSG As String
Public Process_Init_Error_HelpLink As String
Public Process_Init_Error_Source As String
Public Process_Init_ProcessID As Integer
Public Process_End_Status As Boolean
Public Process_End_ExitCode As Long
#End Region

#Region "Structure Variabeln für API Call"
Public processInfo As New PROCESS_INFORMATION()
Public startInfo As New STARTUPINFO()
#End Region

Public Sub BefehlalsUser(ByVal sCMD As String, ByVal sLogonName As String, ByVal sDomain As String, ByVal sPassWord As String)
Dim i As Int16
Dim j As Int16

j = InStr(UCase(sCMD), UCase(".exe"))
If j <> 0 Then
sApplicationName = Trim$(Mid$(sCMD, 1, j + 4))
sb = """" & sApplicationName & """ " & Trim$(Mid$(sCMD, j + 4))
End If

i = InStr(sCMD, ":\")
If i <> 0 Then
sDirectory = Mid$(sCMD, 1, 3)
Else
sDirectory = "C:\"
End If

sEnviroment = &H0&

startInfo.cb = Marshal.SizeOf(startInfo)

startInfo.dwFlags = 0&

Process_Init_Status = CreateProcessWithLogon(sLogonName, sDomain, sPassWord, LOGON_WITH_PROFILE, sApplicationName, sb, CREATE_DEFAULT_ERROR_MODE Or CREATE_NEW_CONSOLE Or CREATE_NEW_PROCESS_GROUP, Marshal.StringToBSTR(sEnviroment), sDirectory, startInfo, processInfo)
If (Process_Init_Status = False) Then
Process_Init_ErrorID = Marshal.GetLastWin32Error()
Dim Win32Err As New System.ComponentModel.Win32Exception(Process_Init_ ErrorID)
Process_Init_Error_MSG = Win32Err.Message
Process_Init_Error_HelpLink = Win32Err.HelpLink
Process_Init_Error_Source = Win32Err.Source
Process_Init_ProcessID = 0
'WriteToEventLog("Error: {" & Process_Init_ErrorID & "} - " & Process_Init_Error_MSG, "VEDA Kommunikations-Dienst", EventLogEntryType.Error)
Else
Process_Init_ErrorID = 0
Process_Init_Error_MSG = ""
Process_Init_Error_HelpLink = ""
Process_Init_Error_Source = ""
Process_Init_ProcessID = processInfo.dwProcessId
'WriteToEventLog("ProcessID: {" & Process_Init_ProcessID & "}", "VEDA Kommunikations-Dienst", EventLogEntryType.Information)
End If
End Sub

A possible Value for sCmd is

\\VACSVR01\HV\P\PWR\PGM\VEDA X2W\X2W.EXE /PV=\\VACSVR01\HV\P\PWR\PGM\VEDA X2W\BECKER\FO02011.DOT /PS=\\VACSVR01\HV\P\PWR\PGM\VEDA x2W\BECKER\CBITEST.DOC /AZKEY1=500000 /AZKEY2= /AZKEY3= /AZKEY=500000//00//00 /AZMANR=1054 /AZGLKU=02726267//4 /AZFGTX=Vollstreckungstitel /AZRAHO=100,00 /AZDABX=1.11.03 /AZDABT=1 /AZZSA=7,00 /ABHF=111.150,11 /AZPFAZ=12M33//88 /XXPFGB=AG Rendsburg /XXPFDE=4.01.88 /AZTIAZ=1B21159//77 /XXTIGB=AG Stuttgart /XXTIDE=22.02.78 /XXTIGS=Hauffstr. 5 /XXTIGL=D /XXTIGP=70190 /XXTIGO=STUTTGART /XXTIAT=VOLLSTR.BESCH. /SUATXV=GEEHRTER /SUATXT=HERR /SUNAME=TIBO /SUVNA=DETLEF-HANS-KLAUS /SUSTR=ADOLF-SPIE_-STR. 8 /SULDKZ=D /SUPLZ=40764 /SUORT=LANGENFELD /SUDG1X=26.10.41 /SUFAST= /FAFBEZ=FA HILDEN /FAFSTR=NEUSTR. 60 /FALDKZ=D /FAFPLZ=40721 /FAFORT=HILDEN /ALGBEZ=AG LANGENFELD /ALGSTR=HAUPTSTR. 15 /ALLDKZ=D /ALGPLZ=40764 /ALGORT=LANGENFELD /MPNAME=DEUTSCHER BUECHERBUND GM /MPVNAM=BH & CO. /MPSTRA=WOLFRAMSTR. 35 /MPLDKZ=D /MPPLZ=70191 /MPORT=STUTTGART /GLNAME=EV.BUCHGEM.GMBH, VERTR.D /GLVNAM=.W.SCHOENICKE /GLSTRA=LIBANONSTR. 4-6 /GLLDKZ=D /GLPLZ=07000 /GLORT=STUTTGART 1 /RAPLZ=00000 /FINAME=INKASSO BECKER WUPPERTAL /FIZUSB=DIETER BECKER GMBH & CO.KG /FISTRA=HOFAUE 46 /FILDKZ=D /FIPLZ=42103 /FIORT=WUPPERTAL /DSMASS=412 /DSBI=12.12.03 /DAHAF=13.12.03 /DSVDAT=28.11.03 /XXRHF=111.150,11 /XXSALD= /XXBRAG= /XXHEBE= /XXAUSL= /XXMWST= /XXSUM1= /XXGESA=318.093,10 /XXFONR= /XASBNR= /ABVGLB=5.000,00 /XXWAEH=EUR /X1WAEH=EUR /X2WAEH=EUR /X3WAEH=EUR /X4WAEH=EUR /X5WAEH=EUR /X6WAEH=EUR /X7WAEH=EUR /X1SBNR= /X2SBNR=18 /MPNAVN=DEUTSCHER BUECHERBUND GMBH & CO. /GLNAVN=EV.BUCHGEM.GMBH, VERTR.D.W.SCHOENICKE /FINAVN=INKASSO BECKER WUPPERTAL /XXSBNR=//18

thanks

chris

Nov 20 '05 #4

P: n/a
Hi Christian,

Thank you for posting in the newsgroup.

I can reproduce the problem on Windows 2000+sp4.
I am researching the problem , I will update you with new information ASAP.

Have a nice day!
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #5

P: n/a
Hi Christian,

After I deeper research, I think that Windows 2000 SP3 and SP4 has changed
the design of this API. So you should not pass a string longer than 260
characters as the lpCommandline arguments on windows 2000 +SP3 or + SP4, I
think this is by design.

I think the MSDN should address this difference between W2k and XP. I have
reported the issue to our content team.

Thank you for you report.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #6

P: n/a
hi peter

what i don't understand is the fact that with vb6 the api worked fine under
windows2000.

but by the way the process class although doesn't work with a commandline
longer than 260
und Windows 2000.

So i don't see any possibility for a workaround!

cya

chris
"Peter Huang" <v-******@online.microsoft.com> schrieb im Newsbeitrag
news:O%****************@cpmsftngxa07.phx.gbl...
Hi Christian,

After I deeper research, I think that Windows 2000 SP3 and SP4 has changed
the design of this API. So you should not pass a string longer than 260
characters as the lpCommandline arguments on windows 2000 +SP3 or + SP4, I
think this is by design.

I think the MSDN should address this difference between W2k and XP. I have
reported the issue to our content team.

Thank you for you report.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #7

P: n/a
Hi Christian,

I have tested the api under VB6, I still get 87 error on windows 2000+ sp4.
I tested with the code below.
285879 HOWTO: Start a Process as Another User from Visual Basic
http://support.microsoft.com/?id=285879

As I said the API's design has changed under windows 2000 + SP3 and windows
2000 + sp4
The Process class should have the same behavior on windows 2000 as the API.

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.